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>
addressMap
protected java.util.Map<java.net.InetSocketAddress,AuthInfo>
authInfoMap
protected BufferAllocator
bufferAllocator
protected CommandFactory
commandFactory
protected Configuration
configuration
protected int
connectionPoolSize
protected long
connectTimeout
protected boolean
enableHealSession
protected boolean
failureMode
protected long
healSessionInterval
protected KeyProvider
keyProvider
private static org.slf4j.Logger
log
protected int
maxQueuedNoReplyOperations
protected java.lang.String
name
protected long
opTimeout
protected boolean
resolveInetAddresses
protected boolean
sanitizeKeys
protected MemcachedSessionComparator
sessionComparator
protected MemcachedSessionLocator
sessionLocator
protected java.util.Map<SocketOption,java.lang.Object>
socketOptions
protected java.util.List<MemcachedClientStateListener>
stateListeners
protected Transcoder
transcoder
protected 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 void
addAuthInfo(java.net.InetSocketAddress address, AuthInfo authInfo)
Add auth info for memcached servervoid
addStateListener(MemcachedClientStateListener stateListener)
Add a state listenerMemcachedClient
build()
Build MemcachedClient by current options.protected void
configureClient(XMemcachedClient memcachedClient)
void
doNotResolveInetAddresses()
java.util.Map<java.net.InetSocketAddress,AuthInfo>
getAuthInfoMap()
return current all auth infoBufferAllocator
getBufferAllocator()
CommandFactory
getCommandFactory()
get xmemcached's command factoryConfiguration
getConfiguration()
Return the default networking's configuration,you can change them.long
getConnectTimeout()
Returns connect timeout in millisecondsstatic Configuration
getDefaultConfiguration()
static java.util.Map<SocketOption,java.lang.Object>
getDefaultSocketOptions()
long
getHealSessionInterval()
int
getMaxQueuedNoReplyOperations()
java.lang.String
getName()
Return the cache instance namelong
getOpTimeout()
Returns the default operation timeout in milliseconds.MemcachedSessionComparator
getSessionComparator()
MemcachedSessionLocator
getSessionLocator()
java.util.Map<SocketOption,java.lang.Object>
getSocketOptions()
Get all tcp socket optionsTranscoder
getTranscoder()
Set xmemcached's transcoder,it is used for seriailizingboolean
isEnableHealSession()
boolean
isFailureMode()
Returns if client is in failure mode.boolean
isResolveInetAddresses()
void
removeAuthInfo(java.net.InetSocketAddress address)
Remove auth info for memcached servervoid
removeStateListener(MemcachedClientStateListener stateListener)
Remove a state listenervoid
setAuthInfoMap(java.util.Map<java.net.InetSocketAddress,AuthInfo> authInfoMap)
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 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.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
setName(java.lang.String name)
Set cache instance namevoid
setOpTimeout(long opTimeout)
Set default operation timeout.void
setResolveInetAddresses(boolean resolveInetAddresses)
void
setSanitizeKeys(boolean sanitizeKeys)
Enables/disables sanitizing keys by URLEncoding.void
setSelectorPoolSize(int selectorPoolSize)
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, java.lang.Object value)
Set tcp socket optionvoid
setStateListeners(java.util.List<MemcachedClientStateListener> stateListeners)
Set state listeners,replace current listvoid
setTranscoder(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:MemcachedClientBuilder
Returns the default operation timeout in milliseconds.- Specified by:
getOpTimeout
in interfaceMemcachedClientBuilder
- Returns:
-
setOpTimeout
public void setOpTimeout(long opTimeout)
Description copied from interface:MemcachedClientBuilder
Set default operation timeout.- Specified by:
setOpTimeout
in 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:MemcachedClientBuilder
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.- Specified by:
setHealSessionInterval
in interfaceMemcachedClientBuilder
- Parameters:
healSessionInterval
- MILLISECONDS
-
isEnableHealSession
public boolean isEnableHealSession()
-
setEnableHealSession
public void setEnableHealSession(boolean enableHealSession)
Description copied from interface:MemcachedClientBuilder
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.- Specified by:
setEnableHealSession
in interfaceMemcachedClientBuilder
-
setMaxQueuedNoReplyOperations
public void setMaxQueuedNoReplyOperations(int maxQueuedNoReplyOperations)
Set max queued noreply operations number- Specified by:
setMaxQueuedNoReplyOperations
in interfaceMemcachedClientBuilder
- Parameters:
maxQueuedNoReplyOperations
-- Since:
- 1.3.8
- See Also:
MemcachedClient.DEFAULT_MAX_QUEUED_NOPS
-
setSanitizeKeys
public void setSanitizeKeys(boolean sanitizeKeys)
Description copied from interface:MemcachedClientBuilder
Enables/disables sanitizing keys by URLEncoding.- Specified by:
setSanitizeKeys
in interfaceMemcachedClientBuilder
-
addStateListener
public void addStateListener(MemcachedClientStateListener stateListener)
Description copied from interface:MemcachedClientBuilder
Add a state listener- Specified by:
addStateListener
in interfaceMemcachedClientBuilder
-
setSocketOption
public void setSocketOption(SocketOption socketOption, java.lang.Object value)
Description copied from interface:MemcachedClientBuilder
Set tcp socket option- Specified by:
setSocketOption
in interfaceMemcachedClientBuilder
-
getSocketOptions
public java.util.Map<SocketOption,java.lang.Object> getSocketOptions()
Description copied from interface:MemcachedClientBuilder
Get all tcp socket options- Specified by:
getSocketOptions
in interfaceMemcachedClientBuilder
- Returns:
-
setConnectionPoolSize
public final void setConnectionPoolSize(int poolSize)
Description copied from interface:MemcachedClientBuilder
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.- Specified by:
setConnectionPoolSize
in interfaceMemcachedClientBuilder
- Parameters:
poolSize
- pool size,default is 1
-
removeStateListener
public void removeStateListener(MemcachedClientStateListener stateListener)
Description copied from interface:MemcachedClientBuilder
Remove a state listener- Specified by:
removeStateListener
in interfaceMemcachedClientBuilder
-
getConnectTimeout
public long getConnectTimeout()
Description copied from interface:MemcachedClientBuilder
Returns connect timeout in milliseconds- Specified by:
getConnectTimeout
in interfaceMemcachedClientBuilder
- Returns:
- connect timeout
-
setConnectTimeout
public void setConnectTimeout(long connectTimeout)
Description copied from interface:MemcachedClientBuilder
Set connect timeout in milliseconds- Specified by:
setConnectTimeout
in interfaceMemcachedClientBuilder
- See Also:
MemcachedClient.DEFAULT_CONNECT_TIMEOUT
-
setStateListeners
public void setStateListeners(java.util.List<MemcachedClientStateListener> stateListeners)
Description copied from interface:MemcachedClientBuilder
Set state listeners,replace current list- Specified by:
setStateListeners
in 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:MemcachedClientBuilder
Returns if client is in failure mode.- Specified by:
isFailureMode
in interfaceMemcachedClientBuilder
- Returns:
-
setFailureMode
public void setFailureMode(boolean failureMode)
Description copied from interface:MemcachedClientBuilder
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.- Specified by:
setFailureMode
in interfaceMemcachedClientBuilder
- Parameters:
failureMode
- true is to configure client in failure mode.
-
getCommandFactory
public final CommandFactory getCommandFactory()
Description copied from interface:MemcachedClientBuilder
get xmemcached's command factory- Specified by:
getCommandFactory
in interfaceMemcachedClientBuilder
- Returns:
-
setCommandFactory
public final void setCommandFactory(CommandFactory commandFactory)
Description copied from interface:MemcachedClientBuilder
set xmemcached's command factory.Default is TextCommandFactory,which implements memcached text protocol.- Specified by:
setCommandFactory
in interfaceMemcachedClientBuilder
-
getSessionLocator
public MemcachedSessionLocator getSessionLocator()
- Specified by:
getSessionLocator
in interfaceMemcachedClientBuilder
- Returns:
- net.rubyeye.xmemcached.MemcachedSessionLocator
-
setSessionLocator
public void setSessionLocator(MemcachedSessionLocator sessionLocator)
Description copied from interface:MemcachedClientBuilder
Set the XmemcachedClient's session locator.Use ArrayMemcachedSessionLocator by default.If you want to choose consistent hash strategy,set it to KetamaMemcachedSessionLocator- Specified by:
setSessionLocator
in interfaceMemcachedClientBuilder
-
getSessionComparator
public MemcachedSessionComparator getSessionComparator()
- Specified by:
getSessionComparator
in interfaceMemcachedClientBuilder
- Returns:
- net.rubyeye.xmemcached.MemcachedSessionComparator
-
setSessionComparator
public void setSessionComparator(MemcachedSessionComparator sessionComparator)
Description copied from interface:MemcachedClientBuilder
Set the XmemcachedClient's session comparator.Use IndexMemcachedSessionComparator by default.- Specified by:
setSessionComparator
in interfaceMemcachedClientBuilder
-
getBufferAllocator
public BufferAllocator getBufferAllocator()
- Specified by:
getBufferAllocator
in interfaceMemcachedClientBuilder
-
setBufferAllocator
public void setBufferAllocator(BufferAllocator bufferAllocator)
Description copied from interface:MemcachedClientBuilder
Set nio ByteBuffer's allocator.Use SimpleBufferAllocator by default.You can choose CachedBufferAllocator.- Specified by:
setBufferAllocator
in interfaceMemcachedClientBuilder
-
getConfiguration
public Configuration getConfiguration()
Description copied from interface:MemcachedClientBuilder
Return the default networking's configuration,you can change them.- Specified by:
getConfiguration
in interfaceMemcachedClientBuilder
- Returns:
-
setConfiguration
public void setConfiguration(Configuration configuration)
Description copied from interface:MemcachedClientBuilder
Set the XmemcachedClient's networking configuration(reuseAddr,receiveBufferSize,tcpDelay etc.)- Specified by:
setConfiguration
in interfaceMemcachedClientBuilder
-
build
public MemcachedClient build() throws java.io.IOException
Description copied from interface:MemcachedClientBuilder
Build MemcachedClient by current options.- Specified by:
build
in interfaceMemcachedClientBuilder
- Returns:
- Throws:
java.io.IOException
-
configureClient
protected void configureClient(XMemcachedClient memcachedClient)
-
getTranscoder
public Transcoder getTranscoder()
Description copied from interface:MemcachedClientBuilder
Set xmemcached's transcoder,it is used for seriailizing- Specified by:
getTranscoder
in interfaceMemcachedClientBuilder
- Returns:
-
setTranscoder
public void setTranscoder(Transcoder transcoder)
- Specified by:
setTranscoder
in interfaceMemcachedClientBuilder
-
getAuthInfoMap
public java.util.Map<java.net.InetSocketAddress,AuthInfo> getAuthInfoMap()
Description copied from interface:MemcachedClientBuilder
return current all auth info- Specified by:
getAuthInfoMap
in 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:MemcachedClientBuilder
Set a key provider for pre-processing keys before sending them to memcached.- Specified by:
setKeyProvider
in interfaceMemcachedClientBuilder
-
addAuthInfo
public void addAuthInfo(java.net.InetSocketAddress address, AuthInfo authInfo)
Description copied from interface:MemcachedClientBuilder
Add auth info for memcached server- Specified by:
addAuthInfo
in interfaceMemcachedClientBuilder
-
removeAuthInfo
public void removeAuthInfo(java.net.InetSocketAddress address)
Description copied from interface:MemcachedClientBuilder
Remove auth info for memcached server- Specified by:
removeAuthInfo
in interfaceMemcachedClientBuilder
-
setAuthInfoMap
public void setAuthInfoMap(java.util.Map<java.net.InetSocketAddress,AuthInfo> authInfoMap)
Description copied from interface:MemcachedClientBuilder
Configure auth info- Specified by:
setAuthInfoMap
in 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:MemcachedClientBuilder
Return the cache instance name- Specified by:
getName
in interfaceMemcachedClientBuilder
- Returns:
-
setName
public void setName(java.lang.String name)
Description copied from interface:MemcachedClientBuilder
Set cache instance name- Specified by:
setName
in interfaceMemcachedClientBuilder
-
setSelectorPoolSize
public void setSelectorPoolSize(int selectorPoolSize)
-
-