class Punchblock::Component::ComponentNode

Public Class Methods

new(*args) click to toggle source
Calls superclass method Punchblock::CommandNode::new
# File lib/punchblock/component/component_node.rb, line 8
def initialize(*args)
  super
  @complete_event_resource = FutureResource.new
  @mutex = Mutex.new
  register_internal_handlers
end

Public Instance Methods

add_event(event) click to toggle source
# File lib/punchblock/component/component_node.rb, line 22
def add_event(event)
  trigger_handler :internal, event
end
complete_event(timeout = nil) click to toggle source
# File lib/punchblock/component/component_node.rb, line 50
def complete_event(timeout = nil)
  @complete_event_resource.resource timeout
end
complete_event=(other) click to toggle source
# File lib/punchblock/component/component_node.rb, line 54
def complete_event=(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
register_event_handler(*guards, &block) click to toggle source
# File lib/punchblock/component/component_node.rb, line 30
def register_event_handler(*guards, &block)
  register_handler :event, *guards, &block
end
register_internal_handlers() click to toggle source
# File lib/punchblock/component/component_node.rb, line 15
def register_internal_handlers
  register_handler :internal, Event::Complete do |event|
    self.complete_event = event
    throw :pass
  end
end
response=(other) click to toggle source
Calls superclass method Punchblock::CommandNode#response=
# File lib/punchblock/component/component_node.rb, line 39
def response=(other)
  @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
end
stop!(options = {}) click to toggle source

Sends a Rayo stop message for the current component

# File lib/punchblock/component/component_node.rb, line 78
def stop!(options = {})
  raise InvalidActionError, "Cannot stop a #{self.class.name.split("::").last} that is #{state}" unless executing?
  stop_action.tap { |action| write_action action }
end
stop_action() click to toggle source

Create a Rayo stop message

@return [Stop] a Rayo stop message

# File lib/punchblock/component/component_node.rb, line 71
def stop_action
  Stop.new :component_id => component_id, :target_call_id => target_call_id
end
trigger_event_handler(event) click to toggle source
# File lib/punchblock/component/component_node.rb, line 26
def trigger_event_handler(event)
  trigger_handler :event, event
end
write_action(action) click to toggle source
# File lib/punchblock/component/component_node.rb, line 34
def write_action(action)
  client.execute_command action, :target_call_id => target_call_id, :component_id => component_id
  action
end