net.spy.memcached
Class DefaultConnectionFactory

java.lang.Object
  extended by net.spy.memcached.compat.SpyObject
      extended by net.spy.memcached.DefaultConnectionFactory
All Implemented Interfaces:
ConnectionFactory
Direct Known Subclasses:
BinaryConnectionFactory, KetamaConnectionFactory

public class DefaultConnectionFactory
extends SpyObject
implements ConnectionFactory

Default implementation of ConnectionFactory.

This implementation creates connections where the operation queue is an ArrayBlockingQueue and the read and write queues are unbounded LinkedBlockingQueues. The Redistribute FailureMode is used by default.


Field Summary
static FailureMode DEFAULT_FAILURE_MODE
          Default failure mode.
static HashAlgorithm DEFAULT_HASH
          Default hash algorithm.
static long DEFAULT_MAX_RECONNECT_DELAY
          Maximum amount of time (in seconds) to wait between reconnect attempts.
static int DEFAULT_OP_QUEUE_LEN
          Maximum length of the operation queue returned by this connection factory.
static long DEFAULT_OPERATION_TIMEOUT
          Default operation timeout in milliseconds.
static int DEFAULT_READ_BUFFER_SIZE
          The read buffer size for each server connection from this factory.
 
Constructor Summary
DefaultConnectionFactory()
          Create a DefaultConnectionFactory with the default parameters.
DefaultConnectionFactory(int qLen, int bufSize)
          Create a DefaultConnectionFactory with the given maximum operation queue length, and the given read buffer size.
DefaultConnectionFactory(int qLen, int bufSize, HashAlgorithm hash)
          Construct a DefaultConnectionFactory with the given parameters.
 
Method Summary
 MemcachedConnection createConnection(List<InetSocketAddress> addrs)
          Create a MemcachedConnection for the given SocketAddresses.
 NodeLocator createLocator(List<MemcachedNode> nodes)
          Create a NodeLocator instance for the given list of nodes.
 MemcachedNode createMemcachedNode(SocketAddress sa, SocketChannel c, int bufSize)
          Create a new memcached node.
 BlockingQueue<Operation> createOperationQueue()
          Create a BlockingQueue for operations for a connection.
 BlockingQueue<Operation> createReadOperationQueue()
          Create a BlockingQueue for the operations currently expecting to read responses from memcached.
 BlockingQueue<Operation> createWriteOperationQueue()
          Create a BlockingQueue for the operations currently expecting to write requests to memcached.
 Transcoder<Object> getDefaultTranscoder()
          Get the default transcoder to be used in connections created by this factory.
 FailureMode getFailureMode()
          Get the default failure mode for the underlying connection.
 HashAlgorithm getHashAlg()
          Get the hash algorithm to be used.
 Collection<ConnectionObserver> getInitialObservers()
          Observers that should be established at the time of connection instantiation.
 long getMaxReconnectDelay()
          Maximum number of milliseconds to wait between reconnect attempts.
 OperationFactory getOperationFactory()
          Get the operation factory for connections built by this connection factory.
 long getOperationTimeout()
          Get the operation timeout used by this connection.
 int getOpQueueLen()
          Get the op queue length set at construct time.
 int getReadBufSize()
           
 boolean isDaemon()
          If true, the IO thread should be a daemon thread.
 boolean shouldOptimize()
          If true, low-level optimization is in effect.
 boolean useNagleAlgorithm()
          If true, the nagle algorithm will be used on connected sockets.
 
Methods inherited from class net.spy.memcached.compat.SpyObject
getLogger
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_FAILURE_MODE

public static final FailureMode DEFAULT_FAILURE_MODE
Default failure mode.


DEFAULT_HASH

public static final HashAlgorithm DEFAULT_HASH
Default hash algorithm.


DEFAULT_OP_QUEUE_LEN

public static final int DEFAULT_OP_QUEUE_LEN
Maximum length of the operation queue returned by this connection factory.

See Also:
Constant Field Values

DEFAULT_READ_BUFFER_SIZE

public static final int DEFAULT_READ_BUFFER_SIZE
The read buffer size for each server connection from this factory.

See Also:
Constant Field Values

DEFAULT_OPERATION_TIMEOUT

public static final long DEFAULT_OPERATION_TIMEOUT
Default operation timeout in milliseconds.

See Also:
Constant Field Values

DEFAULT_MAX_RECONNECT_DELAY

public static final long DEFAULT_MAX_RECONNECT_DELAY
Maximum amount of time (in seconds) to wait between reconnect attempts.

See Also:
Constant Field Values
Constructor Detail

DefaultConnectionFactory

public DefaultConnectionFactory(int qLen,
                                int bufSize,
                                HashAlgorithm hash)
