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

SSL =

The ssl option prefix.

Since:

  • 2.1.0

'ssl'.freeze
TIMEOUT =
Deprecated.

Timeouts on Ruby sockets aren't effective so this default option is no longer used. Will be removed in driver version 3.0.

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



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

def address
  @address
end

#optionsHash (readonly)

Returns options The passed in options.

Returns:

  • (Hash)

    options The passed in options.

Since:

  • 2.0.0



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

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



44
45
46
# File 'lib/mongo/server/connectable.rb', line 44

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



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

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



67
68
69
# File 'lib/mongo/server/connectable.rb', line 67

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