Package net.spy.memcached
Class DefaultConnectionFactory
java.lang.Object
net.spy.memcached.compat.SpyObject
net.spy.memcached.DefaultConnectionFactory
- All Implemented Interfaces:
ConnectionFactory
- Direct Known Subclasses:
BinaryConnectionFactory
,KetamaConnectionFactory
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 always
used. If other FailureModes are needed, look at the ConnectionFactoryBuilder.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final long
The time to wait for the authentication to complete when a operation is written in milliseconds.static final FailureMode
Default failure mode.static final HashAlgorithm
Default hash algorithm.static final long
Maximum amount of time (in seconds) to wait between reconnect attempts.static final int
Maximum number + 2 of timeout exception for shutdown connection.static final MetricType
Turn off metric collection by default.static final int
Maximum length of the operation queue returned by this connection factory.static final long
The maximum time to block waiting for op queue operations to complete, in milliseconds.static final long
Default operation timeout in milliseconds.static final int
The read buffer size for each server connection from this factory.private ExecutorService
The ExecutorService in which the listener callbacks will be executed.private final HashAlgorithm
private MetricCollector
protected final int
private final int
-
Constructor Summary
ConstructorsConstructorDescriptionCreate 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
Modifier and TypeMethodDescriptioncreateConnection
(List<InetSocketAddress> addrs) Create a MemcachedConnection for the given SocketAddresses.createLocator
(List<MemcachedNode> nodes) Create a NodeLocator instance for the given list of nodes.createMemcachedNode
(SocketAddress sa, SocketChannel c, int bufSize) Create a new memcached node.Create a BlockingQueue for operations for a connection.Create a BlockingQueue for the operations currently expecting to read responses from memcached.Create a BlockingQueue for the operations currently expecting to write requests to memcached.If true, metric collections are enabled.Authenticate connections using the given auth descriptor.long
The time to wait until authentication completes when an operation is inserted.Get the default transcoder to be used in connections created by this factory.Get the default failure mode for the underlying connection.Get the hash algorithm to be used.Observers that should be established at the time of connection instantiation.Returns the storedExecutorService
for listeners.long
Maximum number of milliseconds to wait between reconnect attempts.The currently activeMetricCollector
.protected String
getName()
Get the operation factory for connections built by this connection factory.long
Get the operation timeout used by this connection.int
Get the op queue length set at construct time.long
Get the maximum amount of time (in milliseconds) a client is willing to wait to add a new item to a queue.int
int
Maximum number of timeout exception for shutdown connection.boolean
isDaemon()
If true, the IO thread should be a daemon thread.boolean
Returns true if the default providedExecutorService
has not been overriden through the builder.boolean
If true, low-level optimization is in effect.toString()
boolean
If true, the nagle algorithm will be used on connected sockets.
-
Field Details
-
DEFAULT_FAILURE_MODE
Default failure mode. -
DEFAULT_HASH
Default hash algorithm. -
DEFAULT_OP_QUEUE_LEN
public static final int DEFAULT_OP_QUEUE_LENMaximum length of the operation queue returned by this connection factory.- See Also:
-
DEFAULT_OP_QUEUE_MAX_BLOCK_TIME
public static final long DEFAULT_OP_QUEUE_MAX_BLOCK_TIMEThe maximum time to block waiting for op queue operations to complete, in milliseconds. The default has been set with the expectation that most requests are interactive and waiting for more than a few seconds is thus more undesirable than failing the request. -
DEFAULT_READ_BUFFER_SIZE
public static final int DEFAULT_READ_BUFFER_SIZEThe read buffer size for each server connection from this factory.- See Also:
-
DEFAULT_OPERATION_TIMEOUT
public static final long DEFAULT_OPERATION_TIMEOUTDefault operation timeout in milliseconds.- See Also:
-
DEFAULT_MAX_RECONNECT_DELAY
public static final long DEFAULT_MAX_RECONNECT_DELAYMaximum amount of time (in seconds) to wait between reconnect attempts.- See Also:
-
DEFAULT_MAX_TIMEOUTEXCEPTION_THRESHOLD
public static final int DEFAULT_MAX_TIMEOUTEXCEPTION_THRESHOLDMaximum number + 2 of timeout exception for shutdown connection.- See Also:
-
DEFAULT_METRIC_TYPE
Turn off metric collection by default. -
DEFAULT_AUTH_WAIT_TIME
public static final long DEFAULT_AUTH_WAIT_TIMEThe time to wait for the authentication to complete when a operation is written in milliseconds.- See Also:
-
opQueueLen
protected final int opQueueLen -
readBufSize
private final int readBufSize -
hashAlg
-
metrics
-
executorService
The ExecutorService in which the listener callbacks will be executed.
-
-
Constructor Details
-
DefaultConnectionFactory
Construct a DefaultConnectionFactory with the given parameters.- Parameters:
qLen
- the queue length.bufSize
- the buffer sizehash
- 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 Details
-
createMemcachedNode
Description copied from interface:ConnectionFactory
Create a new memcached node.- Specified by:
createMemcachedNode
in interfaceConnectionFactory
-
createConnection
Description copied from interface:ConnectionFactory
Create a MemcachedConnection for the given SocketAddresses.- Specified by:
createConnection
in interfaceConnectionFactory
- 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
Description copied from interface:ConnectionFactory
Get the default failure mode for the underlying connection.- Specified by:
getFailureMode
in interfaceConnectionFactory
-
createOperationQueue
Description copied from interface:ConnectionFactory
Create a BlockingQueue for operations for a connection.- Specified by:
createOperationQueue
in interfaceConnectionFactory
-
createReadOperationQueue
Description copied from interface:ConnectionFactory
Create a BlockingQueue for the operations currently expecting to read responses from memcached.- Specified by:
createReadOperationQueue
in interfaceConnectionFactory
-
createWriteOperationQueue
Description copied from interface:ConnectionFactory
Create a BlockingQueue for the operations currently expecting to write requests to memcached.- Specified by:
createWriteOperationQueue
in interfaceConnectionFactory
-
createLocator
Description copied from interface:ConnectionFactory
Create a NodeLocator instance for the given list of nodes.- Specified by:
createLocator
in interfaceConnectionFactory
-
getOpQueueLen
public int getOpQueueLen()Get the op queue length set at construct time. -
getOpQueueMaxBlockTime
public long getOpQueueMaxBlockTime()Description copied from interface:ConnectionFactory
Get the maximum amount of time (in milliseconds) a client is willing to wait to add a new item to a queue.- Specified by:
getOpQueueMaxBlockTime
in interfaceConnectionFactory
- Returns:
- the maximum time to block waiting for op queue operations to complete, in milliseconds, or null for no waiting.
-
getAuthWaitTime
public long getAuthWaitTime()Description copied from interface:ConnectionFactory
The time to wait until authentication completes when an operation is inserted.- Specified by:
getAuthWaitTime
in interfaceConnectionFactory
- Returns:
- the time to wait for the authentication to complete when a operation is written in milliseconds.
-
getListenerExecutorService
Returns the storedExecutorService
for listeners. By default, aThreadPoolExecutor
is used that acts exactly like a default cachedThreadPool, but defines the upper limit of Threads to be created as the number of available processors to prevent resource exhaustion.- Specified by:
getListenerExecutorService
in interfaceConnectionFactory
- Returns:
- the stored
ExecutorService
.
-
isDefaultExecutorService
public boolean isDefaultExecutorService()Description copied from interface:ConnectionFactory
Returns true if the default providedExecutorService
has not been overriden through the builder.- Specified by:
isDefaultExecutorService
in interfaceConnectionFactory
-
getReadBufSize
public int getReadBufSize()- Specified by:
getReadBufSize
in interfaceConnectionFactory
-
getHashAlg
Description copied from interface:ConnectionFactory
Get the hash algorithm to be used.- Specified by:
getHashAlg
in interfaceConnectionFactory
-
getOperationFactory
Description copied from interface:ConnectionFactory
Get the operation factory for connections built by this connection factory.- Specified by:
getOperationFactory
in interfaceConnectionFactory
-
getOperationTimeout
public long getOperationTimeout()Description copied from interface:ConnectionFactory
Get the operation timeout used by this connection.- Specified by:
getOperationTimeout
in interfaceConnectionFactory
-
isDaemon
public boolean isDaemon()Description copied from interface:ConnectionFactory
If true, the IO thread should be a daemon thread.- Specified by:
isDaemon
in interfaceConnectionFactory
-
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 interfaceConnectionFactory
-
getDefaultTranscoder
Description copied from interface:ConnectionFactory
Get the default transcoder to be used in connections created by this factory.- Specified by:
getDefaultTranscoder
in interfaceConnectionFactory
-
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 interfaceConnectionFactory
-
shouldOptimize
public boolean shouldOptimize()Description copied from interface:ConnectionFactory
If true, low-level optimization is in effect.- Specified by:
shouldOptimize
in interfaceConnectionFactory
-
getMaxReconnectDelay
public long getMaxReconnectDelay()Description copied from interface:ConnectionFactory
Maximum number of milliseconds to wait between reconnect attempts.- Specified by:
getMaxReconnectDelay
in interfaceConnectionFactory
-
getAuthDescriptor
Description copied from interface:ConnectionFactory
Authenticate connections using the given auth descriptor.- Specified by:
getAuthDescriptor
in interfaceConnectionFactory
- Returns:
- null if no authentication should take place
-
getTimeoutExceptionThreshold
public int getTimeoutExceptionThreshold()Description copied from interface:ConnectionFactory
Maximum number of timeout exception for shutdown connection.- Specified by:
getTimeoutExceptionThreshold
in interfaceConnectionFactory
-
enableMetrics
Description copied from interface:ConnectionFactory
If true, metric collections are enabled.- Specified by:
enableMetrics
in interfaceConnectionFactory
-
getMetricCollector
Description copied from interface:ConnectionFactory
The currently activeMetricCollector
.- Specified by:
getMetricCollector
in interfaceConnectionFactory
-
getName
-
toString
-