Class: Adhearsion::Calls

Inherits:
Object show all
Defined in:
lib/adhearsion/calls.rb

Overview

This manages the list of calls the Adhearsion service receives

Defined Under Namespace

Classes: Supervisor

Instance Method Summary collapse

Constructor Details

#initializeCalls

Returns a new instance of Calls


9
10
11
12
13
# File 'lib/adhearsion/calls.rb', line 9

def initialize
  @mutex = ::Monitor.new
  @calls = {}
  restart_supervisor
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object (private)


75
76
77
78
79
# File 'lib/adhearsion/calls.rb', line 75

def method_missing(method, *args, &block)
  @mutex.synchronize do
    @calls.send method, *args, &block
  end
end

Instance Method Details

#<<(call) ⇒ Object


15
16
17
18
19
20
21
22
# File 'lib/adhearsion/calls.rb', line 15

def <<(call)
  @supervisor.link call
  @mutex.synchronize do
    self[call.id] = call
    by_uri[call.uri] = call
  end
  self
end

#remove_inactive_call(call) ⇒ Object


24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/adhearsion/calls.rb', line 24

def remove_inactive_call(call)
  if call_is_dead?(call)
    call_id = key call
    delete call_id if call_id

    remove_call_uri call
  elsif call.respond_to?(:id)
    delete call.id
    remove_call_uri call
  else
    call_actor = delete call
    remove_call_uri call_actor
  end
end

#restart_supervisorObject


53
54
55
56
# File 'lib/adhearsion/calls.rb', line 53

def restart_supervisor
  @supervisor.terminate if @supervisor
  @supervisor = Supervisor.new self
end

#with_tag(tag) ⇒ Object


39
40
41
42
43
44
45
46
47
# File 'lib/adhearsion/calls.rb', line 39

def with_tag(tag)
  values.find_all do |call|
    begin
      call.tagged_with? tag
    rescue Call::ExpiredError
      false
    end
  end
end

#with_uri(uri) ⇒ Object


49
50
51
# File 'lib/adhearsion/calls.rb', line 49

def with_uri(uri)
  by_uri[uri]
end