Class: Faye::Transport
- Inherits:
-
Object
show all
- Includes:
- Logging
- Defined in:
- lib/faye/network/transport.rb
Constant Summary
Constants included
from Logging
Logging::DEFAULT_LOG_LEVEL, Logging::LOG_LEVELS
Class Attribute Summary collapse
Attributes included from Logging
#log_level
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from Logging
#log
Constructor Details
#initialize(client, endpoint) ⇒ Transport
Returns a new instance of Transport.
10
11
12
13
14
|
# File 'lib/faye/network/transport.rb', line 10
def initialize(client, endpoint)
debug('Created new ? transport for ?', connection_type, endpoint)
@client = client
@endpoint = endpoint
end
|
Class Attribute Details
.connection_type ⇒ Object
Returns the value of attribute connection_type.
40
41
42
|
# File 'lib/faye/network/transport.rb', line 40
def connection_type
@connection_type
end
|
Class Method Details
.get(client, connection_types = nil) ⇒ Object
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
# File 'lib/faye/network/transport.rb', line 42
def get(client, connection_types = nil)
endpoint = client.endpoint
connection_types ||= supported_connection_types
candidate_class = @transports.find do |(type, klass)|
connection_types.include?(type) and
klass.usable?(endpoint)
end
unless candidate_class
raise "Could not find a usable connection type for #{ endpoint }"
end
candidate_class.last.new(client, endpoint)
end
|
.register(type, klass) ⇒ Object
58
59
60
61
|
# File 'lib/faye/network/transport.rb', line 58
def register(type, klass)
@transports << [type, klass]
klass.connection_type = type
end
|
.supported_connection_types ⇒ Object
63
64
65
|
# File 'lib/faye/network/transport.rb', line 63
def supported_connection_types
@transports.map { |t| t.first }
end
|
Instance Method Details
#connection_type ⇒ Object
16
17
18
|
# File 'lib/faye/network/transport.rb', line 16
def connection_type
self.class.connection_type
end
|
#receive(responses) ⇒ Object
26
27
28
29
|
# File 'lib/faye/network/transport.rb', line 26
def receive(responses)
debug('Client ? received from ?: ?', @client.client_id, @endpoint, responses)
responses.each { |response| @client.receive_message(response) }
end
|
#retry_block(message, timeout) ⇒ Object
31
32
33
34
35
|
# File 'lib/faye/network/transport.rb', line 31
def retry_block(message, timeout)
lambda do
EventMachine.add_timer(timeout) { request(message, 2 * timeout) }
end
end
|
#send(messages, timeout) ⇒ Object
20
21
22
23
24
|
# File 'lib/faye/network/transport.rb', line 20
def send(messages, timeout)
messages = [messages].flatten
debug('Client ? sending message to ?: ?', @client.client_id, @endpoint, messages)
request(messages, timeout)
end
|