Class: Punchblock::Component::ComponentNode

Inherits:
Punchblock::CommandNode show all
Includes:
HasGuardedHandlers
Defined in:
lib/punchblock/component/component_node.rb

Direct Known Subclasses

Asterisk::AGI::Command, Asterisk::AMI::Action, Input, Output, Prompt, ReceiveFax, Record, SendFax

Instance Attribute Summary

Attributes inherited from RayoNode

#client, #connection, #original_component

Instance Method Summary (collapse)

Methods inherited from Punchblock::CommandNode

#response

Methods inherited from RayoNode

#==, class_from_registration, from_xml, #inherit, #inspect, #rayo_attributes, #rayo_children, register, #source, #to_rayo, #to_xml

Constructor Details

- (ComponentNode) initialize(*args)

Returns a new instance of ComponentNode



8
9
10
11
12
13
# 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

Instance Method Details

- (Object) add_event(event)



22
23
24
# File 'lib/punchblock/component/component_node.rb', line 22

def add_event(event)
  trigger_handler :internal, event
end

- (Object) complete_event(timeout = nil)



50
51
52
# File 'lib/punchblock/component/component_node.rb', line 50

def complete_event(timeout = nil)
  @complete_event_resource.resource timeout
end

- (Object) complete_event=(other)



54
55
56
57
58
59
60
61
62
63
64
# 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

- (Object) register_event_handler(*guards, &block)



30
31
32
# File 'lib/punchblock/component/component_node.rb', line 30

def register_event_handler(*guards, &block)
  register_handler :event, *guards, &block
end

- (Object) register_internal_handlers



15
16
17
18
19
20
# 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

- (Object) response=(other)



39
40
41
42
43
44
45
46
47
48
# 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

- (Object) stop!(options = {})

Sends a Rayo stop message for the current component

Raises:



78
79
80
81
# 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) stop_action

Create a Rayo stop message

Returns:

  • (Stop)

    a Rayo stop message



71
72
73
# 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

- (Object) trigger_event_handler(event)



26
27
28
# File 'lib/punchblock/component/component_node.rb', line 26

def trigger_event_handler(event)
  trigger_handler :event, event
end

- (Object) write_action(action)



34
35
36
37
# 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