Top Level Namespace
- Includes:
- PseudoGuidGenerator
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 '.'
- Infinity =
1.0/0.0
Instance Method Summary collapse
- #ahn_log(*args) ⇒ Object
-
#thread ⇒ Object
EventSocket is a small abstraction of TCPSocket which causes it to behave much like an EventMachine Connection object for the sake of better testability.
Methods included from PseudoGuidGenerator
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 |
#thread ⇒ Object
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" |