Package net.rubyeye.xmemcached
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 BufferAllocator
protected CommandFactory
protected Configuration
protected int
protected long
protected boolean
protected boolean
protected long
protected KeyProvider
private static final org.slf4j.Logger
protected int
protected String
protected long
protected boolean
protected boolean
protected MemcachedSessionComparator
protected MemcachedSessionLocator
protected final Map
<SocketOption, Object> protected List
<MemcachedClientStateListener> protected Transcoder
protected 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 TypeMethodDescriptionvoid
addAuthInfo
(InetSocketAddress address, AuthInfo authInfo) Add auth info for memcached servervoid
addStateListener
(MemcachedClientStateListener stateListener) Add a state listenerbuild()
Build MemcachedClient by current options.protected void
configureClient
(XMemcachedClient memcachedClient) void
return current all auth infofinal CommandFactory
get xmemcached's command factoryReturn the default networking's configuration,you can change them.long
Returns connect timeout in millisecondsstatic final Configuration
static final Map
<SocketOption, Object> long
int
getName()
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
boolean
Returns if client is in failure mode.boolean
void
removeAuthInfo
(InetSocketAddress address) Remove auth info for memcached servervoid
removeStateListener
(MemcachedClientStateListener stateListener) Remove a state listenervoid
setAuthInfoMap
(Map<InetSocketAddress, AuthInfo> authInfoMap) Configure auth infovoid
setBufferAllocator
(BufferAllocator bufferAllocator) Set nio ByteBuffer's allocator.Use SimpleBufferAllocator by default.You can choose CachedBufferAllocator.final 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.)final 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
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, Object value) Set tcp socket optionvoid
setStateListeners
(List<MemcachedClientStateListener> stateListeners) Set state listeners,replace current listvoid
setTranscoder
(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: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
- Parameters:
enableHealSession
-
-
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:
-
setSanitizeKeys
public void setSanitizeKeys(boolean sanitizeKeys) Description copied from interface:MemcachedClientBuilder
Enables/disables sanitizing keys by URLEncoding.- Specified by:
setSanitizeKeys
in interfaceMemcachedClientBuilder
-
addStateListener
Description copied from interface:MemcachedClientBuilder
Add a state listener- Specified by:
addStateListener
in interfaceMemcachedClientBuilder
- Parameters:
stateListener
-
-
setSocketOption
Description copied from interface:MemcachedClientBuilder
Set tcp socket option- Specified by:
setSocketOption
in interfaceMemcachedClientBuilder
- Parameters:
socketOption
-value
-
-
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
Description copied from interface:MemcachedClientBuilder
Remove a state listener- Specified by:
removeStateListener
in interfaceMemcachedClientBuilder
- Parameters:
stateListener
-
-
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
- Parameters:
connectTimeout
-- See Also:
-
setStateListeners
Description copied from interface:MemcachedClientBuilder
Set state listeners,replace current list- Specified by:
setStateListeners
in interfaceMemcachedClientBuilder
- Parameters:
stateListeners
-
-
getDefaultSocketOptions
-
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
Description copied from interface:MemcachedClientBuilder
get xmemcached's command factory- Specified by:
getCommandFactory
in interfaceMemcachedClientBuilder
- Returns:
-
setCommandFactory
Description copied from interface:MemcachedClientBuilder
set xmemcached's command factory.Default is TextCommandFactory,which implements memcached text protocol.- Specified by:
setCommandFactory
in interfaceMemcachedClientBuilder
- Parameters:
commandFactory
-
-
getSessionLocator
- Specified by:
getSessionLocator
in interfaceMemcachedClientBuilder
- Returns:
- net.rubyeye.xmemcached.MemcachedSessionLocator
-
setSessionLocator
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
- Parameters:
sessionLocator
-
-
getSessionComparator
- Specified by:
getSessionComparator
in interfaceMemcachedClientBuilder
- Returns:
- net.rubyeye.xmemcached.MemcachedSessionComparator
-
setSessionComparator
Description copied from interface:MemcachedClientBuilder
Set the XmemcachedClient's session comparator.Use IndexMemcachedSessionComparator by default.- Specified by:
setSessionComparator
in interfaceMemcachedClientBuilder
- Parameters:
sessionComparator
-
-
getBufferAllocator
- Specified by:
getBufferAllocator
in interfaceMemcachedClientBuilder
-
setBufferAllocator
Description copied from interface:MemcachedClientBuilder
Set nio ByteBuffer's allocator.Use SimpleBufferAllocator by default.You can choose CachedBufferAllocator.- Specified by:
setBufferAllocator
in interfaceMemcachedClientBuilder
- Parameters:
bufferAllocator
-
-
getConfiguration
Description copied from interface:MemcachedClientBuilder
Return the default networking's configuration,you can change them.- Specified by:
getConfiguration
in interfaceMemcachedClientBuilder
- Returns:
-
setConfiguration
Description copied from interface:MemcachedClientBuilder
Set the XmemcachedClient's networking configuration(reuseAddr,receiveBufferSize,tcpDelay etc.)- Specified by:
setConfiguration
in interfaceMemcachedClientBuilder
- Parameters:
configuration
-
-
build
Description copied from interface:MemcachedClientBuilder
Build MemcachedClient by current options.- Specified by:
build
in interfaceMemcachedClientBuilder
- Returns:
- Throws:
IOException
-
configureClient
-
getTranscoder
Description copied from interface:MemcachedClientBuilder
Set xmemcached's transcoder,it is used for seriailizing- Specified by:
getTranscoder
in interfaceMemcachedClientBuilder
- Returns:
-
setTranscoder
- Specified by:
setTranscoder
in interfaceMemcachedClientBuilder
-
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
Description copied from interface:MemcachedClientBuilder
Set a key provider for pre-processing keys before sending them to memcached.- Specified by:
setKeyProvider
in interfaceMemcachedClientBuilder
- Parameters:
keyProvider
-
-
addAuthInfo
Description copied from interface:MemcachedClientBuilder
Add auth info for memcached server- Specified by:
addAuthInfo
in interfaceMemcachedClientBuilder
- Parameters:
address
-authInfo
-
-
removeAuthInfo
Description copied from interface:MemcachedClientBuilder
Remove auth info for memcached server- Specified by:
removeAuthInfo
in interfaceMemcachedClientBuilder
- Parameters:
address
-
-
setAuthInfoMap
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
Description copied from interface:MemcachedClientBuilder
Return the cache instance name- Specified by:
getName
in interfaceMemcachedClientBuilder
- Returns:
-
setName
Description copied from interface:MemcachedClientBuilder
Set cache instance name- Specified by:
setName
in interfaceMemcachedClientBuilder
- Parameters:
name
-
-
setSelectorPoolSize
public void setSelectorPoolSize(int selectorPoolSize)
-