Module: Mongo::Server::Connectable

Included in:
Connection, Monitor::Connection
Defined in:
lib/mongo/server/connectable.rb

Overview

This provides common behaviour for connection objects.

Since:

  • 2.0.0

Constant Summary collapse

SSL =

The ssl option prefix.

Since:

  • 2.1.0

'ssl'.freeze
TIMEOUT =

The default time in seconds to timeout an operation executed on a socket.

Since:

  • 2.0.0

5.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#addressMongo::Address (readonly)

Returns address The address to connect to.

Returns:

Since:

  • 2.0.0



34
35
36
# File 'lib/mongo/server/connectable.rb', line 34

def address
  @address
end

#optionsHash (readonly)

Returns options The passed in options.

Returns:

  • (Hash)

    options The passed in options.

Since:

  • 2.0.0



37
38
39
# File 'lib/mongo/server/connectable.rb', line 37

def options
  @options
end

#pidInteger (readonly)

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



40
41
42
# File 'lib/mongo/server/connectable.rb', line 40

def pid
  @pid
end

Instance Method Details

#connectable?true, false

Determine if the server is connectable. This will check not only if the connection exists, but if messages can send to it successfully.

Examples:

Is the server connectable?

connection.connectable?

Returns:

  • (true, false)

    If the connection is connectable.

Since:

  • 2.1.0



51
52
53
# File 'lib/mongo/server/connectable.rb', line 51

def connectable?
  begin; ping; rescue; false; end
end

#connected?true, false

Deprecated.

Use #connectable? instead

Determine if the connection is currently connected.

Examples:

Is the connection connected?

connection.connected?

Returns:

  • (true, false)

    If connected.

Since:

  • 2.0.0



63
64
65
# File 'lib/mongo/server/connectable.rb', line 63

def connected?
  !!@socket && @socket.alive?
end

#timeoutFloat

Get the timeout to execute an operation on a socket.

Examples:

Get the timeout to execute an operation on a socket.

connection.timeout

Returns:

  • (Float)

    The operation timeout in seconds.

Since:

  • 2.0.0



75
76
77
# File 'lib/mongo/server/connectable.rb', line 75

def timeout
  @timeout ||= options[:socket_timeout] || TIMEOUT
end