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 longThe time to wait for the authentication to complete when a operation is written in milliseconds.static final ClientModeDefault client mode.static final FailureModeDefault failure mode.static final HashAlgorithmDefault hash algorithm.static final longMaximum amount of time (in seconds) to wait between reconnect attempts.static final intMaximum number + 2 of timeout exception for shutdown connection.static final MetricTypeTurn off metric collection by default.static final intMaximum length of the operation queue returned by this connection factory.static final longThe maximum time to block waiting for op queue operations to complete, in milliseconds.static final longDefault operation timeout in milliseconds.static final intThe read buffer size for each server connection from this factory.protected final int -
Constructor Summary
ConstructorsConstructorDescriptionDefaultConnectionFactory(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.DefaultConnectionFactory(ClientMode clientMode) Create a DefaultConnectionFactory with the default parameters.DefaultConnectionFactory(ClientMode clientMode, int qLen, int bufSize) Create a DefaultConnectionFactory with the given maximum operation queue length, and the given read buffer size.DefaultConnectionFactory(ClientMode clientMode, 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.longThe time to wait until authentication completes when an operation is inserted.The mode in which the client is operating.Get the default transcoder to be used in connections created by this factory.longThe interval used for periodic polling of configuration.Get the default failure mode for the underlying connection.Get the hash algorithm to be used.Get hostname for hostname verification.Observers that should be established at the time of connection instantiation.booleanIf true, keep alive will be used on connected sockets.Returns the storedExecutorServicefor listeners.longMaximum number of milliseconds to wait between reconnect attempts.The currently activeMetricCollector.protected StringgetName()Get the operation factory for connections built by this connection factory.longGet the operation timeout used by this connection.intGet the op queue length set at construct time.longGet the maximum amount of time (in milliseconds) a client is willing to wait to add a new item to a queue.intGet SSLContext for TLS connections usage.intMaximum number of timeout exception for shutdown connection.booleanisDaemon()If true, the IO thread should be a daemon thread.booleanReturns true if the default providedExecutorServicehas not been overriden through the builder.voidsetClientMode(ClientMode clientMode) Set the client mode in client.booleanIf true, low-level optimization is in effect.booleanReturns whether or not hostname verification is not required for TLS connection (default to false).toString()booleanIf true, the nagle algorithm will be used on connected sockets.
-
Field Details
-
DEFAULT_CLIENT_MODE
Default client mode. -
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
-
-
Constructor Details
-
DefaultConnectionFactory
Construct a DefaultConnectionFactory with the given parameters.- Parameters:
clientMode- the client mode.qLen- the queue length.bufSize- the buffer sizehash- the algorithm to use for hashing
-
DefaultConnectionFactory
Construct a DefaultConnectionFactory with the given parameters.- Parameters:
qLen- the queue length.bufSize- the buffer sizehash- the algorithm to use for hashing
-
DefaultConnectionFactory
Create a DefaultConnectionFactory with the given maximum operation queue length, and the given read buffer size. -
DefaultConnectionFactory
public DefaultConnectionFactory(int qLen, int bufSize) Create a DefaultConnectionFactory with the given maximum operation queue length, and the given read buffer size. -
DefaultConnectionFactory
Create a DefaultConnectionFactory with the default parameters. -
DefaultConnectionFactory
public DefaultConnectionFactory()
-
-
Method Details
-
getClientMode
Description copied from interface:ConnectionFactoryThe mode in which the client is operating.- Specified by:
getClientModein interfaceConnectionFactory- Returns:
- the clientMode.
-
setClientMode
Description copied from interface:ConnectionFactorySet the client mode in client. Should only be used in the constructor when determine the client mode.- Specified by:
setClientModein interfaceConnectionFactory
-
getDynamicModePollingInterval
public long getDynamicModePollingInterval()Description copied from interface:ConnectionFactoryThe interval used for periodic polling of configuration.- Specified by:
getDynamicModePollingIntervalin interfaceConnectionFactory- Returns:
- the interval in milliseconds
-
createMemcachedNode
Description copied from interface:ConnectionFactoryCreate a new memcached node.- Specified by:
createMemcachedNodein interfaceConnectionFactory
-
createConnection
Description copied from interface:ConnectionFactoryCreate a MemcachedConnection for the given SocketAddresses.- Specified by:
createConnectionin 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:ConnectionFactoryGet the default failure mode for the underlying connection.- Specified by:
getFailureModein interfaceConnectionFactory
-
createOperationQueue
Description copied from interface:ConnectionFactoryCreate a BlockingQueue for operations for a connection.- Specified by:
createOperationQueuein interfaceConnectionFactory
-
createReadOperationQueue
Description copied from interface:ConnectionFactoryCreate a BlockingQueue for the operations currently expecting to read responses from memcached.- Specified by:
createReadOperationQueuein interfaceConnectionFactory
-
createWriteOperationQueue
Description copied from interface:ConnectionFactoryCreate a BlockingQueue for the operations currently expecting to write requests to memcached.- Specified by:
createWriteOperationQueuein interfaceConnectionFactory
-
createLocator
Description copied from interface:ConnectionFactoryCreate a NodeLocator instance for the given list of nodes.- Specified by:
createLocatorin interfaceConnectionFactory
-
getOpQueueLen
public int getOpQueueLen()Get the op queue length set at construct time. -
getOpQueueMaxBlockTime
public long getOpQueueMaxBlockTime()Description copied from interface:ConnectionFactoryGet the maximum amount of time (in milliseconds) a client is willing to wait to add a new item to a queue.- Specified by:
getOpQueueMaxBlockTimein 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:ConnectionFactoryThe time to wait until authentication completes when an operation is inserted.- Specified by:
getAuthWaitTimein interfaceConnectionFactory- Returns:
- the time to wait for the authentication to complete when a operation is written in milliseconds.
-
getListenerExecutorService
Returns the storedExecutorServicefor listeners. By default, aThreadPoolExecutoris 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:
getListenerExecutorServicein interfaceConnectionFactory- Returns:
- the stored
ExecutorService.
-
isDefaultExecutorService
public boolean isDefaultExecutorService()Description copied from interface:ConnectionFactoryReturns true if the default providedExecutorServicehas not been overriden through the builder.- Specified by:
isDefaultExecutorServicein interfaceConnectionFactory
-
getReadBufSize
public int getReadBufSize()- Specified by:
getReadBufSizein interfaceConnectionFactory
-
getHashAlg
Description copied from interface:ConnectionFactoryGet the hash algorithm to be used.- Specified by:
getHashAlgin interfaceConnectionFactory
-
getOperationFactory
Description copied from interface:ConnectionFactoryGet the operation factory for connections built by this connection factory.- Specified by:
getOperationFactoryin interfaceConnectionFactory
-
getOperationTimeout
public long getOperationTimeout()Description copied from interface:ConnectionFactoryGet the operation timeout used by this connection.- Specified by:
getOperationTimeoutin interfaceConnectionFactory
-
isDaemon
public boolean isDaemon()Description copied from interface:ConnectionFactoryIf true, the IO thread should be a daemon thread.- Specified by:
isDaemonin interfaceConnectionFactory
-
getInitialObservers
Description copied from interface:ConnectionFactoryObservers that should be established at the time of connection instantiation. These observers will see the first connection established.- Specified by:
getInitialObserversin interfaceConnectionFactory
-
getDefaultTranscoder
Description copied from interface:ConnectionFactoryGet the default transcoder to be used in connections created by this factory.- Specified by:
getDefaultTranscoderin interfaceConnectionFactory
-
useNagleAlgorithm
public boolean useNagleAlgorithm()Description copied from interface:ConnectionFactoryIf true, the nagle algorithm will be used on connected sockets.See
Socket.setTcpNoDelay(boolean)for more information.- Specified by:
useNagleAlgorithmin interfaceConnectionFactory
-
getKeepAlive
public boolean getKeepAlive()Description copied from interface:ConnectionFactoryIf true, keep alive will be used on connected sockets.See
Socket.setKeepAlive(boolean)for more information.- Specified by:
getKeepAlivein interfaceConnectionFactory
-
shouldOptimize
public boolean shouldOptimize()Description copied from interface:ConnectionFactoryIf true, low-level optimization is in effect.- Specified by:
shouldOptimizein interfaceConnectionFactory
-
getMaxReconnectDelay
public long getMaxReconnectDelay()Description copied from interface:ConnectionFactoryMaximum number of milliseconds to wait between reconnect attempts.- Specified by:
getMaxReconnectDelayin interfaceConnectionFactory
-
getAuthDescriptor
Description copied from interface:ConnectionFactoryAuthenticate connections using the given auth descriptor.- Specified by:
getAuthDescriptorin interfaceConnectionFactory- Returns:
- null if no authentication should take place
-
getTimeoutExceptionThreshold
public int getTimeoutExceptionThreshold()Description copied from interface:ConnectionFactoryMaximum number of timeout exception for shutdown connection.- Specified by:
getTimeoutExceptionThresholdin interfaceConnectionFactory
-
getSSLContext
Get SSLContext for TLS connections usage.- Specified by:
getSSLContextin interfaceConnectionFactory- Returns:
- the SSLContext for TLS connections, null for non-TLS connections.
-
getHostnameForTlsVerification
Get hostname for hostname verification.- Specified by:
getHostnameForTlsVerificationin interfaceConnectionFactory- Returns:
- hostname for TLS hostname verification, null if TLS hostname verification disabled.
-
skipTlsHostnameVerification
public boolean skipTlsHostnameVerification()Returns whether or not hostname verification is not required for TLS connection (default to false).- Specified by:
skipTlsHostnameVerificationin interfaceConnectionFactory- Returns:
- false if require hostname verification, true if not require hostname verification.
-
enableMetrics
Description copied from interface:ConnectionFactoryIf true, metric collections are enabled.- Specified by:
enableMetricsin interfaceConnectionFactory
-
getMetricCollector
Description copied from interface:ConnectionFactoryThe currently activeMetricCollector.- Specified by:
getMetricCollectorin interfaceConnectionFactory
-
getName
-
toString
-