Class: Faye::Transport
Defined Under Namespace
Classes: Http, Local
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 Timeouts
#add_timeout, #remove_timeout
Methods included from Logging
#log
Constructor Details
#initialize(client, endpoint) ⇒ Transport
Returns a new instance of Transport.
10
11
12
13
14
15
|
# File 'lib/faye/transport/transport.rb', line 10
def initialize(client, endpoint)
debug('Created new ? transport for ?', connection_type, endpoint)
@client = client
@endpoint = endpoint
@outbox = []
end
|
Class Attribute Details
.connection_type ⇒ Object
Returns the value of attribute connection_type.
69
70
71
|
# File 'lib/faye/transport/transport.rb', line 69
def connection_type
@connection_type
end
|
Class Method Details
.get(client, connection_types = nil) ⇒ Object
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
|
# File 'lib/faye/transport/transport.rb', line 71
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
87
88
89
90
|
# File 'lib/faye/transport/transport.rb', line 87
def register(type, klass)
@transports << [type, klass]
klass.connection_type = type
end
|
.supported_connection_types ⇒ Object
92
93
94
|
# File 'lib/faye/transport/transport.rb', line 92
def supported_connection_types
@transports.map { |t| t.first }
end
|
Instance Method Details
#batching? ⇒ Boolean
17
18
19
|
# File 'lib/faye/transport/transport.rb', line 17
def batching?
true
end
|
#connection_type ⇒ Object
21
22
23
|
# File 'lib/faye/transport/transport.rb', line 21
def connection_type
self.class.connection_type
end
|
#flush ⇒ Object
42
43
44
45
46
47
48
49
50
51
52
53
|
# File 'lib/faye/transport/transport.rb', line 42
def flush
remove_timeout(:publish)
if @outbox.size > 1 and @connection_message
@connection_message['advice'] = {'timeout' => 0}
end
request(@outbox, @timeout)
@connection_message = nil
@outbox = []
end
|
#receive(responses) ⇒ Object
55
56
57
58
|
# File 'lib/faye/transport/transport.rb', line 55
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
60
61
62
63
64
|
# File 'lib/faye/transport/transport.rb', line 60
def retry_block(message, timeout)
lambda do
EventMachine.add_timer(timeout) { request(message, 2 * timeout) }
end
end
|
#send(message, timeout) ⇒ Object
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
# File 'lib/faye/transport/transport.rb', line 25
def send(message, timeout)
debug('Client ? sending message to ?: ?', @client.client_id, @endpoint, message)
return request([message], timeout) unless batching?
@outbox << message
@timeout = timeout
return flush if message['channel'] == Channel::HANDSHAKE
if message['channel'] == Channel::CONNECT
@connection_message = message
end
add_timeout(:publish, Engine::MAX_DELAY) { flush }
end
|