Package net.rubyeye.xmemcached.impl
Class KetamaMemcachedSessionLocator
- java.lang.Object
-
- net.rubyeye.xmemcached.impl.AbstractMemcachedSessionLocator
-
- net.rubyeye.xmemcached.impl.KetamaMemcachedSessionLocator
-
- All Implemented Interfaces:
MemcachedSessionLocator
public class KetamaMemcachedSessionLocator extends AbstractMemcachedSessionLocator
Consistent Hash Algorithm implementation,based on TreeMap.tailMap(hash) method.
-
-
Field Summary
Fields Modifier and Type Field Description private booleancwNginxUpstreamConsistent(package private) static intDEFAULT_PORTcompatible with nginx-upstream-consistent,patched by wolfg1969private booleangwhalinMemcachedJavaClientCompatibiltyConsistentprivate HashAlgorithmhashAlgprivate java.util.TreeMap<java.lang.Long,java.util.List<Session>>ketamaSessionsprivate intmaxTries(package private) static intNUM_REPS-
Fields inherited from class net.rubyeye.xmemcached.impl.AbstractMemcachedSessionLocator
failureMode
-
-
Constructor Summary
Constructors Constructor Description KetamaMemcachedSessionLocator()Create a KetamaMemcachedSessionLocator with default config.KetamaMemcachedSessionLocator(boolean cwNginxUpstreamConsistent)Create a KetamaMemcachedSessionLocatorKetamaMemcachedSessionLocator(java.util.List<Session> list, HashAlgorithm alg)KetamaMemcachedSessionLocator(HashAlgorithm alg)Create a KetamaMemcachedSessionLocator with a special hash algorithm.KetamaMemcachedSessionLocator(HashAlgorithm alg, boolean cwNginxUpstreamConsistent)KetamaMemcachedSessionLocator(HashAlgorithm alg, boolean cwNginxUpstreamConsistent, boolean gwhalinMemcachedJavaClientCompatibiltyConsistent)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private voidbuildMap(java.util.Collection<Session> list, HashAlgorithm alg)SessiongetSessionByHash(long hash)SessiongetSessionByKey(java.lang.String key)Returns a session by special key.private java.util.List<Session>getSessionList(java.util.TreeMap<java.lang.Long,java.util.List<Session>> sessionMap, long k)private java.lang.StringgetSockStr(Session session)longnextHash(long hashVal, java.lang.String key, int tries)voidupdateSessions(java.util.Collection<Session> list)Update sessions when session was added or removed.-
Methods inherited from class net.rubyeye.xmemcached.impl.AbstractMemcachedSessionLocator
setFailureMode
-
-
-
-
Field Detail
-
NUM_REPS
static final int NUM_REPS
- See Also:
- Constant Field Values
-
ketamaSessions
private transient volatile java.util.TreeMap<java.lang.Long,java.util.List<Session>> ketamaSessions
-
hashAlg
private final HashAlgorithm hashAlg
-
maxTries
private int maxTries
-
DEFAULT_PORT
static final int DEFAULT_PORT
compatible with nginx-upstream-consistent,patched by wolfg1969- See Also:
- Constant Field Values
-
cwNginxUpstreamConsistent
private final boolean cwNginxUpstreamConsistent
-
gwhalinMemcachedJavaClientCompatibiltyConsistent
private final boolean gwhalinMemcachedJavaClientCompatibiltyConsistent
-
-
Constructor Detail
-
KetamaMemcachedSessionLocator
public KetamaMemcachedSessionLocator()
Create a KetamaMemcachedSessionLocator with default config.
-
KetamaMemcachedSessionLocator
public KetamaMemcachedSessionLocator(boolean cwNginxUpstreamConsistent)
Create a KetamaMemcachedSessionLocator- Parameters:
cwNginxUpstreamConsistent- true if compatible with nginx up stream memcached consistent algorithm.
-
KetamaMemcachedSessionLocator
public KetamaMemcachedSessionLocator(HashAlgorithm alg)
Create a KetamaMemcachedSessionLocator with a special hash algorithm.- Parameters:
alg-
-
KetamaMemcachedSessionLocator
public KetamaMemcachedSessionLocator(HashAlgorithm alg, boolean cwNginxUpstreamConsistent)
-
KetamaMemcachedSessionLocator
public KetamaMemcachedSessionLocator(HashAlgorithm alg, boolean cwNginxUpstreamConsistent, boolean gwhalinMemcachedJavaClientCompatibiltyConsistent)
-
KetamaMemcachedSessionLocator
public KetamaMemcachedSessionLocator(java.util.List<Session> list, HashAlgorithm alg)
-
-
Method Detail
-
buildMap
private final void buildMap(java.util.Collection<Session> list, HashAlgorithm alg)
-
getSockStr
private java.lang.String getSockStr(Session session)
-
getSessionList
private java.util.List<Session> getSessionList(java.util.TreeMap<java.lang.Long,java.util.List<Session>> sessionMap, long k)
-
getSessionByKey
public final Session getSessionByKey(java.lang.String key)
Description copied from interface:MemcachedSessionLocatorReturns a session by special key.- Returns:
-
getSessionByHash
public final Session getSessionByHash(long hash)
-
nextHash
public final long nextHash(long hashVal, java.lang.String key, int tries)
-
updateSessions
public final void updateSessions(java.util.Collection<Session> list)
Description copied from interface:MemcachedSessionLocatorUpdate sessions when session was added or removed.- Parameters:
list- The newer sessions
-
-