org.infinispan.distribution.ch
Interface ConsistentHash

All Known Implementing Classes:
AbstractConsistentHash, AbstractWheelConsistentHash, DefaultConsistentHash, ExperimentalDefaultConsistentHash, TopologyAwareConsistentHash, UnionConsistentHash

public interface ConsistentHash

A consistent hash algorithm implementation. Implementations would typically be constructed via reflection so should implement a public, no-arg constructor.

Since:
4.0
Author:
Manik Surtani, Mircea.Markus@jboss.com

Method Summary
 List<Address> getBackupsForNode(Address node, int replCount)
          Deprecated. No longer supported. This method doesn't make sense with virtual nodes enabled.
 Set<Address> getCaches()
          Should return a collection of cache addresses in the cluster.
 List<Integer> getHashIds(Address a)
          Returns a list of values between 0 and the hash space limit, or hash id, for a particular address.
 List<Address> getStateProvidersOnJoin(Address joiner, int replCount)
          Deprecated. No longer supported. This method doesn't make sense with virtual nodes enabled.
 List<Address> getStateProvidersOnLeave(Address leaver, int replCount)
          Deprecated. No longer supported. This method doesn't make sense with virtual nodes enabled.
 boolean isKeyLocalToAddress(Address a, Object key, int replCount)
          Test to see whether a key is mapped to a given address.
 List<Address> locate(Object key, int replCount)
          Locates a key, given a replication count (number of copies).
 Map<Object,List<Address>> locateAll(Collection<Object> keys, int replCount)
          The logical equivalent of calling locate(Object, int) multiple times for each key in the collection of keys.
 Address primaryLocation(Object key)
          Should be equivalent to return the first element of locate(Object, int).
 void setCaches(Set<Address> caches)
          Sets the collection of cache addresses in the cluster.
 

Method Detail

setCaches

void setCaches(Set<Address> caches)
Sets the collection of cache addresses in the cluster. The implementation should store these internally and use these to locate keys.

Parameters:
caches - A set of unique caches in cluster.

getCaches

Set<Address> getCaches()
Should return a collection of cache addresses in the cluster.

Returns:
set of unique of cache addresses

locate

List<Address> locate(Object key,
                     int replCount)
Locates a key, given a replication count (number of copies).

Parameters:
key - key to locate
replCount - replication count (number of copies)
Returns:
a list of addresses where the key resides, where this list is a subset of the addresses set in setCaches(java.util.Set). Should never be null, and should contain replCount elements or the max number of caches available, whichever is smaller.

locateAll

Map<Object,List<Address>> locateAll(Collection<Object> keys,
                                    int replCount)
The logical equivalent of calling locate(Object, int) multiple times for each key in the collection of keys. Implementations may be optimised for such a bulk lookup, or may just repeatedly call locate(Object, int).

Parameters:
keys - keys to locate
replCount - replication count (number of copies) for each key
Returns:
Map of locations, keyed on key.

isKeyLocalToAddress

boolean isKeyLocalToAddress(Address a,
                            Object key,
                            int replCount)
Test to see whether a key is mapped to a given address.

Parameters:
a - address to test
key - key to test
replCount - repl count
Returns:
true if the key is mapped to the address; false otherwise

getHashIds

List<Integer> getHashIds(Address a)
Returns a list of values between 0 and the hash space limit, or hash id, for a particular address. If virtual nodes are disabled, the list will only contain a single element, whereas if virtual nodes are enabled, this list's size will be the number of virtual nodes configured. If there are no hash ids for that address, it returns an empty list.

Returns:
A list of N size where N is the configured number of virtual nodes, or an empty list if there're no hash ids associated with the address.

getStateProvidersOnLeave

@Deprecated
List<Address> getStateProvidersOnLeave(Address leaver,
                                                  int replCount)
Deprecated. No longer supported. This method doesn't make sense with virtual nodes enabled.

Returns the nodes that need will replicate their state if the specified node crashes. The return collection should contain all the nodes that backup-ed on leaver and one of the nodes which acted as a backup for the leaver .

Pre: leaver must be present in the caches known to this CH, as returned by getCaches()

Parameters:
leaver - the node that leaves the cluster
replCount -

getStateProvidersOnJoin

@Deprecated
List<Address> getStateProvidersOnJoin(Address joiner,
                                                 int replCount)
Deprecated. No longer supported. This method doesn't make sense with virtual nodes enabled.

Returns the nodes that would act as state providers when a new node joins: - the nodes for which the joiner is a backup - the nodes that held joiner's state


getBackupsForNode

@Deprecated
List<Address> getBackupsForNode(Address node,
                                           int replCount)
Deprecated. No longer supported. This method doesn't make sense with virtual nodes enabled.

Returns the nodes that backup data for the supplied node including the node itself.


primaryLocation

Address primaryLocation(Object key)
Should be equivalent to return the first element of locate(Object, int). Useful as a performance optimization, as this is a frequently needed information.

Parameters:
key - key to locate
Returns:

-->

Copyright © 2012 JBoss, a division of Red Hat. All Rights Reserved.