module Mongo::Server::Connectable
This provides common behavior for connection objects.
@since 2.0.0
Constants
- SSL
The ssl option prefix.
@since 2.1.0 @deprecated
- TIMEOUT
The default time in seconds to timeout an operation executed on a socket.
@since 2.0.0
@deprecated Timeouts on Ruby sockets aren't effective so this default
option is no longer used. Will be removed in driver version 3.0.
Attributes
@return [ Integer ] pid The process id when the connection was created.
Public Instance Methods
Determine if the server is connectable. This will check not only if the connection exists, but if messages can send to it successfully.
@example Is the server connectable?
connection.connectable?
@return [ true, false ] If the connection is connectable.
@since 2.1.0
@deprecated No longer necessary with Server
Selection specification.
# File lib/mongo/server/connectable.rb, line 51 def connectable?; end
Determine if the connection is currently connected.
@example Is the connection connected?
connection.connected?
@return [ true, false ] If connected.
@deprecated Use connectable?
instead
# File lib/mongo/server/connectable.rb, line 61 def connected? !!@socket && @socket.alive? end
Private Instance Methods
# File lib/mongo/server/connectable.rb, line 79 def ensure_connected ensure_same_process! begin connect! result = yield socket success = true result ensure unless success disconnect!(reason: :error) end end end
# File lib/mongo/server/connectable.rb, line 93 def ensure_same_process! if pid != Process.pid # When we reconnect here, CMAP events won't be correctly sent # since the CMAP spec does not permit a connection to be disconnected # and then reconnected log_warn("Detected PID change - Mongo client should have been reconnected (old pid #{pid}, new pid #{Process.pid}") disconnect!(reason: :stale) @closed = false @pid = Process.pid connect! end end
# File lib/mongo/server/connectable.rb, line 71 def ssl_options @ssl_options ||= if options[:ssl] options.select { |k, v| k.to_s.start_with?('ssl') } else {} end.freeze end