Module: Mongo::Server::Connectable
- Included in:
- Connection, Monitor::Connection
- Defined in:
- lib/mongo/server/connectable.rb
Overview
This provides common behaviour for connection objects.
Constant Summary collapse
- SSL =
The ssl option prefix.
'ssl'.freeze
- TIMEOUT =
Deprecated.
Timeouts on Ruby sockets aren’t effective so this default option is no longer used. Will be removed in driver version 3.0.
The default time in seconds to timeout an operation executed on a socket.
5.freeze
Instance Attribute Summary collapse
-
#address ⇒ Mongo::Address
readonly
Address The address to connect to.
-
#options ⇒ Hash
readonly
Options The passed in options.
-
#pid ⇒ Integer
readonly
Pid The process id when the connection was created.
Instance Method Summary collapse
-
#connectable? ⇒ true, false
Determine if the server is connectable.
-
#connected? ⇒ true, false
deprecated
Deprecated.
Use #connectable? instead
-
#timeout ⇒ Float
Get the timeout to execute an operation on a socket.
Instance Attribute Details
#address ⇒ Mongo::Address (readonly)
Returns address The address to connect to.
38 39 40 |
# File 'lib/mongo/server/connectable.rb', line 38 def address @address end |
#options ⇒ Hash (readonly)
Returns options The passed in options.
41 42 43 |
# File 'lib/mongo/server/connectable.rb', line 41 def end |
#pid ⇒ Integer (readonly)
Returns pid The process id when the connection was created.
44 45 46 |
# File 'lib/mongo/server/connectable.rb', line 44 def pid @pid end |
Instance Method Details
#connectable? ⇒ true, false
Determine if the server is connectable. This will check not only if the connection exists, but if messages can send to it successfully.
55 56 57 |
# File 'lib/mongo/server/connectable.rb', line 55 def connectable? begin; ping; rescue; false; end end |
#connected? ⇒ true, false
Use #connectable? instead
Determine if the connection is currently connected.
67 68 69 |
# File 'lib/mongo/server/connectable.rb', line 67 def connected? !!@socket && @socket.alive? end |
#timeout ⇒ Float
Get the timeout to execute an operation on a socket.
79 80 81 |
# File 'lib/mongo/server/connectable.rb', line 79 def timeout @timeout ||= [:socket_timeout] end |