lib/punchblock/component/component_node.rb in punchblock-2.3.1 vs lib/punchblock/component/component_node.rb in punchblock-2.4.0

- old
+ new

@@ -6,10 +6,11 @@ include HasGuardedHandlers def initialize(*args) super @complete_event_resource = FutureResource.new + @mutex = Mutex.new register_internal_handlers end def register_internal_handlers register_handler :internal, Event::Complete do |event| @@ -34,26 +35,30 @@ client.execute_command action, :target_call_id => target_call_id, :component_id => component_id action end def response=(other) - if other.is_a?(Ref) - @component_id = other.component_id - @source_uri = other.uri.to_s - client.register_component self if client + @mutex.synchronize do + if other.is_a?(Ref) + @component_id = other.component_id + @source_uri = other.uri.to_s + client.register_component self if client + end + super end - super end def complete_event(timeout = nil) @complete_event_resource.resource timeout end def complete_event=(other) - return if @complete_event_resource.set_yet? - client.delete_component_registration self if client - complete! - @complete_event_resource.resource = other + @mutex.synchronize do + return if @complete_event_resource.set_yet? + client.delete_component_registration self if client + complete! + @complete_event_resource.resource = other + end rescue StateMachine::InvalidTransition => e e.message << " for component #{self}" raise e end