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 =
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.
34 35 36 |
# File 'lib/mongo/server/connectable.rb', line 34 def address @address end |
#options ⇒ Hash (readonly)
Returns options The passed in options.
37 38 39 |
# File 'lib/mongo/server/connectable.rb', line 37 def @options end |
#pid ⇒ Integer (readonly)
Returns pid The process id when the connection was created.
40 41 42 |
# File 'lib/mongo/server/connectable.rb', line 40 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.
51 52 53 |
# File 'lib/mongo/server/connectable.rb', line 51 def connectable? begin; ping; rescue; false; end end |
#connected? ⇒ true, false
Use #connectable? instead
Determine if the connection is currently connected.
63 64 65 |
# File 'lib/mongo/server/connectable.rb', line 63 def connected? !!@socket && @socket.alive? end |
#timeout ⇒ Float
Get the timeout to execute an operation on a socket.
75 76 77 |
# File 'lib/mongo/server/connectable.rb', line 75 def timeout @timeout ||= [:socket_timeout] || TIMEOUT end |