Class: Dialed::HTTP::Connection
- Inherits:
-
Object
- Object
- Dialed::HTTP::Connection
show all
- Defined in:
- lib/dialed/http/connection.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(configuration) ⇒ Connection
Returns a new instance of Connection.
18
19
20
21
22
|
# File 'lib/dialed/http/connection.rb', line 18
def initialize(configuration)
@semaphore = Async::Semaphore.new
@configuration = configuration
end
|
Instance Attribute Details
#configuration ⇒ Object
Returns the value of attribute configuration.
6
7
8
|
# File 'lib/dialed/http/connection.rb', line 6
def configuration
@configuration
end
|
Instance Method Details
#address ⇒ Object
28
29
30
|
# File 'lib/dialed/http/connection.rb', line 28
def address
"#{host}:#{port}"
end
|
#close ⇒ Object
69
70
71
|
# File 'lib/dialed/http/connection.rb', line 69
def close
raise NotImplementedError, 'Subclasses must implement close'
end
|
#closed? ⇒ Boolean
32
33
34
|
# File 'lib/dialed/http/connection.rb', line 32
def closed?
internal_connection.closed?
end
|
#connect ⇒ Object
def call(…)
Sync do
@semaphore2.acquire do
Sync do
reconnect! if closed?
end
internal_connection.call(...)
end
end
end
51
52
53
54
55
56
57
|
# File 'lib/dialed/http/connection.rb', line 51
def connect
open?
rescue StandardError => e
@internal_connection = NilConnection.new
raise e
end
|
#nil_connection? ⇒ Boolean
59
60
61
|
# File 'lib/dialed/http/connection.rb', line 59
def nil_connection?
false
end
|
#open? ⇒ Boolean
36
37
38
|
# File 'lib/dialed/http/connection.rb', line 36
def open?
!closed?
end
|
#ping ⇒ Object
24
25
26
|
# File 'lib/dialed/http/connection.rb', line 24
def ping
internal_connection.send_ping(SecureRandom.bytes(8))
end
|
#reconnect! ⇒ Object
63
64
65
66
67
|
# File 'lib/dialed/http/connection.rb', line 63
def reconnect!
@semaphore.acquire do
@internal_connection = create_internal_connection
end
end
|