Top Level Namespace

Defined Under Namespace

Modules: Adhearsion, ComponentConfigurationSpecHelper, ComponentTester, PseudoGuidGenerator, Theatre Classes: BlankSlate, Class, EventSocket, FutureResource, Module, Numeric, Object, Range, String, SynchronizedHash

Constant Summary collapse

THEATRE_VERSION_STRING =
THEATRE_VERSION.join '.'

Instance Method Summary collapse

Instance Method Details

#ahn_log(*args) ⇒ Object



86
87
88
89
90
91
92
# File 'lib/adhearsion/logging.rb', line 86

def ahn_log(*args)
  if args.any?
    Adhearsion::Logging::DefaultAdhearsionLogger.info(*args)
  else
    Adhearsion::Logging::DefaultAdhearsionLogger
  end
end

#new_guidObject

This GUID implementation doesn’t adhere to the RFC which wants to make certain segments based on the MAC address of a network interface card and other wackiness. It’s sufficiently random for our needs.



20
21
22
# File 'lib/theatre/guid.rb', line 20

def new_guid
  [8,4,4,4,12].map { |segment_length| random_string(segment_length) }.join('-')
end

#random_characterObject



6
7
8
9
10
11
12
# File 'lib/theatre/guid.rb', line 6

def random_character
  case random_digit = rand(62)
    when  0...10 then random_digit.to_s
    when 10...36 then (random_digit + 55).chr
    when 36...62 then (random_digit + 61).chr
  end
end

#random_string(length_of_string = 8) ⇒ Object



14
15
16
# File 'lib/theatre/guid.rb', line 14

def random_string(length_of_string=8)
  Array.new(length_of_string) { random_character }.join
end

#threadObject

EventSocket is a small abstraction of TCPSocket which causes it to behave much like an EventMachine Connection object for the sake of better testability. The EventMachine Connection paradigm (as well as other networking libraries such as the Objective-C HTTP library) uses callbacks to signal different stages of a socket’s lifecycle.

A handler can be registered in one of two ways: through registrations on an object yielded by the constructor or pre-defined on the object given as a constructor parameter. Below is an example definition which uses the block way:

EventSocket.new do |handler|
  def handler.receive_data(data)
    # Do something here
  end
  def handler.disconnected
    # Do something here
  end
  def handler.connected
    # Do something here
  end
end

Note: this is also a valid way of defining block callbacks:

EventSocket.new do |handler|
  handler.receive_data { |data| do_something }
  handler.disconnected { do_something }
  handler.connected    { do_something }
end

and here is an example of using a handler object:

class MyCallbackHandler
  def receive_data(data) end
  def connected() end
  def disconnected() end
end
EventSocket.new(MyCallbackHandler.new)

If you wish to ask the EventSocket what state it is in, you can call the Thread-safe EventSocket#state method. The supported states are:

- :new
- :connected
- :stopped
- :connection_dropped

Note: the EventSocket’s state will be changed before these callbacks are executed. For example, if your “connected” callback queried its own EventSocket for its state, it will have already transitioned to the connected() state.

Warning: If an exception occurs in your EventSocket callbacks, they will be “eaten” and never bubbled up the call stack. You should always wrap your callbacks in a begin/rescue clause and handle exceptions explicitly.



52
# File 'lib/adhearsion/foundation/event_socket.rb', line 52

require "thread"