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


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)


79
80
81
82
83
# File 'lib/adhearsion/calls.rb', line 79

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
38
39
# File 'lib/adhearsion/calls.rb', line 24

def remove_inactive_call(call)
  @mutex.synchronize do
    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
end

#restart_supervisorObject


57
58
59
60
# File 'lib/adhearsion/calls.rb', line 57

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

#with_tag(tag) ⇒ Object


41
42
43
44
45
46
47
48
49
50
51
# File 'lib/adhearsion/calls.rb', line 41

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

#with_uri(uri) ⇒ Object


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

def with_uri(uri)
  by_uri[uri]
end