Package net.rubyeye.xmemcached
Interface MemcachedClientBuilder
-
- All Known Implementing Classes:
AWSElasticCacheClientBuilder,XMemcachedClientBuilder
public interface MemcachedClientBuilderBuilder pattern.Configure XmemcachedClient's options,then build it
-
-
Method Summary
All Methods Instance Methods Abstract 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.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 millisecondsjava.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 seriailizingbooleanisFailureMode()Returns if client is in failure mode.voidremoveAuthInfo(java.net.InetSocketAddress address)Remove auth info for memcached servervoidremoveStateListener(MemcachedClientStateListener stateListener)Remove a state listenervoidsetAuthInfoMap(java.util.Map<java.net.InetSocketAddress,AuthInfo> map)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 healConnectionInterval)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.voidsetSanitizeKeys(boolean sanitizeKeys)Enables/disables sanitizing keys by URLEncoding.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)
-
-
-
Method Detail
-
getSessionLocator
MemcachedSessionLocator getSessionLocator()
- Returns:
- net.rubyeye.xmemcached.MemcachedSessionLocator
-
setSessionLocator
void setSessionLocator(MemcachedSessionLocator sessionLocator)
Set the XmemcachedClient's session locator.Use ArrayMemcachedSessionLocator by default.If you want to choose consistent hash strategy,set it to KetamaMemcachedSessionLocator- Parameters:
sessionLocator-
-
getSessionComparator
MemcachedSessionComparator getSessionComparator()
- Returns:
- net.rubyeye.xmemcached.MemcachedSessionComparator
-
setSessionComparator
void setSessionComparator(MemcachedSessionComparator sessionComparator)
Set the XmemcachedClient's session comparator.Use IndexMemcachedSessionComparator by default.- Parameters:
sessionComparator-
-
getBufferAllocator
BufferAllocator getBufferAllocator()
-
setBufferAllocator
void setBufferAllocator(BufferAllocator bufferAllocator)
Set nio ByteBuffer's allocator.Use SimpleBufferAllocator by default.You can choose CachedBufferAllocator.- Parameters:
bufferAllocator-
-
getConfiguration
Configuration getConfiguration()
Return the default networking's configuration,you can change them.- Returns:
-
setConfiguration
void setConfiguration(Configuration configuration)
Set the XmemcachedClient's networking configuration(reuseAddr,receiveBufferSize,tcpDelay etc.)- Parameters:
configuration-
-
build
MemcachedClient build() throws java.io.IOException
Build MemcachedClient by current options.- Returns:
- Throws:
java.io.IOException
-
setConnectionPoolSize
void setConnectionPoolSize(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. 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.- Parameters:
poolSize- pool size,default is 1
-
getTranscoder
Transcoder getTranscoder()
Set xmemcached's transcoder,it is used for seriailizing- Returns:
-
setTranscoder
void setTranscoder(Transcoder transcoder)
-
getCommandFactory
CommandFactory getCommandFactory()
get xmemcached's command factory- Returns:
-
addStateListener
void addStateListener(MemcachedClientStateListener stateListener)
Add a state listener- Parameters:
stateListener-
-
removeStateListener
void removeStateListener(MemcachedClientStateListener stateListener)
Remove a state listener- Parameters:
stateListener-
-
setStateListeners
void setStateListeners(java.util.List<MemcachedClientStateListener> stateListeners)
Set state listeners,replace current list- Parameters:
stateListeners-
-
setCommandFactory
void setCommandFactory(CommandFactory commandFactory)
set xmemcached's command factory.Default is TextCommandFactory,which implements memcached text protocol.- Parameters:
commandFactory-
-
setSocketOption
void setSocketOption(SocketOption socketOption, java.lang.Object value)
Set tcp socket option- Parameters:
socketOption-value-
-
getSocketOptions
java.util.Map<SocketOption,java.lang.Object> getSocketOptions()
Get all tcp socket options- Returns:
-
setAuthInfoMap
void setAuthInfoMap(java.util.Map<java.net.InetSocketAddress,AuthInfo> map)
Configure auth info- Parameters:
map- Auth info map,key is memcached server address,and value is the auth info for the key.
-
getAuthInfoMap
java.util.Map<java.net.InetSocketAddress,AuthInfo> getAuthInfoMap()
return current all auth info- Returns:
- Auth info map,key is memcached server address,and value is the auth info for the key.
-
addAuthInfo
void addAuthInfo(java.net.InetSocketAddress address, AuthInfo authInfo)Add auth info for memcached server- Parameters:
address-authInfo-
-
removeAuthInfo
void removeAuthInfo(java.net.InetSocketAddress address)
Remove auth info for memcached server- Parameters:
address-
-
getName
java.lang.String getName()
Return the cache instance name- Returns:
-
setName
void setName(java.lang.String name)
Set cache instance name- Parameters:
name-
-
setFailureMode
void setFailureMode(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. 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.- Parameters:
failureMode- true is to configure client in failure mode.
-
isFailureMode
boolean isFailureMode()
Returns if client is in failure mode.- Returns:
-
getConnectTimeout
long getConnectTimeout()
Returns connect timeout in milliseconds- Returns:
- connect timeout
-
setConnectTimeout
void setConnectTimeout(long connectTimeout)
Set connect timeout in milliseconds- Parameters:
connectTimeout-- See Also:
MemcachedClient.DEFAULT_CONNECT_TIMEOUT
-
setSanitizeKeys
void setSanitizeKeys(boolean sanitizeKeys)
Enables/disables sanitizing keys by URLEncoding.- Parameters:
sanitizeKey- if true, then URLEncode all keys
-
setKeyProvider
void setKeyProvider(KeyProvider keyProvider)
Set a key provider for pre-processing keys before sending them to memcached.- Parameters:
keyProvider-- Since:
- 1.3.8
-
setMaxQueuedNoReplyOperations
void setMaxQueuedNoReplyOperations(int maxQueuedNoReplyOperations)
Set max queued noreply operations number- Parameters:
maxQueuedNoReplyOperations-- Since:
- 1.3.8
- See Also:
MemcachedClient.DEFAULT_MAX_QUEUED_NOPS
-
setHealSessionInterval
void setHealSessionInterval(long healConnectionInterval)
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. You can change that value by this method.- Parameters:
healConnectionInterval- MILLISECONDS- Since:
- 1.3.9
-
setEnableHealSession
void setEnableHealSession(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.- Parameters:
enableHealSession-- Since:
- 1.3.9
-
setOpTimeout
void setOpTimeout(long opTimeout)
Set default operation timeout.- Parameters:
opTimeout- Operation timeout value in milliseconds.- Since:
- 1.4.1
-
getOpTimeout
long getOpTimeout()
Returns the default operation timeout in milliseconds.- Returns:
- Since:
- 1.4.1
-
-