Permalink
Browse files

First implementation of Cucub Proxy

  • Loading branch information...
1 parent de6c961 commit eedd695a2a6f8be7f98dae7cdf4921ce427ee7cf @krakatoa krakatoa committed Feb 4, 2013
Showing with 68 additions and 5 deletions.
  1. +4 −0 examples/boot.rb
  2. +2 −0 examples/initializer.rb
  3. +2 −0 lib/cucub-vm.rb
  4. +30 −0 lib/driver.rb
  5. +4 −0 lib/object.rb
  6. +17 −0 lib/proxy.rb
  7. +3 −3 lib/reactor.rb
  8. +1 −2 lib/vm.rb
  9. +5 −0 lib/vm/configuration.rb
View
@@ -9,3 +9,7 @@ def state(i=1)
puts "Hola! #{i}"
end
end
+
+# TODO try to supress this requirement
+class Engine
+end
@@ -1,2 +1,4 @@
core = Core.new
core2 = Core.new
+
+Engine.new
View
@@ -3,7 +3,9 @@
require_relative './object'
require_relative './objects_hub'
+require_relative './proxy'
require_relative './channel'
require_relative './actor'
require_relative './reactor'
+require_relative './driver'
require_relative './vm'
View
@@ -0,0 +1,30 @@
+class String
+ def underscore
+ self.gsub(/::/, '/').
+ gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
+ gsub(/([a-z\d])([A-Z])/,'\1_\2').
+ tr("-", "_").
+ downcase
+ end
+end
+
+module Cucub
+ 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
+ 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)
+ end
+ end
+ end
+end
View
@@ -17,6 +17,10 @@ def new(*args, &block)
obj
end
+ def proxy
+ Cucub::VM::Driver.instance.proxy_class_for(self)
+ end
+
def instance(*args, &block)
obj = super
Cucub::ObjectsHub.instance.register(obj)
View
@@ -0,0 +1,17 @@
+module Cucub
+ class Proxy
+ def initialize(class_name, actions)
+ @class_name = class_name
+ @actions = actions
+ end
+
+ def method_missing(method, *args, &block)
+ if @actions.include?(method)
+ # puts "PROXY: #{method}"
+ Cucub::VM::Driver.instance.send_msg(method, args)
+ else
+ super
+ end
+ end
+ end
+end
View
@@ -86,8 +86,8 @@ def container_prepare
begin
- # worker is going to be a Class, fibered-aware, which can receive messages
- # relay(@worker)
+ # worker is going to be a Class, fibered-aware, which can receive messages
+ # relay(@worker)
$stdout.puts "prepared to receive."
@@ -135,7 +135,7 @@ def kill_actors
def init_channels
@inbound = Cucub::Channel.vm_inner_inbound
- #@outbound = Cucub::Channel.vm_inner_outbound
+ @outbound = Cucub::Channel.vm_inner_outbound
end
def stop
View
@@ -14,8 +14,7 @@ def initialize
end
def start!(vm_opts={})
- vm_opts[:threaded] = true if vm_opts[:threaded].nil?
- @threaded = vm_opts[:threaded]
+ @threaded = vm_opts[:threaded].nil? ? true : vm_opts[:threaded]
if @running
@config_filepath = vm_opts[:config]
@@ -20,6 +20,11 @@ def reload
@classes = nil
end
+ def actions_for_class(class_name)
+ obj_spec = @specification_set[class_name]
+ obj_spec.action_specifications.collect(&:action_name)
+ end
+
def classes
# lazy load array of classes
return @classes if @classes

0 comments on commit eedd695

Please sign in to comment.