Class: Mongo::Server::ConnectionBase
- Inherits:
-
ConnectionCommon
- Object
- ConnectionCommon
- Mongo::Server::ConnectionBase
- Extended by:
- Forwardable
- Includes:
- Monitoring::Publishable
- Defined in:
- build/ruby-driver-v2.19/lib/mongo/server/connection_base.rb
Overview
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.
Direct Known Subclasses
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.
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.
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.
2097152
Constants included from Loggable
Instance Attribute Summary collapse
-
#description ⇒ Server::Description
readonly
private
Returns the server description for this connection, derived from the hello response for the handshake performed on this connection.
-
#options ⇒ Hash
readonly
Options The passed in options.
-
#server ⇒ Mongo::Address
readonly
Address The address to connect to.
Attributes included from Monitoring::Publishable
Attributes inherited from ConnectionCommon
Instance Method Summary collapse
- #app_metadata ⇒ Object
-
#dispatch(messages, context, options = {}) ⇒ Protocol::Message | nil
Dispatch a single message to the connection.
-
#generation ⇒ Integer | nil
Connection pool generation from which this connection was created.
-
#service_id ⇒ nil | Object
The service id, if any.
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
#description ⇒ Server::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.
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.
82 83 84 |
# File 'build/ruby-driver-v2.19/lib/mongo/server/connection_base.rb', line 82 def description @description end |
#options ⇒ Hash (readonly)
Returns options The passed in options.
53 54 55 |
# File 'build/ruby-driver-v2.19/lib/mongo/server/connection_base.rb', line 53 def @options end |
#server ⇒ Mongo::Address (readonly)
Returns address The address to connect to.
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_metadata ⇒ Object
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.[key] != [key] same = false break end end if same @server. else AppMetadata.new(.merge(purpose: @server..purpose)) end end end |
#dispatch(messages, context, options = {}) ⇒ Protocol::Message | nil
This method is named dispatch since ‘send’ is a core Ruby method on all objects.
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.
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(, context, = {}) # 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 .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 = .first deliver(, context, ) end |
#generation ⇒ Integer | nil
Connection pool generation from which this connection was created. May be nil.
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 || [:generation] end |
#service_id ⇒ nil | Object
Returns The service id, if any.
92 93 94 |
# File 'build/ruby-driver-v2.19/lib/mongo/server/connection_base.rb', line 92 def service_id description&.service_id end |