Method: Mongo::Server::Monitor::Connection#initialize

Defined in:
lib/mongo/server/monitor/connection.rb

#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.

Note:

Monitoring connections do not authenticate.

Creates a new connection object to the specified target address with the specified options.

The constructor does not perform any I/O (and thus does not create sockets nor handshakes); call connect! method on the connection object to create the network connection.

Parameters:

  • The address the connection is for.

  • (defaults to: {})

    The connection options.

Options Hash (options):

  • :app_metadata (Mongo::Server::Monitor::AppMetadata)

    Metadata to use for handshake. If missing or nil, handshake will not be performed. Although a Mongo::Server::AppMetadata instance will also work, monitoring connections are meant to use Mongo::Server::Monitor::AppMetadata instances in order to omit performing SCRAM negotiation with the server, as monitoring sockets do not authenticate.

  • :compressors (Array<String>)

    A list of potential compressors to use, in order of preference. The driver chooses the first compressor that is also supported by the server. Currently the driver only supports ‘zstd’, ‘snappy’ and ‘zlib’.

  • :connect_timeout (Float)

    The timeout, in seconds, to use for network operations. This timeout is used for all socket operations rather than connect calls only, contrary to what the name implies,

Since:

  • 2.0.0

API:

  • private



58
59
60
61
62
63
64
65
66
67
68
# File 'lib/mongo/server/monitor/connection.rb', line 58

def initialize(address, options = {})
  @address = address
  @options = options.dup.freeze
  unless @app_metadata = options[:app_metadata]
    raise ArgumentError, 'App metadata is required'
  end
  @socket = nil
  @pid = Process.pid
  @compressor = nil
  @hello_ok = false
end