Skip to content
Browse files

Basic draft for messaging between VM and Actors

  • Loading branch information...
1 parent 4c18176 commit e442404911b34b7cc225c66f78c855c05f2ea28d @krakatoa krakatoa committed
Showing with 48 additions and 5 deletions.
  1. +2 −1 examples/boot.rb
  2. +23 −2 lib/actor.rb
  3. +23 −2 lib/reactor.rb
View
3 examples/boot.rb
@@ -2,7 +2,8 @@
# ruby bin/cucub-vm.rb start examples/boot.rb -c examples/protocol.ini -i examples/initializer.rb
class Core
- def state(i)
+ def state(i=1)
+ i = i.to_i
puts "--ack--"
sleep(i)
puts "Hola! #{i}"
View
25 lib/actor.rb
@@ -2,8 +2,11 @@
module Cucub
class Actor
- def initialize
+ def initialize(cucub_object)
@state = :alive
+
+ @cucub_object = cucub_object
+
set_fiber
self
end
@@ -13,7 +16,10 @@ def set_fiber
while alive?
$stdout.puts "> at Actor"
msg = args.shift
- puts msg
+ $stdout.puts msg.inspect
+
+ message = read_message(msg[1])
+ play message
#if msg == "exit"
# self.kill
@@ -27,6 +33,21 @@ def set_fiber
}
end
+ def read_message(message_txt)
+ message = {}
+ message[:action] = message_txt.split(";")[0]
+ message[:params] = message_txt.split(";")[1].split(",") if message_txt.split(";")[1]
+ message
+ end
+
+ def play(message) #(method_name, *args)
+ if message.has_key?(:params) #args
+ @cucub_object.send(message[:action], *message[:params])
+ else
+ @cucub_object.send(message[:action])
+ end
+ end
+
def wire(msg)
@fiber.transfer(msg, Fiber.current)
end
View
25 lib/reactor.rb
@@ -17,9 +17,13 @@ def run
end
def plug_actors
- @actor = Cucub::Actor.new
+ #@actor = Cucub::Actor.new
+ #plug_actor(@actor)
- plug_actor(@actor)
+ Cucub::ObjectsHub.instance.objects.each do |object|
+ actor = Cucub::Actor.new(object)
+ plug_actor(actor)
+ end
end
def container
@@ -32,12 +36,29 @@ def container
@inbound.receive { |msg|
$stdout.puts "received: #{msg.inspect}"
+ wrap, wire_message = unwrap_message(msg.last)
+ $stdout.puts "Wrap: #{wrap.inspect}"
+ $stdout.puts "Wire: #{wire_message.inspect}"
+ msg[msg.size - 1] = [wrap, wire_message]
+
@actors.first.wire(msg)
+
$stdout.puts "\n"
}
}
end
+ def unwrap_message(message)
+ #unserialized, serialized = message.split("\n")
+
+ # encrypted;oid | action;param1,param2
+ wrap, wire_message_txt = message.split("|")
+
+ # unencrypt, deserialize wire_message_txt
+
+ [wrap, wire_message_txt]
+ end
+
def plug_actor(actor)
@actors << actor
# maybe send plugged event ?

0 comments on commit e442404

Please sign in to comment.
Something went wrong with that request. Please try again.