Class: Mongo::Server::ConnectionCommon

Inherits:
Object
  • Object
show all
Defined in:
build/ruby-driver-master/lib/mongo/server/connection_common.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.

Common methods used by both monitoring and non-monitoring connections.

Since:

  • 2.0.0

Direct Known Subclasses

ConnectionBase, Monitor::Connection

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#compressorString | nil (readonly)

The compressor negotiated during the handshake for this connection, if any.

This attribute is nil for connections that haven't completed the handshake yet, and for connections that negotiated no compression.

Returns:

  • (String | nil)

    The compressor.

Since:

  • 2.0.0



37
38
39
# File 'build/ruby-driver-master/lib/mongo/server/connection_common.rb', line 37

def compressor
  @compressor
end

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

Returns pid The process id when the connection was created.

Returns:

  • (Integer)

    pid The process id when the connection was created.

Since:

  • 2.0.0



53
54
55
# File 'build/ruby-driver-master/lib/mongo/server/connection_common.rb', line 53

def pid
  @pid
end

Instance Method Details

#connected?true, false

Deprecated.

Determine if the connection is currently connected.

Examples:

Is the connection connected?

connection.connected?

Returns:

  • (true, false)

    If connected.

Since:

  • 2.0.0



47
48
49
# File 'build/ruby-driver-master/lib/mongo/server/connection_common.rb', line 47

def connected?
  !!socket
end

#handshake_command(handshake_document) ⇒ Protocol::Message

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.

Build a command that should be used for connection handshake.

Parameters:

  • handshake_document (BSON::Document)

    Document that should be sent to a server for handshake purpose.

Returns:

  • (Protocol::Message)

    Command that should be sent to a server for handshake purposes.

Since:

  • 2.0.0



94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'build/ruby-driver-master/lib/mongo/server/connection_common.rb', line 94

def handshake_command(handshake_document)
  if handshake_document['apiVersion']
    Protocol::Msg.new(
      [], {}, handshake_document.merge({'$db' => Database::ADMIN})
    )
  else
    Protocol::Query.new(
      Database::ADMIN,
      Database::COMMAND,
      handshake_document,
      :limit => -1
    )
  end
end

#handshake_document(app_metadata, speculative_auth_doc: nil, load_balancer: false, server_api: nil) ⇒ BSON::Document

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.

Build a document that should be used for connection handshake.

Parameters:

  • app_metadata (Server::AppMetadata)

    Application metadata

  • speculative_auth_doc (BSON::Document) (defaults to: nil)

    The speculative authentication document, if any.

  • load_balancer (true | false) (defaults to: false)

    Whether the connection is to a load balancer.

  • server_api (Hash | nil) (defaults to: nil)

    server_api Server API version.

Returns:

  • (BSON::Document)

    Document that should be sent to a server for handshake purposes.

Since:

  • 2.0.0



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'build/ruby-driver-master/lib/mongo/server/connection_common.rb', line 68

def handshake_document(, speculative_auth_doc: nil, load_balancer: false, server_api: nil)
  serv_api = .server_api || server_api
  document = if serv_api
               HELLO_DOC.merge(Utils.transform_server_api(serv_api))
             else
               LEGACY_HELLO_DOC
             end
  document.merge(.validated_document).tap do |doc|
    if speculative_auth_doc
      doc.update(speculativeAuthenticate: speculative_auth_doc)
    end
    if load_balancer
      doc.update(loadBalanced: true)
    end
  end
end