Class: Mongo::Server::ConnectionBase

Inherits:
ConnectionCommon show all
Extended by:
Forwardable
Includes:
Monitoring::Publishable
Defined in:
build/ruby-driver-v2.19/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 hello 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?, #handshake_command, #handshake_document

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 hello response for the handshake performed on this connection.

Returns:

Since:

  • 2.0.0



82
83
84
# File 'build/ruby-driver-v2.19/lib/mongo/server/connection_base.rb', line 82

def description
  @description
end

#optionsHash (readonly)

Returns options The passed in options.

Returns:

  • (Hash)

    options The passed in options.

Since:

  • 2.0.0



53
54
55
# File 'build/ruby-driver-v2.19/lib/mongo/server/connection_base.rb', line 53

def options
  @options
end

#serverMongo::Address (readonly)

Returns address The address to connect to.

Returns:

Since:

  • 2.0.0



58
59
60
# File 'build/ruby-driver-v2.19/lib/mongo/server/connection_base.rb', line 58

def server
  @server
end

Instance Method Details

#app_metadataObject

Since:

  • 2.0.0



107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'build/ruby-driver-v2.19/lib/mongo/server/connection_base.rb', line 107

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

#dispatch(messages, context, 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.

  • context (Operation::Context)

    The operation context.

  • 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:

Raises:

Since:

  • 2.0.0



150
151
152
153
154
155
156
157
158
159
160
161
162
# File 'build/ruby-driver-v2.19/lib/mongo/server/connection_base.rb', line 150

def dispatch(messages, context, 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
  if description.unknown?
    raise Error::InternalDriverError, "Cannot dispatch a message on a connection with unknown description: #{description.inspect}"
  end
  message = messages.first
  deliver(message, context, 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



100
101
102
103
104
105
# File 'build/ruby-driver-v2.19/lib/mongo/server/connection_base.rb', line 100

def generation
  # If the connection is to a load balancer, @generation is set
  # after handshake completes. If the connection is to another server
  # type, generation is specified during connection creation.
  @generation || options[:generation]
end

#service_idnil | Object

Returns The service id, if any.

Returns:

  • (nil | Object)

    The service id, if any.

Since:

  • 2.0.0



92
93
94
# File 'build/ruby-driver-v2.19/lib/mongo/server/connection_base.rb', line 92

def service_id
  description&.service_id
end