lib/metacosm/simulation.rb in metacosm-0.3.1 vs lib/metacosm/simulation.rb in metacosm-0.3.2

- old
+ new

@@ -3,10 +3,14 @@ # TODO protected? def redis_connection Redis.new end + def params + @params ||= {} + end + def fire(command) command_queue.push(command) end def command_queue @@ -38,10 +42,12 @@ @mutex = Mutex.new end def apply(command) mutex.synchronize do + received_commands.push(command) + if command.is_a?(Hash) handler_module_name = command.delete(:handler_module) handler_class_name = command.delete(:handler_class_name) module_name = handler_module_name handler = (module_name.constantize). @@ -52,10 +58,14 @@ handler.handle(command.attrs) end end end + def received_commands + @commands_received ||= [] + end + def apply_event(event) if !@on_event_callback.nil? event_dto = event.attrs.merge(listener_module: event.listener_module_name, listener_class_name: event.listener_class_name) @on_event_callback[event_dto] end @@ -95,11 +105,13 @@ on.subscribe do |chan, subscriptions| puts "Subscribed to ##{chan} (#{subscriptions} subscriptions)" end on.message do |chan, message| - puts "##{chan}: #{message}" - apply(Marshal.load(message)) + # puts "##{chan}: #{message}" + command_data = Marshal.load(message) + p [ :got_message, command_data: command_data ] + apply(command_data) end on.unsubscribe do |chan, subscriptions| puts "Unsubscribed from ##{chan} (#{subscriptions} subscriptions)" end