Permalink
Browse files

Configuration is now a normal class (not Singleton); updated VM booti…

…ng methods; uid and Reporting class added
  • Loading branch information...
1 parent a8f8ce5 commit 6f65494069690eef0362569627c346d6c829a308 @krakatoa krakatoa committed Feb 17, 2013
Showing with 80 additions and 16 deletions.
  1. +1 −0 lib/cucub-vm.rb
  2. +10 −4 lib/driver.rb
  3. +34 −0 lib/reporting.rb
  4. +30 −7 lib/vm.rb
  5. +5 −5 lib/vm/configuration.rb
View
1 lib/cucub-vm.rb
@@ -8,4 +8,5 @@
require_relative './actor'
require_relative './reactor'
require_relative './driver'
+require_relative './reporting'
require_relative './vm'
View
14 lib/driver.rb
@@ -15,24 +15,24 @@ class Driver
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}
+ actions = Cucub::VM.instance.configuration.actions_for_class(class_name).collect{|action| action.to_sym}
Cucub::Proxy.new(class_name, actions)
end
def get_from(klass, action)
class_name = get_class_name(klass)
- Cucub::VM::Configuration.instance.from_for_class_action(class_name, action.to_s)
+ Cucub::VM.instance.configuration.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)
+ Cucub::VM.instance.configuration.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
+ return nil if not Cucub::VM.instance.configuration.classes.include? class_name
class_name
end
@@ -41,6 +41,12 @@ def send_msg(message)
puts message.inspect
Cucub::Channel.vm_inner_outbound.send_string(message.serialize)
end
+
+ def register(uid, klass)
+ # TODO FIX armar mensajes para boot entre vm y server
+ $stdout.puts "Registering: #{uid} #{klass}"
+ # Cucub::Channel.vm_inner_outbound.send_string("register #{uid} #{klass}")
+ end
end
end
end
View
34 lib/reporting.rb
@@ -0,0 +1,34 @@
+module Cucub
+ class Reporting
+ # include Singleton
+
+ def initialize(vm_uid)
+ @vm_uid = vm_uid
+ @messages = []
+ @last_send = Time.now
+ @max_elapsed_time = 1
+ end
+
+ #def set_vm_uid=(vm_uid)
+ # @vm_uid = vm_uid
+ #end
+
+ def task_done(msg)
+ # Remains:
+ # send all when no activity is registered
+ # differentiate classes and uids in the messages
+ #
+ @messages << msg
+ if (Time.now - @last_send) > @max_elapsed_time
+ self.bulk_send
+ end
+ end
+
+ def bulk_send
+ puts "ready #{@vm_uid} engine #{@messages.join(",")}"
+ Cucub::Channel.vm_inner_outbound.send_string "ready #{@vm_uid} engine #{@messages.join(",")}"
+ @last_send = Time.now
+ @messages = []
+ end
+ end
+end
View
37 lib/vm.rb
@@ -6,30 +6,53 @@ module Cucub
class VM
include Singleton
- attr_reader :threaded
+ attr_reader :threaded, :uid, :reporting
def initialize
#@dispatcher = Cucub::Dispatcher.instance
+
@running = true
end
- def start!(vm_opts={})
+ def set_uid
+ @uid = rand(50)
+ end
+
+ def register
+ @configuration.classes.each do |class_name|
+ Cucub::VM::Driver.instance.register(@uid, class_name)
+ end
+ end
+
+ def set_reporting
+ @reporting = Cucub::Reporting.new(@uid)
+ end
+
+ def boot(vm_opts={})
+ set_uid
+ @config_filepath = vm_opts[:config]
+ @initializer = vm_opts[:initializer]
+ @configuration = Cucub::VM::Configuration.new(@config_filepath)
@threaded = vm_opts[:threaded].nil? ? true : vm_opts[:threaded]
+ register
+ set_reporting
+ end
+
+ def start!
if @running
- @config_filepath = vm_opts[:config]
self.init_classes
$stdout.puts Cucub::ObjectsHub.instance.objects.inspect
- self.init_objects(vm_opts[:initializer]) # this will go inside worker instance
+ self.init_objects(@initializer) # this will go inside worker instance
$stdout.puts Cucub::ObjectsHub.instance.objects.inspect
self.init_reactor
end
end
def init_classes
- Cucub::VM::Configuration.instance.classes.each do |class_name|
+ @configuration.classes.each do |class_name|
begin
const = Kernel.const_get(class_name.capitalize)
const.send :include, Cucub::Object
@@ -53,8 +76,8 @@ def shutdown!
Cucub::Reactor.instance.stop
end
- def config_filepath
- @config_filepath
+ def configuration
+ @configuration
end
#def address
View
10 lib/vm/configuration.rb
@@ -3,16 +3,16 @@
module Cucub
class VM
class Configuration
- include Singleton
+ #include Singleton
- def initialize
+ def initialize(config_filepath)
@loader = Cucub::Protocol::Loader.new
- set_config_file
+ set_config_file(config_filepath)
reload
end
- def set_config_file
- @loader.set_path(Cucub::VM.instance.config_filepath)
+ def set_config_file(config_filepath)
+ @loader.set_path(config_filepath)
end
def reload

0 comments on commit 6f65494

Please sign in to comment.