Package net.spy.memcached
Class HashAlgorithmRegistry
- java.lang.Object
-
- net.spy.memcached.HashAlgorithmRegistry
-
public final class HashAlgorithmRegistry extends java.lang.ObjectRegistry of known hashing algorithms for locating a server for a key. Useful when configuring from files using algorithm names.Please, make sure you register your algorithm with {
registerHashAlgorithm(String, HashAlgorithm)before referring to it by name
-
-
Field Summary
Fields Modifier and Type Field Description private static java.util.Map<java.lang.String,HashAlgorithm>REGISTRYInternal registry storage.
-
Constructor Summary
Constructors Modifier Constructor Description privateHashAlgorithmRegistry()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static HashAlgorithmlookupHashAlgorithm(java.lang.String name)Tries to find selected hash algorithm using name provided.static voidregisterHashAlgorithm(java.lang.String name, HashAlgorithm alg)Registers providedHashAlgorithminstance with the given name.private static voidvalidateAlgorithm(HashAlgorithm alg)Validates algorithm instance.private static voidvalidateName(java.lang.String name)Validates name of the algorithm.
-
-
-
Field Detail
-
REGISTRY
private static final java.util.Map<java.lang.String,HashAlgorithm> REGISTRY
Internal registry storage.
-
-
Method Detail
-
registerHashAlgorithm
public static void registerHashAlgorithm(java.lang.String name, HashAlgorithm alg)Registers providedHashAlgorithminstance with the given name. Name is not case sensitive. Any registered algorithm with the same name will be substituted- Parameters:
name- name of the algorithmalg- algorithm instance to register
-
lookupHashAlgorithm
public static HashAlgorithm lookupHashAlgorithm(java.lang.String name)
Tries to find selected hash algorithm using name provided.Note, that lookup is being performed using name's lower-case value
- Parameters:
name- the algorithm name to be used for lookup- Returns:
- a
HashAlgorithminstance ornullif there's no algorithm with the specified name
-
validateName
private static void validateName(java.lang.String name)
Validates name of the algorithm. A non-empty name should be provided AnIllegalArgumentExceptionis being thrown in case of incorrect name- Parameters:
name- a name to validate
-
validateAlgorithm
private static void validateAlgorithm(HashAlgorithm alg)
Validates algorithm instance. A non-nullinstance should be provided. AnIllegalArgumentExceptionis being thrown in case ofnullinstance- Parameters:
alg- aHashAlgorithminstance to validate
-
-