Permalink
Browse files

Cucub::VM now gets instances initialized with initializer.rb file; th…

…ey are registered into the ObjectsHub
  • Loading branch information...
1 parent 4da0fc0 commit 073ad9cbcfef8278f0a0a1905e82bea57c184ef8 @krakatoa krakatoa committed Oct 24, 2012
Showing with 44 additions and 24 deletions.
  1. +9 −7 examples/boot.rb
  2. +2 −0 examples/initializer.rb
  3. +3 −0 examples/protocol.ini
  4. +0 −7 examples/reply_channel_test.rb
  5. +25 −3 lib/vm.rb
  6. +2 −0 lib/vm/cli.rb
  7. +3 −7 lib/vm/configuration.rb
View
@@ -1,8 +1,10 @@
-# Run it on root with this command: ruby bin/cucub-vm start examples/boot.rb
+# Run it on root dir with this command:
+# ruby bin/cucub-vm.rb start examples/boot.rb -c examples/protocol.ini -i examples/initializer.rb
-require './examples/reply_channel_test'
-
-core = Core.new
-#core.oid = 1
-
-#Cucub.start!('10.0.0.5', Proc.new {})
+class Core
+ def state(i)
+ puts "--ack--"
+ sleep(i)
+ puts "Hola! #{i}"
+ end
+end
View
@@ -0,0 +1,2 @@
+core = Core.new
+core2 = Core.new
View
@@ -1,3 +1,6 @@
+[core]
+ role = receiver
+
[engine]
role = receiver
default_uses = mailbox
@@ -1,7 +0,0 @@
-class Core
- def state(i)
- puts "--ack--"
- sleep(i)
- puts "Hola! #{i}"
- end
-end
View
@@ -11,12 +11,34 @@ def initialize
def start!(vm_opts={})
@config_filepath = vm_opts[:config]
- @configuration = Cucub::VM::Configuration.instance
- #@address = server_opts[:host]
- #@dispatcher.start
+ self.init_classes
+
+ $stdout.puts Cucub::ObjectsHub.instance.objects.inspect
+ self.init_objects(vm_opts[:initializer]) # this will go inside worker instance
+ $stdout.puts Cucub::ObjectsHub.instance.objects.inspect
+ EM.run do
+ $stdout.puts "inside reactor"
+ end
+ end
+
+ def init_classes
+ Cucub::VM::Configuration.instance.classes.each do |class_name|
+ begin
+ const = Kernel.const_get(class_name.capitalize)
+ const.send :include, Cucub::Object
+ rescue NameError
+ $stdout.puts "There is one class defined (#{class_name.capitalize}), that wasn't loaded in the ObjectSpace."
+ end
+ end
+ end
+
+ def init_objects(boot_file)
+ boot_file = "./#{boot_file}" unless boot_file.match(/^[\/.]/)
+ require boot_file
end
def shutdown!
+ EM.stop
#@dispatcher.stop
end
View
@@ -14,6 +14,7 @@ class CLI < Thor
desc "start", "start cucub-vm"
#method_option :host, :aliases => '-h', :default => '127.0.0.1', :type => :string
method_option :config, :aliases => '-c', :default => 'config/protocol.ini', :type => :string
+ method_option :initializer, :aliases => '-i', :default => 'config/initializer.rb', :type => :string
def start(boot_file)
opts = options.dup
@@ -33,6 +34,7 @@ def start(boot_file)
#core = Antir::Core.instance
#core.oid = 1
servolux = Cucub::VM::Servolux.new('Cucub-VM', :logger => logger, :pid_file => pid_file)
+
servolux.vm_opts = opts # opts are passed raw to the servolux. They are read by a Cucub::Server instance.
boot_file = "./#{boot_file}" unless boot_file.match(/^[\/.]/)
View
@@ -17,18 +17,14 @@ def set_config_file
def reload
@specification_set = @loader.parse
- $stdout.puts self.classes.inspect
- @uses = nil
+ @classes = nil
end
def classes
# lazy load array of classes
return @classes if @classes
- #uses = []
- #uses << "box" if @specification_set.uses_box
- #uses << "mailbox" if @specification_set.uses_mailbox
- #uses << "board" if @specification_set.uses_board
- @uses = @specification_set.classes
+ classes = @specification_set.classes
+ @classes = classes
end
end
end

0 comments on commit 073ad9c

Please sign in to comment.