Package net.rubyeye.xmemcached
Class XMemcachedClientBuilder
- java.lang.Object
-
- net.rubyeye.xmemcached.XMemcachedClientBuilder
-
- All Implemented Interfaces:
MemcachedClientBuilder
- Direct Known Subclasses:
AWSElasticCacheClientBuilder
public class XMemcachedClientBuilder extends java.lang.Object implements MemcachedClientBuilder
Builder pattern.Configure XmemcachedClient's options,then build it
-
-
Field Summary
Fields Modifier and Type Field Description protected java.util.Map<java.net.InetSocketAddress,java.net.InetSocketAddress>addressMapprotected java.util.Map<java.net.InetSocketAddress,AuthInfo>authInfoMapprotected BufferAllocatorbufferAllocatorprotected CommandFactorycommandFactoryprotected Configurationconfigurationprotected intconnectionPoolSizeprotected longconnectTimeoutprotected booleanenableHealSessionprotected booleanfailureModeprotected longhealSessionIntervalprotected KeyProviderkeyProviderprivate static org.slf4j.Loggerlogprotected intmaxQueuedNoReplyOperationsprotected java.lang.Stringnameprotected longopTimeoutprotected booleanresolveInetAddressesprotected booleansanitizeKeysprotected MemcachedSessionComparatorsessionComparatorprotected MemcachedSessionLocatorsessionLocatorprotected java.util.Map<SocketOption,java.lang.Object>socketOptionsprotected java.util.List<MemcachedClientStateListener>stateListenersprotected Transcodertranscoderprotected int[]weights
-
Constructor Summary
Constructors Constructor Description XMemcachedClientBuilder()XMemcachedClientBuilder(java.lang.String addressList)XMemcachedClientBuilder(java.util.List<java.net.InetSocketAddress> addressList)XMemcachedClientBuilder(java.util.List<java.net.InetSocketAddress> addressList, int[] weights)XMemcachedClientBuilder(java.util.Map<java.net.InetSocketAddress,java.net.InetSocketAddress> addressMap)XMemcachedClientBuilder(java.util.Map<java.net.InetSocketAddress,java.net.InetSocketAddress> addressMap, int[] weights)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddAuthInfo(java.net.InetSocketAddress address, AuthInfo authInfo)Add auth info for memcached servervoidaddStateListener(MemcachedClientStateListener stateListener)Add a state listenerMemcachedClientbuild()Build MemcachedClient by current options.protected voidconfigureClient(XMemcachedClient memcachedClient)voiddoNotResolveInetAddresses()java.util.Map<java.net.InetSocketAddress,AuthInfo>getAuthInfoMap()return current all auth infoBufferAllocatorgetBufferAllocator()CommandFactorygetCommandFactory()get xmemcached's command factoryConfigurationgetConfiguration()Return the default networking's configuration,you can change them.longgetConnectTimeout()Returns connect timeout in millisecondsstatic ConfigurationgetDefaultConfiguration()static java.util.Map<SocketOption,java.lang.Object>getDefaultSocketOptions()longgetHealSessionInterval()intgetMaxQueuedNoReplyOperations()java.lang.StringgetName()Return the cache instance namelonggetOpTimeout()Returns the default operation timeout in milliseconds.MemcachedSessionComparatorgetSessionComparator()MemcachedSessionLocatorgetSessionLocator()java.util.Map<SocketOption,java.lang.Object>getSocketOptions()Get all tcp socket optionsTranscodergetTranscoder()Set xmemcached's transcoder,it is used for seriailizingbooleanisEnableHealSession()booleanisFailureMode()Returns if client is in failure mode.booleanisResolveInetAddresses()voidremoveAuthInfo(java.net.InetSocketAddress address)Remove auth info for memcached servervoidremoveStateListener(MemcachedClientStateListener stateListener)Remove a state listenervoidsetAuthInfoMap(java.util.Map<java.net.InetSocketAddress,AuthInfo> authInfoMap)Configure auth infovoidsetBufferAllocator(BufferAllocator bufferAllocator)Set nio ByteBuffer's allocator.Use SimpleBufferAllocator by default.You can choose CachedBufferAllocator.voidsetCommandFactory(CommandFactory commandFactory)set xmemcached's command factory.Default is TextCommandFactory,which implements memcached text protocol.voidsetConfiguration(Configuration configuration)Set the XmemcachedClient's networking configuration(reuseAddr,receiveBufferSize,tcpDelay etc.)voidsetConnectionPoolSize(int poolSize)In a high concurrent enviroment,you may want to pool memcached clients.But a xmemcached client has to start a reactor thread and some thread pools,if you create too many clients,the cost is very large.voidsetConnectTimeout(long connectTimeout)Set connect timeout in millisecondsvoidsetEnableHealSession(boolean enableHealSession)If the memcached dump or network error cause connection closed,xmemcached would try to heal the connection.You can disable this behaviour by using this method:
client.setEnableHealSession(false);
The default value is true.voidsetFailureMode(boolean failureMode)Configure wheather to set client in failure mode.If set it to true,that means you want to configure client in failure mode.voidsetHealSessionInterval(long healSessionInterval)If the memcached dump or network error cause connection closed,xmemcached would try to heal the connection.The interval between reconnections is 2 seconds by default.voidsetKeyProvider(KeyProvider keyProvider)Set a key provider for pre-processing keys before sending them to memcached.voidsetMaxQueuedNoReplyOperations(int maxQueuedNoReplyOperations)Set max queued noreply operations numbervoidsetName(java.lang.String name)Set cache instance namevoidsetOpTimeout(long opTimeout)Set default operation timeout.voidsetResolveInetAddresses(boolean resolveInetAddresses)voidsetSanitizeKeys(boolean sanitizeKeys)Enables/disables sanitizing keys by URLEncoding.voidsetSelectorPoolSize(int selectorPoolSize)voidsetSessionComparator(MemcachedSessionComparator sessionComparator)Set the XmemcachedClient's session comparator.Use IndexMemcachedSessionComparator by default.voidsetSessionLocator(MemcachedSessionLocator sessionLocator)Set the XmemcachedClient's session locator.Use ArrayMemcachedSessionLocator by default.If you want to choose consistent hash strategy,set it to KetamaMemcachedSessionLocatorvoidsetSocketOption(SocketOption socketOption, java.lang.Object value)Set tcp socket optionvoidsetStateListeners(java.util.List<MemcachedClientStateListener> stateListeners)Set state listeners,replace current listvoidsetTranscoder(Transcoder transcoder)
-
-
-
Field Detail
-
log
private static final org.slf4j.Logger log
-
sessionLocator
protected MemcachedSessionLocator sessionLocator
-
sessionComparator
protected MemcachedSessionComparator sessionComparator
-
bufferAllocator
protected BufferAllocator bufferAllocator
-
configuration
protected Configuration configuration
-
addressMap
protected java.util.Map<java.net.InetSocketAddress,java.net.InetSocketAddress> addressMap
-
weights
protected int[] weights
-
connectTimeout
protected long connectTimeout
-
connectionPoolSize
protected int connectionPoolSize
-
socketOptions
protected final java.util.Map<SocketOption,java.lang.Object> socketOptions
-
stateListeners
protected java.util.List<MemcachedClientStateListener> stateListeners
-
authInfoMap
protected java.util.Map<java.net.InetSocketAddress,AuthInfo> authInfoMap
-
name
protected java.lang.String name
-
failureMode
protected boolean failureMode
-
sanitizeKeys
protected boolean sanitizeKeys
-
keyProvider
protected KeyProvider keyProvider
-
maxQueuedNoReplyOperations
protected int maxQueuedNoReplyOperations
-
healSessionInterval
protected long healSessionInterval
-
enableHealSession
protected boolean enableHealSession
-
opTimeout
protected long opTimeout
-
resolveInetAddresses
protected boolean resolveInetAddresses
-
commandFactory
protected CommandFactory commandFactory
-
transcoder
protected Transcoder transcoder
-
-
Constructor Detail
-
XMemcachedClientBuilder
public XMemcachedClientBuilder(java.lang.String addressList)
-
XMemcachedClientBuilder
public XMemcachedClientBuilder(java.util.List<java.net.InetSocketAddress> addressList)
-
XMemcachedClientBuilder
public XMemcachedClientBuilder(java.util.List<java.net.InetSocketAddress> addressList, int[] weights)
-
XMemcachedClientBuilder
public XMemcachedClientBuilder(java.util.Map<java.net.InetSocketAddress,java.net.InetSocketAddress> addressMap)
-
XMemcachedClientBuilder
public XMemcachedClientBuilder(java.util.Map<java.net.InetSocketAddress,java.net.InetSocketAddress> addressMap, int[] weights)
-
XMemcachedClientBuilder
public XMemcachedClientBuilder()
-
-
Method Detail
-
isResolveInetAddresses
public boolean isResolveInetAddresses()
-
setResolveInetAddresses
public void setResolveInetAddresses(boolean resolveInetAddresses)
-
doNotResolveInetAddresses
public void doNotResolveInetAddresses()
-
getOpTimeout
public long getOpTimeout()
Description copied from interface:MemcachedClientBuilderReturns the default operation timeout in milliseconds.- Specified by:
getOpTimeoutin interfaceMemcachedClientBuilder- Returns:
-
setOpTimeout
public void setOpTimeout(long opTimeout)
Description copied from interface:MemcachedClientBuilderSet default operation timeout.- Specified by:
setOpTimeoutin interfaceMemcachedClientBuilder- Parameters:
opTimeout- Operation timeout value in milliseconds.
-
getMaxQueuedNoReplyOperations
public int getMaxQueuedNoReplyOperations()
-
getHealSessionInterval
public long getHealSessionInterval()
-
setHealSessionInterval
public void setHealSessionInterval(long healSessionInterval)
Description copied from interface:MemcachedClientBuilderIf the memcached dump or network error cause connection closed,xmemcached would try to heal the connection.The interval between reconnections is 2 seconds by default. You can change that value by this method.- Specified by:
setHealSessionIntervalin interfaceMemcachedClientBuilder- Parameters:
healSessionInterval- MILLISECONDS
-
isEnableHealSession
public boolean isEnableHealSession()
-
setEnableHealSession
public void setEnableHealSession(boolean enableHealSession)
Description copied from interface:MemcachedClientBuilderIf the memcached dump or network error cause connection closed,xmemcached would try to heal the connection.You can disable this behaviour by using this method:
client.setEnableHealSession(false);
The default value is true.- Specified by:
setEnableHealSessionin interfaceMemcachedClientBuilder
-
setMaxQueuedNoReplyOperations
public void setMaxQueuedNoReplyOperations(int maxQueuedNoReplyOperations)
Set max queued noreply operations number- Specified by:
setMaxQueuedNoReplyOperationsin interfaceMemcachedClientBuilder- Parameters:
maxQueuedNoReplyOperations-- Since:
- 1.3.8
- See Also:
MemcachedClient.DEFAULT_MAX_QUEUED_NOPS
-
setSanitizeKeys
public void setSanitizeKeys(boolean sanitizeKeys)
Description copied from interface:MemcachedClientBuilderEnables/disables sanitizing keys by URLEncoding.- Specified by:
setSanitizeKeysin interfaceMemcachedClientBuilder
-
addStateListener
public void addStateListener(MemcachedClientStateListener stateListener)
Description copied from interface:MemcachedClientBuilderAdd a state listener- Specified by:
addStateListenerin interfaceMemcachedClientBuilder
-
setSocketOption
public void setSocketOption(SocketOption socketOption, java.lang.Object value)
Description copied from interface:MemcachedClientBuilderSet tcp socket option- Specified by:
setSocketOptionin interfaceMemcachedClientBuilder
-
getSocketOptions
public java.util.Map<SocketOption,java.lang.Object> getSocketOptions()
Description copied from interface:MemcachedClientBuilderGet all tcp socket options- Specified by:
getSocketOptionsin interfaceMemcachedClientBuilder- Returns:
-
setConnectionPoolSize
public final void setConnectionPoolSize(int poolSize)
Description copied from interface:MemcachedClientBuilderIn a high concurrent enviroment,you may want to pool memcached clients.But a xmemcached client has to start a reactor thread and some thread pools,if you create too many clients,the cost is very large. Xmemcached supports connection pool instead of client pool.you can create more connections to one or more memcached servers,and these connections share the same reactor and thread pools,it will reduce the cost of system.- Specified by:
setConnectionPoolSizein interfaceMemcachedClientBuilder- Parameters:
poolSize- pool size,default is 1
-
removeStateListener
public void removeStateListener(MemcachedClientStateListener stateListener)
Description copied from interface:MemcachedClientBuilderRemove a state listener- Specified by:
removeStateListenerin interfaceMemcachedClientBuilder
-
getConnectTimeout
public long getConnectTimeout()
Description copied from interface:MemcachedClientBuilderReturns connect timeout in milliseconds- Specified by:
getConnectTimeoutin interfaceMemcachedClientBuilder- Returns:
- connect timeout
-
setConnectTimeout
public void setConnectTimeout(long connectTimeout)
Description copied from interface:MemcachedClientBuilderSet connect timeout in milliseconds- Specified by:
setConnectTimeoutin interfaceMemcachedClientBuilder- See Also:
MemcachedClient.DEFAULT_CONNECT_TIMEOUT
-
setStateListeners
public void setStateListeners(java.util.List<MemcachedClientStateListener> stateListeners)
Description copied from interface:MemcachedClientBuilderSet state listeners,replace current list- Specified by:
setStateListenersin interfaceMemcachedClientBuilder
-
getDefaultSocketOptions
public static final java.util.Map<SocketOption,java.lang.Object> getDefaultSocketOptions()
-
getDefaultConfiguration
public static final Configuration getDefaultConfiguration()
-
isFailureMode
public boolean isFailureMode()
Description copied from interface:MemcachedClientBuilderReturns if client is in failure mode.- Specified by:
isFailureModein interfaceMemcachedClientBuilder- Returns:
-
setFailureMode
public void setFailureMode(boolean failureMode)
Description copied from interface:MemcachedClientBuilderConfigure wheather to set client in failure mode.If set it to true,that means you want to configure client in failure mode. Failure mode is that when a memcached server is down,it would not taken from the server list but marked as unavailable,and then further requests to this server will be transformed to standby node if configured or throw an exception until it comes back up.- Specified by:
setFailureModein interfaceMemcachedClientBuilder- Parameters:
failureMode- true is to configure client in failure mode.
-
getCommandFactory
public final CommandFactory getCommandFactory()
Description copied from interface:MemcachedClientBuilderget xmemcached's command factory- Specified by:
getCommandFactoryin interfaceMemcachedClientBuilder- Returns:
-
setCommandFactory
public final void setCommandFactory(CommandFactory commandFactory)
Description copied from interface:MemcachedClientBuilderset xmemcached's command factory.Default is TextCommandFactory,which implements memcached text protocol.- Specified by:
setCommandFactoryin interfaceMemcachedClientBuilder
-
getSessionLocator
public MemcachedSessionLocator getSessionLocator()
- Specified by:
getSessionLocatorin interfaceMemcachedClientBuilder- Returns:
- net.rubyeye.xmemcached.MemcachedSessionLocator
-
setSessionLocator
public void setSessionLocator(MemcachedSessionLocator sessionLocator)
Description copied from interface:MemcachedClientBuilderSet the XmemcachedClient's session locator.Use ArrayMemcachedSessionLocator by default.If you want to choose consistent hash strategy,set it to KetamaMemcachedSessionLocator- Specified by:
setSessionLocatorin interfaceMemcachedClientBuilder
-
getSessionComparator
public MemcachedSessionComparator getSessionComparator()
- Specified by:
getSessionComparatorin interfaceMemcachedClientBuilder- Returns:
- net.rubyeye.xmemcached.MemcachedSessionComparator
-
setSessionComparator
public void setSessionComparator(MemcachedSessionComparator sessionComparator)
Description copied from interface:MemcachedClientBuilderSet the XmemcachedClient's session comparator.Use IndexMemcachedSessionComparator by default.- Specified by:
setSessionComparatorin interfaceMemcachedClientBuilder
-
getBufferAllocator
public BufferAllocator getBufferAllocator()
- Specified by:
getBufferAllocatorin interfaceMemcachedClientBuilder
-
setBufferAllocator
public void setBufferAllocator(BufferAllocator bufferAllocator)
Description copied from interface:MemcachedClientBuilderSet nio ByteBuffer's allocator.Use SimpleBufferAllocator by default.You can choose CachedBufferAllocator.- Specified by:
setBufferAllocatorin interfaceMemcachedClientBuilder
-
getConfiguration
public Configuration getConfiguration()
Description copied from interface:MemcachedClientBuilderReturn the default networking's configuration,you can change them.- Specified by:
getConfigurationin interfaceMemcachedClientBuilder- Returns:
-
setConfiguration
public void setConfiguration(Configuration configuration)
Description copied from interface:MemcachedClientBuilderSet the XmemcachedClient's networking configuration(reuseAddr,receiveBufferSize,tcpDelay etc.)- Specified by:
setConfigurationin interfaceMemcachedClientBuilder
-
build
public MemcachedClient build() throws java.io.IOException
Description copied from interface:MemcachedClientBuilderBuild MemcachedClient by current options.- Specified by:
buildin interfaceMemcachedClientBuilder- Returns:
- Throws:
java.io.IOException
-
configureClient
protected void configureClient(XMemcachedClient memcachedClient)
-
getTranscoder
public Transcoder getTranscoder()
Description copied from interface:MemcachedClientBuilderSet xmemcached's transcoder,it is used for seriailizing- Specified by:
getTranscoderin interfaceMemcachedClientBuilder- Returns:
-
setTranscoder
public void setTranscoder(Transcoder transcoder)
- Specified by:
setTranscoderin interfaceMemcachedClientBuilder
-
getAuthInfoMap
public java.util.Map<java.net.InetSocketAddress,AuthInfo> getAuthInfoMap()
Description copied from interface:MemcachedClientBuilderreturn current all auth info- Specified by:
getAuthInfoMapin interfaceMemcachedClientBuilder- Returns:
- Auth info map,key is memcached server address,and value is the auth info for the key.
-
setKeyProvider
public void setKeyProvider(KeyProvider keyProvider)
Description copied from interface:MemcachedClientBuilderSet a key provider for pre-processing keys before sending them to memcached.- Specified by:
setKeyProviderin interfaceMemcachedClientBuilder
-
addAuthInfo
public void addAuthInfo(java.net.InetSocketAddress address, AuthInfo authInfo)Description copied from interface:MemcachedClientBuilderAdd auth info for memcached server- Specified by:
addAuthInfoin interfaceMemcachedClientBuilder
-
removeAuthInfo
public void removeAuthInfo(java.net.InetSocketAddress address)
Description copied from interface:MemcachedClientBuilderRemove auth info for memcached server- Specified by:
removeAuthInfoin interfaceMemcachedClientBuilder
-
setAuthInfoMap
public void setAuthInfoMap(java.util.Map<java.net.InetSocketAddress,AuthInfo> authInfoMap)
Description copied from interface:MemcachedClientBuilderConfigure auth info- Specified by:
setAuthInfoMapin interfaceMemcachedClientBuilder- Parameters:
authInfoMap- Auth info map,key is memcached server address,and value is the auth info for the key.
-
getName
public java.lang.String getName()
Description copied from interface:MemcachedClientBuilderReturn the cache instance name- Specified by:
getNamein interfaceMemcachedClientBuilder- Returns:
-
setName
public void setName(java.lang.String name)
Description copied from interface:MemcachedClientBuilderSet cache instance name- Specified by:
setNamein interfaceMemcachedClientBuilder
-
setSelectorPoolSize
public void setSelectorPoolSize(int selectorPoolSize)
-
-