Class XMemcachedClientBuilder
java.lang.Object
net.rubyeye.xmemcached.XMemcachedClientBuilder
- All Implemented Interfaces:
MemcachedClientBuilder
- Direct Known Subclasses:
AWSElasticCacheClientBuilder
Builder pattern.Configure XmemcachedClient's options,then build it
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected Map<InetSocketAddress, InetSocketAddress> protected Map<InetSocketAddress, AuthInfo> protected BufferAllocatorprotected CommandFactoryprotected Configurationprotected intprotected longprotected booleanprotected booleanprotected longprotected KeyProviderprivate static final org.slf4j.Loggerprotected intprotected Stringprotected longprotected booleanprotected booleanprotected MemcachedSessionComparatorprotected MemcachedSessionLocatorprotected final Map<SocketOption, Object> protected List<MemcachedClientStateListener> protected Transcoderprotected int[] -
Constructor Summary
ConstructorsConstructorDescriptionXMemcachedClientBuilder(String addressList) XMemcachedClientBuilder(List<InetSocketAddress> addressList) XMemcachedClientBuilder(List<InetSocketAddress> addressList, int[] weights) XMemcachedClientBuilder(Map<InetSocketAddress, InetSocketAddress> addressMap) XMemcachedClientBuilder(Map<InetSocketAddress, InetSocketAddress> addressMap, int[] weights) -
Method Summary
Modifier and TypeMethodDescriptionvoidaddAuthInfo(InetSocketAddress address, AuthInfo authInfo) Add auth info for memcached servervoidaddStateListener(MemcachedClientStateListener stateListener) Add a state listenerbuild()Build MemcachedClient by current options.protected voidconfigureClient(XMemcachedClient memcachedClient) voidreturn current all auth infofinal CommandFactoryget xmemcached's command factoryReturn the default networking's configuration,you can change them.longReturns connect timeout in millisecondsstatic final Configurationstatic final Map<SocketOption, Object> longintgetName()Return the cache instance namelongReturns the default operation timeout in milliseconds.Get all tcp socket optionsSet xmemcached's transcoder,it is used for seriailizingbooleanbooleanReturns if client is in failure mode.booleanvoidremoveAuthInfo(InetSocketAddress address) Remove auth info for memcached servervoidremoveStateListener(MemcachedClientStateListener stateListener) Remove a state listenervoidsetAuthInfoMap(Map<InetSocketAddress, AuthInfo> authInfoMap) Configure auth infovoidsetBufferAllocator(BufferAllocator bufferAllocator) Set nio ByteBuffer's allocator.Use SimpleBufferAllocator by default.You can choose CachedBufferAllocator.final 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.)final 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 numbervoidSet 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, Object value) Set tcp socket optionvoidsetStateListeners(List<MemcachedClientStateListener> stateListeners) Set state listeners,replace current listvoidsetTranscoder(Transcoder transcoder)
-
Field Details
-
log
private static final org.slf4j.Logger log -
sessionLocator
-
sessionComparator
-
bufferAllocator
-
configuration
-
addressMap
-
weights
protected int[] weights -
connectTimeout
protected long connectTimeout -
connectionPoolSize
protected int connectionPoolSize -
socketOptions
-
stateListeners
-
authInfoMap
-
name
-
failureMode
protected boolean failureMode -
sanitizeKeys
protected boolean sanitizeKeys -
keyProvider
-
maxQueuedNoReplyOperations
protected int maxQueuedNoReplyOperations -
healSessionInterval
protected long healSessionInterval -
enableHealSession
protected boolean enableHealSession -
opTimeout
protected long opTimeout -
resolveInetAddresses
protected boolean resolveInetAddresses -
commandFactory
-
transcoder
-
-
Constructor Details
-
XMemcachedClientBuilder
-
XMemcachedClientBuilder
-
XMemcachedClientBuilder
-
XMemcachedClientBuilder
-
XMemcachedClientBuilder
-
XMemcachedClientBuilder
public XMemcachedClientBuilder()
-
-
Method Details
-
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- Parameters:
enableHealSession-
-
setMaxQueuedNoReplyOperations
public void setMaxQueuedNoReplyOperations(int maxQueuedNoReplyOperations) Set max queued noreply operations number- Specified by:
setMaxQueuedNoReplyOperationsin interfaceMemcachedClientBuilder- Parameters:
maxQueuedNoReplyOperations-- Since:
- 1.3.8
- See Also:
-
setSanitizeKeys
public void setSanitizeKeys(boolean sanitizeKeys) Description copied from interface:MemcachedClientBuilderEnables/disables sanitizing keys by URLEncoding.- Specified by:
setSanitizeKeysin interfaceMemcachedClientBuilder
-
addStateListener
Description copied from interface:MemcachedClientBuilderAdd a state listener- Specified by:
addStateListenerin interfaceMemcachedClientBuilder- Parameters:
stateListener-
-
setSocketOption
Description copied from interface:MemcachedClientBuilderSet tcp socket option- Specified by:
setSocketOptionin interfaceMemcachedClientBuilder- Parameters:
socketOption-value-
-
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
Description copied from interface:MemcachedClientBuilderRemove a state listener- Specified by:
removeStateListenerin interfaceMemcachedClientBuilder- Parameters:
stateListener-
-
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- Parameters:
connectTimeout-- See Also:
-
setStateListeners
Description copied from interface:MemcachedClientBuilderSet state listeners,replace current list- Specified by:
setStateListenersin interfaceMemcachedClientBuilder- Parameters:
stateListeners-
-
getDefaultSocketOptions
-
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
Description copied from interface:MemcachedClientBuilderget xmemcached's command factory- Specified by:
getCommandFactoryin interfaceMemcachedClientBuilder- Returns:
-
setCommandFactory
Description copied from interface:MemcachedClientBuilderset xmemcached's command factory.Default is TextCommandFactory,which implements memcached text protocol.- Specified by:
setCommandFactoryin interfaceMemcachedClientBuilder- Parameters:
commandFactory-
-
getSessionLocator
- Specified by:
getSessionLocatorin interfaceMemcachedClientBuilder- Returns:
- net.rubyeye.xmemcached.MemcachedSessionLocator
-
setSessionLocator
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- Parameters:
sessionLocator-
-
getSessionComparator
- Specified by:
getSessionComparatorin interfaceMemcachedClientBuilder- Returns:
- net.rubyeye.xmemcached.MemcachedSessionComparator
-
setSessionComparator
Description copied from interface:MemcachedClientBuilderSet the XmemcachedClient's session comparator.Use IndexMemcachedSessionComparator by default.- Specified by:
setSessionComparatorin interfaceMemcachedClientBuilder- Parameters:
sessionComparator-
-
getBufferAllocator
- Specified by:
getBufferAllocatorin interfaceMemcachedClientBuilder
-
setBufferAllocator
Description copied from interface:MemcachedClientBuilderSet nio ByteBuffer's allocator.Use SimpleBufferAllocator by default.You can choose CachedBufferAllocator.- Specified by:
setBufferAllocatorin interfaceMemcachedClientBuilder- Parameters:
bufferAllocator-
-
getConfiguration
Description copied from interface:MemcachedClientBuilderReturn the default networking's configuration,you can change them.- Specified by:
getConfigurationin interfaceMemcachedClientBuilder- Returns:
-
setConfiguration
Description copied from interface:MemcachedClientBuilderSet the XmemcachedClient's networking configuration(reuseAddr,receiveBufferSize,tcpDelay etc.)- Specified by:
setConfigurationin interfaceMemcachedClientBuilder- Parameters:
configuration-
-
build
Description copied from interface:MemcachedClientBuilderBuild MemcachedClient by current options.- Specified by:
buildin interfaceMemcachedClientBuilder- Returns:
- Throws:
IOException
-
configureClient
-
getTranscoder
Description copied from interface:MemcachedClientBuilderSet xmemcached's transcoder,it is used for seriailizing- Specified by:
getTranscoderin interfaceMemcachedClientBuilder- Returns:
-
setTranscoder
- Specified by:
setTranscoderin interfaceMemcachedClientBuilder
-
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
Description copied from interface:MemcachedClientBuilderSet a key provider for pre-processing keys before sending them to memcached.- Specified by:
setKeyProviderin interfaceMemcachedClientBuilder- Parameters:
keyProvider-
-
addAuthInfo
Description copied from interface:MemcachedClientBuilderAdd auth info for memcached server- Specified by:
addAuthInfoin interfaceMemcachedClientBuilder- Parameters:
address-authInfo-
-
removeAuthInfo
Description copied from interface:MemcachedClientBuilderRemove auth info for memcached server- Specified by:
removeAuthInfoin interfaceMemcachedClientBuilder- Parameters:
address-
-
setAuthInfoMap
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
Description copied from interface:MemcachedClientBuilderReturn the cache instance name- Specified by:
getNamein interfaceMemcachedClientBuilder- Returns:
-
setName
Description copied from interface:MemcachedClientBuilderSet cache instance name- Specified by:
setNamein interfaceMemcachedClientBuilder- Parameters:
name-
-
setSelectorPoolSize
public void setSelectorPoolSize(int selectorPoolSize)
-