org.infinispan.distribution
Class DefaultConsistentHash

java.lang.Object
  extended by org.infinispan.distribution.AbstractConsistentHash
      extended by org.infinispan.distribution.DefaultConsistentHash
All Implemented Interfaces:
ConsistentHash

public class DefaultConsistentHash
extends AbstractConsistentHash


Nested Class Summary
static class DefaultConsistentHash.Externalizer
           
 
Constructor Summary
DefaultConsistentHash()
           
 
Method Summary
 boolean equals(Object o)
           
 List<Address> getCaches()
          Should return a collection of cache addresses in the cluster.
 int getDistance(Address a1, Address a2)
          Calculates the logical distance between two addresses.
 int hashCode()
           
 boolean isAdjacent(Address a1, Address a2)
          Tests whether two addresses are logically next to each other in the hash space.
 boolean isKeyLocalToAddress(Address target, 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).
 void setCaches(List<Address> caches)
          Sets the collection of cache addresses in the cluster.
 String toString()
           
 
Methods inherited from class org.infinispan.distribution.AbstractConsistentHash
locateAll
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

DefaultConsistentHash

public DefaultConsistentHash()
Method Detail

setCaches

public void setCaches(List<Address> caches)
Description copied from interface: ConsistentHash
Sets the collection of cache addresses in the cluster. The implementation should store these internally and use these to locate keys.

Parameters:
caches - caches in cluster.

getCaches

public List<Address> getCaches()
Description copied from interface: ConsistentHash
Should return a collection of cache addresses in the cluster.

Returns:
collection of cache addresses

locate

public List<Address> locate(Object key,
                            int replCount)
Description copied from interface: ConsistentHash
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 ConsistentHash.setCaches(java.util.List). Should never be null, and should contain replCount elements or the max number of caches available, whichever is smaller.

isKeyLocalToAddress

public boolean isKeyLocalToAddress(Address target,
                                   Object key,
                                   int replCount)
Description copied from interface: ConsistentHash
Test to see whether a key is mapped to a given address.

Specified by:
isKeyLocalToAddress in interface ConsistentHash
Overrides:
isKeyLocalToAddress in class AbstractConsistentHash
Parameters:
target - address to test
key - key to test
replCount - repl count
Returns:
true if the key is mapped to the address; false otherwise

getDistance

public int getDistance(Address a1,
                       Address a2)
Description copied from interface: ConsistentHash
Calculates the logical distance between two addresses. This distance is based on where the addresses lie in the hash space.

Parameters:
a1 - address to test
a2 - address to test
Returns:
the distance between the 2 nodes. Always a positive number, where the distance between a1 and itself is 0. The distance between a1 and the next adjacent node is 1 and teh distance between a1 and the previous adjacent node is caches.size() - 1. A -1 may be returned if either of the addresses do not exist.

isAdjacent

public boolean isAdjacent(Address a1,
                          Address a2)
Description copied from interface: ConsistentHash
Tests whether two addresses are logically next to each other in the hash space.

Parameters:
a1 - address to test
a2 - address to test
Returns:
true if adjacent, false if not

equals

public boolean equals(Object o)
Overrides:
equals in class Object

hashCode

public int hashCode()
Overrides:
hashCode in class Object

toString

public String toString()
Overrides:
toString in class Object

Google Analytics

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