Permalink
Browse files

Made messaging available for internal VM-Server purpose

  • Loading branch information...
1 parent 7c28e12 commit f03918affb425fa53943d44cdb804faec8e8390d @krakatoa krakatoa committed Feb 19, 2013
Showing with 13 additions and 31 deletions.
  1. +1 −1 lib/message.rb
  2. +2 −1 lib/message/body.rb
  3. +3 −1 lib/message/header.rb
  4. +7 −2 lib/reference.rb
  5. +0 −26 msg_testing.rb
View
2 lib/message.rb
@@ -25,7 +25,7 @@ def initialize(opts={})
@header = Cucub::Message::Header.parse(opts["header"])
@body = Cucub::Message::Body.load(opts["body"])
else
- opts_for_header = opts.select{|key| ["from", "to", "respond_to"].include?(key)}
+ opts_for_header = opts.select{|key| ["from", "to", "respond_to", "layer"].include?(key)}
@header = Cucub::Message::Header.new(opts_for_header)
@body = Cucub::Message::Body.new(opts["action"], opts["additionals"])
end
View
3 lib/message/body.rb
@@ -54,7 +54,8 @@ def unlock(mechanism)
return false if not locked?
puts "Unlocking..."
case mechanism
- when :msgpack
+ # TODO implement this mechanisms in a Strategy pattern
+ when :msgpack, :inner_outbound
decoded = Base64.decode64(@serialized)
decoded = MessagePack.unpack(decoded)
@action = decoded["action"]
View
4 lib/message/header.rb
@@ -29,10 +29,12 @@ def serialize
end
def self.parse(hash)
+ # It may not receive a respond_to in case of sending: registrations (from VM to Server); ready jobs (from VM to Server)..
+ respond_to = Cucub::Reference.new(hash["respond_to"]) rescue nil
Cucub::Message::Header.new(
"from" => Cucub::Reference.new(hash["from"]),
"to" => Cucub::Reference.new(hash["to"]),
- "respond_to" => Cucub::Reference.new(hash["respond_to"])
+ "respond_to" => respond_to
)
end
View
9 lib/reference.rb
@@ -1,18 +1,23 @@
module Cucub
class Reference
- attr_reader :object_uuid
+ attr_reader :object_uuid # TODO rename it to uuid
attr_reader :class_name
+ attr_reader :layer
def initialize(opts={})
@object_uuid = opts["object_uuid"] || opts[:object_uuid]
@class_name = opts["class_name"] || opts[:class_name]
+ @layer = opts["layer"] || opts[:layer] || :vm # [:wcn, :server, :vm]
+ @layer = @layer.to_sym
end
def to_hash
- {
+ output = {
"object_uuid" => self.object_uuid,
"class_name" => self.class_name
}
+ output["layer"] = @layer unless @layer == :vm
+ output
end
end
end
View
26 msg_testing.rb
@@ -1,26 +0,0 @@
-require './lib/message'
-require './lib/reference'
-require 'msgpack'
-
-# action deberia automaticamente parsearse como symbol, para poder mandar por send
-
-ref = Cucub::Reference.new({:object_uuid => 1, :class_name => "Core"})
-ref2 = Cucub::Reference.new({:object_uuid => 2, :class_name => "Engine"})
-
-puts "Message with from, to, respond_to, action, additionals params:\n"
-message = Cucub::Message.new("from" => ref, "to" => ref2, "respond_to" => ref, "action" => "state", "additionals" => 1)
-message.locked?
-serialized = message.serialize
-message.locked?
-
-puts "==="
-puts "Message by parsing serialized data:\n"
-message2 = Cucub::Message.parse(serialized)
-message2.locked?
-message2.unlock(:msgpack)
-puts "action: #{message2.action} | additionals: #{message2.additionals}"
-message2.locked?
-
-# testear header.parse
-# testear reference.parse
-# testear message.parse

0 comments on commit f03918a

Please sign in to comment.