Module: Moped::Connection::Manager

Extended by:
Manager
Included in:
Manager
Defined in:
lib/moped/connection/manager.rb

Overview

This class contains behaviour of connection pools for specific addresses.

Since:

  • 2.0.0

Constant Summary collapse

MUTEX =

Used for synchronization of pools access.

Since:

  • 2.0.0

Mutex.new
POOL_SIZE =

The default max size for the connection pool.

Since:

  • 2.0.0

5
TIMEOUT =

The default timeout for getting connections from the queue.

Since:

  • 2.0.0

0.5

Instance Method Summary collapse

Instance Method Details

#delete_pool(node) ⇒ Object

Since:

  • 2.0.0



59
60
61
62
63
# File 'lib/moped/connection/manager.rb', line 59

def delete_pool(node)
  MUTEX.synchronize do
    pools.delete(node.address.resolved)
  end
end

#pool(node) ⇒ Pool

Get a connection pool for the provided node.

Examples:

Get a connection pool for the node.

Manager.pool(node)

Parameters:

  • The (Node)

    node.

Returns:

  • (Pool)

    The connection pool for the Node.

Since:

  • 2.0.0



32
33
34
35
36
# File 'lib/moped/connection/manager.rb', line 32

def pool(node)
  MUTEX.synchronize do
    pools[node.address.resolved] ||= create_pool(node)
  end
end

#shutdown(node) ⇒ nil

Shutdown the connection pool for the provided node. In the case of unresolved IP addresses the resolved address would be nil resulting in the same pool for all nodes that did not have IP resolved.

Examples:

Shut down the connection pool.

Manager.shutdown(node)

Parameters:

  • node (Node)

    The node.

Returns:

  • (nil)

    Always nil.

Since:

  • 2.0.3



50
51
52
53
54
55
56
57
# File 'lib/moped/connection/manager.rb', line 50

def shutdown(node)
  pool = nil
  MUTEX.synchronize do
    pool = pools.delete(node.address.resolved)
  end
  pool.shutdown{ |conn| conn.disconnect } if pool
  nil
end