Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Proxy now is able to send messages via Driver; Implemented usage of R…

…espondTo policy
  • Loading branch information...
commit a8f8ce5bdaf46b414f53313dc8e6157387083da9 1 parent eedd695
@krakatoa krakatoa authored
View
6 examples/protocol.ini
@@ -6,18 +6,18 @@
default_uses = mailbox
serialize = msgpack
compression = gzip
+ respond_to = * > core > *
; cp = 1425
[engine#create_vps]
from = core
- respond_to = class+object
uses_board = true
serialize = none
- read_by = core
[agent]
default_uses = board
role = emitter
+ respond_to = * > ~ > *
[agent#metric]
serialize = none
@@ -25,5 +25,5 @@
[agent#adelantar_metric]
from = trigger
; respond_to = broadcast
- respond_to = box
+ uses_box = true
read_by = monitor
View
28 lib/driver.rb
@@ -13,17 +13,33 @@ class VM
class Driver
include Singleton
- def proxy_class_for(klass)
- class_name = klass.to_s.underscore
- return false if not Cucub::VM::Configuration.instance.classes.include? class_name
+ def proxy_for_class(klass)
+ class_name = get_class_name(klass)
actions = Cucub::VM::Configuration.instance.actions_for_class(class_name).collect{|action| action.to_sym}
Cucub::Proxy.new(class_name, actions)
end
- def send_msg(action, args)
- message = action.to_s
- Cucub::Channel.vm_inner_outbound.send_string(message)
+ def get_from(klass, action)
+ class_name = get_class_name(klass)
+ Cucub::VM::Configuration.instance.from_for_class_action(class_name, action.to_s)
+ end
+
+ def get_respond_to(klass, action)
+ class_name = get_class_name(klass)
+ Cucub::VM::Configuration.instance.respond_to_for_class_action(class_name, action.to_s)
+ end
+
+ def get_class_name(klass)
+ class_name = klass.to_s.underscore
+ return nil if not Cucub::VM::Configuration.instance.classes.include? class_name
+ class_name
+ end
+
+ def send_msg(message)
+ #message = action.to_s
+ puts message.inspect
+ Cucub::Channel.vm_inner_outbound.send_string(message.serialize)
end
end
end
View
14 lib/object.rb
@@ -10,6 +10,10 @@ def uuid
uuid.to_s(35)
end
+ def reference
+ Cucub::Reference.new(:object_uuid => uuid, :class_name => Cucub::VM::Driver.instance.get_class_name(self.class))
+ end
+
module ClassMethods
def new(*args, &block)
obj = super
@@ -17,8 +21,14 @@ def new(*args, &block)
obj
end
- def proxy
- Cucub::VM::Driver.instance.proxy_class_for(self)
+ def reference
+ Cucub::Reference.new(:class_name => Cucub::VM::Driver.instance.get_class_name(self))
+ end
+
+ def proxy(options={})
+ proxy = Cucub::VM::Driver.instance.proxy_for_class(self)
+ proxy.default_respond_to=(options[:respond_to].reference) if options.has_key?(:respond_to)
+ proxy
end
def instance(*args, &block)
View
55 lib/proxy.rb
@@ -5,10 +5,61 @@ def initialize(class_name, actions)
@actions = actions
end
- def method_missing(method, *args, &block)
+ def uuid
+ uuid = hash
+ uuid = -uuid if uuid < 0
+ uuid.to_s(35)
+ end
+
+ def default_respond_to=(reference)
+ @default_respond_to = reference
+ end
+
+ def default_respond_to
+ @default_respond_to
+ end
+
+ def reference
+ Cucub::Reference.new(:class_name => Cucub::VM::Driver.instance.get_class_name(@class_name))
+ end
+
+ def method_missing(method, args={}, &block)
if @actions.include?(method)
# puts "PROXY: #{method}"
- Cucub::VM::Driver.instance.send_msg(method, args)
+
+ ### Build message START
+ ## Build from START
+ from = Cucub::VM::Driver.instance.get_from(@class_name, method) if not args.has_key?(:from)
+ from = Cucub::Reference.new(:class_name => from)
+ ## Build from END
+ ## Build respond_to START
+
+ overriden_respond_to = args.delete(:respond_to).reference rescue nil
+ overriden_respond_to ||= default_respond_to
+
+ # TODO Remains the validation of the overriden respond_to values :)
+ if not overriden_respond_to
+ respond_to = Cucub::VM::Driver.instance.get_respond_to(@class_name, method) if not args.has_key?(:respond_to)
+
+ instance_specific, object_uuid = respond_to.is_instance_specific?
+ class_specific, class_name = respond_to.is_class_specific?
+ zone_specific, zone = respond_to.is_zone_specific?
+
+ respond_to = Cucub::Reference.new(:object_uuid => object_uuid, :class_name => class_name)
+ else
+ respond_to = overriden_respond_to
+ end
+
+ ## Build respond_to END
+
+ message = Cucub::Message.new("from" => from, "to" => self.reference, "respond_to" => respond_to, "action" => method, "additionals" => args)
+ # TODO set Cucub::Proxy#from
+ # TODO set Cucub::Proxy#respond_to
+ # TODO implement same configuration style as respond_to on from field.
+ # TODO move this to a class in charge
+ ### Build message END
+
+ Cucub::VM::Driver.instance.send_msg(message)
else
super
end
View
10 lib/vm/configuration.rb
@@ -6,7 +6,7 @@ class Configuration
include Singleton
def initialize
- @loader = Cucub::Protocol::Loader.instance
+ @loader = Cucub::Protocol::Loader.new
set_config_file
reload
end
@@ -25,6 +25,14 @@ def actions_for_class(class_name)
obj_spec.action_specifications.collect(&:action_name)
end
+ def respond_to_for_class_action(class_name, action)
+ @specification_set[class_name].action_specifications.select {|spec| spec.action_name == action }.first.respond_to
+ end
+
+ def from_for_class_action(class_name, action)
+ @specification_set[class_name].action_specifications.select {|spec| spec.action_name == action }.first.from
+ end
+
def classes
# lazy load array of classes
return @classes if @classes
Please sign in to comment.
Something went wrong with that request. Please try again.