Construct a DefaultConnectionFactory with the given parameters.

Parameters:
qLen - the queue length.
bufSize - the buffer size
hash - the algorithm to use for hashing

DefaultConnectionFactory

public DefaultConnectionFactory(int qLen,
                                int bufSize)
Create a DefaultConnectionFactory with the given maximum operation queue length, and the given read buffer size.


DefaultConnectionFactory

public DefaultConnectionFactory()
Create a DefaultConnectionFactory with the default parameters.

Method Detail

createMemcachedNode

public MemcachedNode createMemcachedNode(SocketAddress sa,
                                         SocketChannel c,
                                         int bufSize)
Description copied from interface: ConnectionFactory
Create a new memcached node.

Specified by:
createMemcachedNode in interface ConnectionFactory

createConnection

public MemcachedConnection createConnection(List<InetSocketAddress> addrs)
                                     throws IOException
Description copied from interface: ConnectionFactory
Create a MemcachedConnection for the given SocketAddresses.

Specified by:
createConnection in interface ConnectionFactory
Parameters:
addrs - the addresses of the memcached servers
Returns:
a new MemcachedConnection connected to those addresses
Throws:
IOException - for problems initializing the memcached connections

getFailureMode

public FailureMode getFailureMode()
Description copied from interface: ConnectionFactory
Get the default failure mode for the underlying connection.

Specified by:
getFailureMode in interface ConnectionFactory

createOperationQueue

public BlockingQueue<Operation> createOperationQueue()
Description copied from interface: ConnectionFactory
Create a BlockingQueue for operations for a connection.

Specified by:
createOperationQueue in interface ConnectionFactory

createReadOperationQueue

public BlockingQueue<Operation> createReadOperationQueue()
Description copied from interface: ConnectionFactory
Create a BlockingQueue for the operations currently expecting to read responses from memcached.

Specified by:
createReadOperationQueue in interface ConnectionFactory

createWriteOperationQueue

public BlockingQueue<Operation> createWriteOperationQueue()
Description copied from interface: ConnectionFactory
Create a BlockingQueue for the operations currently expecting to write requests to memcached.

Specified by:
createWriteOperationQueue in interface ConnectionFactory

createLocator

public NodeLocator createLocator(List<MemcachedNode> nodes)
Description copied from interface: ConnectionFactory
Create a NodeLocator instance for the given list of nodes.

Specified by:
createLocator in interface ConnectionFactory

getOpQueueLen

public int getOpQueueLen()
Get the op queue length set at construct time.


getReadBufSize

public int getReadBufSize()
Specified by:
getReadBufSize in interface ConnectionFactory

getHashAlg

public HashAlgorithm getHashAlg()
Description copied from interface: ConnectionFactory
Get the hash algorithm to be used.

Specified by:
getHashAlg in interface ConnectionFactory

getOperationFactory

public OperationFactory getOperationFactory()
Description copied from interface: ConnectionFactory
Get the operation factory for connections built by this connection factory.

Specified by:
getOperationFactory in interface ConnectionFactory

getOperationTimeout

public long getOperationTimeout()
Description copied from interface: ConnectionFactory
Get the operation timeout used by this connection.

Specified by:
getOperationTimeout in interface ConnectionFactory

isDaemon

public boolean isDaemon()
Description copied from interface: ConnectionFactory
If true, the IO thread should be a daemon thread.

Specified by:
isDaemon in interface ConnectionFactory

getInitialObservers

public Collection<ConnectionObserver> getInitialObservers()
Description copied from interface: ConnectionFactory
Observers that should be established at the time of connection instantiation. These observers will see the first connection established.

Specified by:
getInitialObservers in interface ConnectionFactory

getDefaultTranscoder

public Transcoder<Object> getDefaultTranscoder()
Description copied from interface: ConnectionFactory
Get the default transcoder to be used in connections created by this factory.

Specified by:
getDefaultTranscoder in interface ConnectionFactory

useNagleAlgorithm

public boolean useNagleAlgorithm()
Description copied from interface: ConnectionFactory
If true, the nagle algorithm will be used on connected sockets.

See Socket.setTcpNoDelay(boolean) for more information.

Specified by:
useNagleAlgorithm in interface ConnectionFactory

shouldOptimize

public boolean shouldOptimize()
Description copied from interface: ConnectionFactory
If true, low-level optimization is in effect.

Specified by:
shouldOptimize in interface ConnectionFactory

getMaxReconnectDelay

public long getMaxReconnectDelay()
Description copied from interface: ConnectionFactory
Maximum number of milliseconds to wait between reconnect attempts.

Specified by:
getMaxReconnectDelay in interface ConnectionFactory