Class: Mongo::Server::Monitor::Connection
- Inherits:
-
Object
- Object
- Mongo::Server::Monitor::Connection
- Includes:
- Connectable
- Defined in:
- lib/mongo/server/monitor/connection.rb
Overview
This class models the monitor connections and their behavior.
Constant Summary collapse
- ISMASTER =
The command used for determining server status.
{ :ismaster => 1 }.freeze
- ISMASTER_MESSAGE =
The constant for the ismaster command.
Protocol::Query.new(Database::ADMIN, Database::COMMAND, ISMASTER, :limit => -1)
- ISMASTER_BYTES =
The raw bytes for the ismaster message.
ISMASTER_MESSAGE.serialize.to_s.freeze
- CONNECT_TIMEOUT =
The default time in seconds to timeout a connection attempt.
10.freeze
Constants included from Connectable
Connectable::SSL, Connectable::TIMEOUT
Instance Attribute Summary
Attributes included from Connectable
Instance Method Summary collapse
-
#connect! ⇒ true
Tell the underlying socket to establish a connection to the host.
-
#disconnect! ⇒ true
Disconnect the connection.
-
#initialize(address, options = {}) ⇒ Connection
constructor
private
Initialize a new socket connection from the client to the server.
-
#ismaster ⇒ BSON::Document
Send the preserialized ismaster call.
-
#timeout ⇒ Float
Get the connection timeout.
Methods included from Connectable
Constructor Details
#initialize(address, options = {}) ⇒ Connection
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Connection must never be directly instantiated outside of a Monitor.
Initialize a new socket connection from the client to the server.
112 113 114 115 116 117 118 |
# File 'lib/mongo/server/monitor/connection.rb', line 112 def initialize(address, = {}) @address = address @options = .freeze @ssl_options = .reject { |k, v| !k.to_s.start_with?(SSL) } @socket = nil @pid = Process.pid end |
Instance Method Details
#connect! ⇒ true
This method mutates the connection class by setting a socket if one previously did not exist.
Tell the underlying socket to establish a connection to the host.
71 72 73 74 75 76 77 |
# File 'lib/mongo/server/monitor/connection.rb', line 71 def connect! unless socket @socket = address.socket(timeout, ) socket.connect! end true end |
#disconnect! ⇒ true
This method mutates the connection by setting the socket to nil if the closing succeeded.
Disconnect the connection.
90 91 92 93 94 95 96 |
# File 'lib/mongo/server/monitor/connection.rb', line 90 def disconnect! if socket socket.close @socket = nil end true end |
#ismaster ⇒ BSON::Document
Send the preserialized ismaster call.
53 54 55 56 57 58 |
# File 'lib/mongo/server/monitor/connection.rb', line 53 def ismaster ensure_connected do |socket| socket.write(ISMASTER_BYTES) Protocol::Reply.deserialize(socket).documents[0] end end |
#timeout ⇒ Float
Get the connection timeout.
128 129 130 |
# File 'lib/mongo/server/monitor/connection.rb', line 128 def timeout @timeout ||= [:connect_timeout] || CONNECT_TIMEOUT end |