Class: Bones::RPC::Connection
- Inherits:
-
Object
- Object
- Bones::RPC::Connection
- Defined in:
- lib/bones/rpc/connection.rb,
lib/bones/rpc/connection/socket/connectable.rb
Overview
This class contains behaviour of Bones::RPC socket connections.
Direct Known Subclasses
Defined Under Namespace
Modules: Socket
Constant Summary collapse
- TIMEOUT =
The default connection timeout, in seconds.
5
Instance Attribute Summary collapse
- #node ⇒ Object readonly
- #socket ⇒ Object readonly
Class Method Summary collapse
Instance Method Summary collapse
-
#alive? ⇒ true, false
Is the connection alive?.
- #cleanup_socket(socket) ⇒ Object
-
#connect ⇒ TCPSocket
Connect to the server defined by @host, @port without timeout @timeout.
-
#connected? ⇒ true, false
Is the connection connected?.
-
#disconnect ⇒ nil
Disconnect from the server.
- #host ⇒ Object
-
#initialize(node) ⇒ Connection
constructor
A new instance of Connection.
- #inspect ⇒ Object
- #options ⇒ Object
- #port ⇒ Object
- #timeout ⇒ Object
- #write(operations) ⇒ Object
Constructor Details
#initialize(node) ⇒ Connection
Returns a new instance of Connection.
100 101 102 103 |
# File 'lib/bones/rpc/connection.rb', line 100 def initialize(node) @node = node @socket = nil end |
Instance Attribute Details
#node ⇒ Object (readonly)
17 18 19 |
# File 'lib/bones/rpc/connection.rb', line 17 def node @node end |
#socket ⇒ Object (readonly)
17 18 19 |
# File 'lib/bones/rpc/connection.rb', line 17 def socket @socket end |
Class Method Details
.writer_class(klass = nil) ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/bones/rpc/connection.rb', line 19 def self.writer_class(klass = nil) if klass.nil? @writer_class else @writer_class = klass end end |
Instance Method Details
#alive? ⇒ true, false
Is the connection alive?
35 36 37 |
# File 'lib/bones/rpc/connection.rb', line 35 def alive? connected? ? @socket.alive? : false end |
#cleanup_socket(socket) ⇒ Object
39 40 41 42 43 44 45 |
# File 'lib/bones/rpc/connection.rb', line 39 def cleanup_socket(socket) if @writer @writer.async.terminate if @writer.alive? @writer = nil end @node.cleanup_socket(socket) end |
#connect ⇒ TCPSocket
Connect to the server defined by @host, @port without timeout @timeout.
55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/bones/rpc/connection.rb', line 55 def connect if @writer @writer.terminate @writer = nil end @socket = if !![:ssl] self.class::Socket::SSL.connect(host, port, timeout) else self.class::Socket::TCP.connect(host, port, timeout) end writer return true end |
#connected? ⇒ true, false
Is the connection connected?
77 78 79 |
# File 'lib/bones/rpc/connection.rb', line 77 def connected? !!@socket end |
#disconnect ⇒ nil
Disconnect from the server.
89 90 91 92 93 94 |
# File 'lib/bones/rpc/connection.rb', line 89 def disconnect @socket.close rescue ensure @socket = nil end |
#host ⇒ Object
96 97 98 |
# File 'lib/bones/rpc/connection.rb', line 96 def host node.address.ip end |
#inspect ⇒ Object
105 106 107 |
# File 'lib/bones/rpc/connection.rb', line 105 def inspect "<#{self.class} \"#{node.address.resolved}\">" end |
#options ⇒ Object
109 110 111 |
# File 'lib/bones/rpc/connection.rb', line 109 def node. end |
#port ⇒ Object
113 114 115 |
# File 'lib/bones/rpc/connection.rb', line 113 def port node.address.port end |
#timeout ⇒ Object
117 118 119 |
# File 'lib/bones/rpc/connection.rb', line 117 def timeout [:timeout] || Connection::TIMEOUT end |
#write(operations) ⇒ Object
121 122 123 |
# File 'lib/bones/rpc/connection.rb', line 121 def write(operations) raise NotImplementedError, "Connection#write not implemented for this backend" end |