Represents a single server on the server side that can be standalone, part of a replica set, or a mongos.
@since 2.0.0
| CONNECT_TIMEOUT | = | 10.freeze |
The default time in seconds to timeout a connection attempt.
@since 2.4.3 |
| heartbeat_frequency | -> | heartbeat_frequency_seconds |
| address | [R] | @return [ String ] The configured address for the server. |
| cluster | [R] | @return [ Cluster ] cluster The server cluster. |
| monitor | [R] | @return [ Monitor ] monitor The server monitor. |
| monitoring | [R] | @return [ Monitoring ] monitoring The monitoring. |
| options | [R] | @return [ Hash ] The options hash. |
When the server is flagged for garbage collection, stop the monitor thread.
@example Finalize the object.
Server.finalize(monitor)
@param [ Server::Monitor ] monitor The server monitor.
@since 2.2.0
Instantiate a new server object. Will start the background refresh and subscribe to the appropriate events.
@api private
@example Initialize the server.
Mongo::Server.new('127.0.0.1:27017', cluster, monitoring, listeners)
@note Server must never be directly instantiated outside of a Cluster.
@param [ Address ] address The host:port address to connect to. @param [ Cluster ] cluster The cluster the server belongs to. @param [ Monitoring ] monitoring The monitoring. @param [ Event::Listeners ] event_listeners The event listeners. @param [ Hash ] options The server options.
@option options [ Boolean ] :monitor For internal driver use only:
whether to monitor the server after instantiating it.
@option options [ true, false ] :monitoring_io For internal driver
use only. Set to false to prevent SDAM-related I/O from being done by this server. Note: setting this option to false will make the server non-functional. It is intended for use in tests which manually invoke SDAM state transitions.
@since 2.0.0
Is this server equal to another?
@example Is the server equal to the other?
server == other
@param [ Object ] other The object to compare to.
@return [ true, false ] If the servers are equal.
@since 2.0.0
Determine if a connection to the server is able to be established and messages can be sent to it.
@example Is the server connectable?
server.connectable?
@return [ true, false ] If the server is connectable.
@since 2.1.0
@deprecated No longer necessary with Server Selection specification.
Whether the server is connected.
@return [ true|false ] Whether the server is connected.
@api private @since 2.7.0
Disconnect the server from the connection.
@example Disconnect the server.
server.disconnect!
@param [ Boolean ] wait Whether to wait for background threads to
finish running.
@return [ true ] Always true with no exception.
@since 2.0.0
Handle authentication failure.
@example Handle possible authentication failure.
server.handle_auth_failure! do
Auth.get(user).login(self)
end
@raise [ Auth::Unauthorized ] If the authentication failed.
@return [ Object ] The result of the block execution.
@since 2.3.0
Get a pretty printed server inspection.
@example Get the server inspection.
server.inspect
@return [ String ] The nice inspection string.
@since 2.0.0
Determine if the provided tags are a subset of the server‘s tags.
@example Are the provided tags a subset of the server‘s tags.
server.matches_tag_set?({ 'rack' => 'a', 'dc' => 'nyc' })
@param [ Hash ] tag_set The tag set to compare to the server‘s tags.
@return [ true, false ] If the provided tags are a subset of the server‘s tags.
@since 2.0.0
Get the connection pool for this server.
@example Get the connection pool for the server.
server.pool
@return [ Mongo::Server::ConnectionPool ] The connection pool.
@since 2.0.0
Restart the server monitor.
@example Restart the server monitor.
server.reconnect!
@return [ true ] Always true.
@since 2.1.0
Will writes sent to this server be retried.
@example Will writes be retried.
server.retry_writes?
@return [ true, false ] If writes will be retried.
@note Retryable writes are only available on server versions 3.6+ and with
sharded clusters or replica sets.
@since 2.5.0
Start monitoring the server.
Used internally by the driver to add a server to a cluster while delaying monitoring until the server is in the cluster.
@api private
Marks server unknown and publishes the associated SDAM event (server description changed).
@since 2.4.0, SDAM events are sent as of version 2.7.0
Execute a block of code with a connection, that is checked out of the server‘s pool and then checked back in.
@example Send a message with the connection.
server.with_connection do |connection|
connection.dispatch([ command ])
end
@return [ Object ] The result of the block execution.
@since 2.3.0