lib/arborist/node.rb in arborist-0.0.1.pre20161005112841 vs lib/arborist/node.rb in arborist-0.0.1.pre20161005182540

- old
+ new

@@ -491,15 +491,23 @@ compact_hash( self.properties ) # Super to the state machine event method super + return self.collect_events + end + + + ### Collect the events generated by updates and return them after broadcasting + ### them to any child nodes. + def collect_events events = self.pending_update_events.clone events << self.make_update_event events << self.make_delta_event unless self.update_delta.empty? self.broadcast_events( *events ) + return events ensure self.update_delta.clear self.pending_update_events.clear end @@ -636,11 +644,11 @@ end ### Publish the specified +events+ to any subscriptions the node has which match them. def publish_events( *events ) - self.log.debug "Got published events: %p" % [ events ] + self.log.debug "Got events to publish: %p" % [ events ] self.subscriptions.each_value do |sub| sub.on_events( *events ) end end @@ -670,13 +678,11 @@ self.log.debug "No handler for a %s event!" % [ event.type ] end super # to state-machine - self.publish_events( event, *self.pending_update_events ) - ensure - self.pending_update_events.clear + return self.collect_events end ### Returns +true+ if this node's dependencies are not met. def dependencies_down? @@ -712,9 +718,10 @@ self.quieted_reasons[ :primary ] = "Parent down: %s" % [ self.parent ] # :TODO: backtrace? end end + ### Handle a 'node.disabled' event received via broadcast. def handle_node_disabled_event( event ) self.log.debug "Got a node.disabled event: %p" % [ event ] self.dependencies.mark_down( event.node.identifier ) if self.dependencies_down?