Class: Mongo::Server::ConnectionBase

Inherits:
ConnectionCommon show all
Extended by:
Forwardable
Includes:
Monitoring::Publishable
Defined in:
lib/mongo/server/connection_base.rb

Overview

Note:

Although methods of this module are part of the public API, the fact that these methods are defined on this module and not on the classes which include this module is not part of the public API.

This class encapsulates common connection functionality.

Since:

  • 2.0.0

Direct Known Subclasses

Connection, PendingConnection

Constant Summary collapse

DEFAULT_MAX_BSON_OBJECT_SIZE =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

The maximum allowed size in bytes that a user-supplied document may take up when serialized, if the server’s ismaster response does not include maxBsonObjectSize field.

The commands that are sent to the server may exceed this size by MAX_BSON_COMMAND_OVERHEAD.

Since:

  • 2.0.0

16777216
MAX_BSON_COMMAND_OVERHEAD =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

The additional overhead allowed for command data (i.e. fields added to the command document by the driver, as opposed to documents provided by the user) when serializing a complete command to BSON.

Since:

  • 2.0.0

16384
REDUCED_MAX_BSON_SIZE =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Since:

  • 2.0.0

2097152

Constants included from Loggable

Loggable::PREFIX

Instance Attribute Summary collapse

Attributes included from Monitoring::Publishable

#monitoring

Attributes inherited from ConnectionCommon

#compressor, #pid

Instance Method Summary collapse

Methods included from Monitoring::Publishable

#publish_cmap_event, #publish_event, #publish_sdam_event

Methods included from Loggable

#log_debug, #log_error, #log_fatal, #log_info, #log_warn, #logger

Methods inherited from ConnectionCommon

#connected?

Instance Attribute Details

#descriptionServer::Description (readonly)

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:

A connection object that hasn’t yet connected (handshaken and authenticated, if authentication is required) does not have a description. While handshaking and authenticating the driver must be using global defaults, in particular not assuming that the properties of a particular connection are the same as properties of other connections made to the same address (since the server on the other end could have been shut down and a different server version could have been launched).

Returns the server description for this connection, derived from the isMaster response for the handshake performed on this connection.

Returns:

Since:

  • 2.0.0



79
80
81
# File 'lib/mongo/server/connection_base.rb', line 79

def description
  @description
end

#optionsHash (readonly)

Returns options The passed in options.

Returns:

  • (Hash)

    options The passed in options.

Since:

  • 2.0.0



50
51
52
# File 'lib/mongo/server/connection_base.rb', line 50

def options
  @options
end

#serverMongo::Address (readonly)

Returns address The address to connect to.

Returns:

Since:

  • 2.0.0



55
56
57
# File 'lib/mongo/server/connection_base.rb', line 55

def server
  @server
end

Instance Method Details

#app_metadataObject

Since:

  • 2.0.0



96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/mongo/server/connection_base.rb', line 96

def 
   ||= begin
    same = true
    ::AUTH_OPTION_KEYS.each do |key|
      if @server.options[key] != options[key]
        same = false
        break
      end
    end
    if same
      @server.
    else
      .new(options)
    end
  end
end

#dispatch(messages, operation_id = nil, client = nil, options = {}) ⇒ Protocol::Message | nil

Note:

This method is named dispatch since ‘send’ is a core Ruby method on all objects.

Note:

For backwards compatibility, this method accepts the messages as an array. However, exactly one message must be given per invocation.

Dispatch a single message to the connection. If the message requires a response, a reply will be returned.

Examples:

Dispatch the message.

connection.dispatch([ insert ])

Parameters:

  • messages (Array<Message>)

    A one-element array containing the message to dispatch.

  • operation_id (Integer) (defaults to: nil)

    The operation id to link messages.

  • options (Hash) (defaults to: {})

Options Hash (options):

  • :deserialize_as_bson (Boolean)

    Whether to deserialize the response to this message using BSON objects in place of native Ruby types wherever possible.

Returns:

Since:

  • 2.0.0



137
138
139
140
141
142
143
144
145
146
# File 'lib/mongo/server/connection_base.rb', line 137

def dispatch(messages, operation_id = nil, client = nil, options = {})
  # The monitoring code does not correctly handle multiple messages,
  # and the driver internally does not send more than one message at
  # a time ever. Thus prohibit multiple message use for now.
  if messages.length != 1
    raise ArgumentError, 'Can only dispatch one message at a time'
  end
  message = messages.first
  deliver(message, client, options)
end

#generationInteger | nil

Connection pool generation from which this connection was created. May be nil.

Returns:

  • (Integer | nil)

    Connection pool generation.

Since:

  • 2.0.0



92
93
94
# File 'lib/mongo/server/connection_base.rb', line 92

def generation
  options[:generation]
end