Package net.rubyeye.xmemcached
Interface MemcachedClientBuilder
- All Known Implementing Classes:
AWSElasticCacheClientBuilder
,XMemcachedClientBuilder
public interface MemcachedClientBuilder
Builder pattern.Configure XmemcachedClient's options,then build it
-
Method Summary
Modifier and TypeMethodDescriptionvoid
addAuthInfo
(InetSocketAddress address, AuthInfo authInfo) Add auth info for memcached servervoid
addStateListener
(MemcachedClientStateListener stateListener) Add a state listenerbuild()
Build MemcachedClient by current options.return current all auth infoget xmemcached's command factoryReturn the default networking's configuration,you can change them.long
Returns connect timeout in millisecondsgetName()
Return the cache instance namelong
Returns the default operation timeout in milliseconds.Get all tcp socket optionsSet xmemcached's transcoder,it is used for seriailizingboolean
Returns if client is in failure mode.void
removeAuthInfo
(InetSocketAddress address) Remove auth info for memcached servervoid
removeStateListener
(MemcachedClientStateListener stateListener) Remove a state listenervoid
Configure auth infovoid
setBufferAllocator
(BufferAllocator bufferAllocator) Set nio ByteBuffer's allocator.Use SimpleBufferAllocator by default.You can choose CachedBufferAllocator.void
setCommandFactory
(CommandFactory commandFactory) set xmemcached's command factory.Default is TextCommandFactory,which implements memcached text protocol.void
setConfiguration
(Configuration configuration) Set the XmemcachedClient's networking configuration(reuseAddr,receiveBufferSize,tcpDelay etc.)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.void
setConnectTimeout
(long connectTimeout) Set connect timeout in millisecondsvoid
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.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.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.void
setKeyProvider
(KeyProvider keyProvider) Set a key provider for pre-processing keys before sending them to memcached.void
setMaxQueuedNoReplyOperations
(int maxQueuedNoReplyOperations) Set max queued noreply operations numbervoid
Set cache instance namevoid
setOpTimeout
(long opTimeout) Set default operation timeout.void
setSanitizeKeys
(boolean sanitizeKeys) Enables/disables sanitizing keys by URLEncoding.void
setSessionComparator
(MemcachedSessionComparator sessionComparator) Set the XmemcachedClient's session comparator.Use IndexMemcachedSessionComparator by default.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 KetamaMemcachedSessionLocatorvoid
setSocketOption
(SocketOption socketOption, Object value) Set tcp socket optionvoid
setStateListeners
(List<MemcachedClientStateListener> stateListeners) Set state listeners,replace current listvoid
setTranscoder
(Transcoder transcoder)
-
Method Details
-
getSessionLocator
MemcachedSessionLocator getSessionLocator()- Returns:
- net.rubyeye.xmemcached.MemcachedSessionLocator
-
setSessionLocator
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
Set the XmemcachedClient's session comparator.Use IndexMemcachedSessionComparator by default.- Parameters:
sessionComparator
-
-
getBufferAllocator
BufferAllocator getBufferAllocator() -
setBufferAllocator
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
Set the XmemcachedClient's networking configuration(reuseAddr,receiveBufferSize,tcpDelay etc.)- Parameters:
configuration
-
-
build
Build MemcachedClient by current options.- Returns:
- Throws:
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
-
getCommandFactory
CommandFactory getCommandFactory()get xmemcached's command factory- Returns:
-
addStateListener
Add a state listener- Parameters:
stateListener
-
-
removeStateListener
Remove a state listener- Parameters:
stateListener
-
-
setStateListeners
Set state listeners,replace current list- Parameters:
stateListeners
-
-
setCommandFactory
set xmemcached's command factory.Default is TextCommandFactory,which implements memcached text protocol.- Parameters:
commandFactory
-
-
setSocketOption
Set tcp socket option- Parameters:
socketOption
-value
-
-
getSocketOptions
Map<SocketOption,Object> getSocketOptions()Get all tcp socket options- Returns:
-
setAuthInfoMap
Configure auth info- Parameters:
map
- Auth info map,key is memcached server address,and value is the auth info for the key.
-
getAuthInfoMap
Map<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
Add auth info for memcached server- Parameters:
address
-authInfo
-
-
removeAuthInfo
Remove auth info for memcached server- Parameters:
address
-
-
getName
String getName()Return the cache instance name- Returns:
-
setName
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:
-
setSanitizeKeys
void setSanitizeKeys(boolean sanitizeKeys) Enables/disables sanitizing keys by URLEncoding.- Parameters:
sanitizeKey
- if true, then URLEncode all keys
-
setKeyProvider
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:
-
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
-