org.infinispan.distribution
Class DistributionManagerImpl

java.lang.Object
  extended by org.infinispan.distribution.DistributionManagerImpl
All Implemented Interfaces:
DistributionManager

public class DistributionManagerImpl
extends Object
implements DistributionManager

The default distribution manager implementation

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

Nested Class Summary
 class DistributionManagerImpl.ViewChangeListener
           
 
Constructor Summary
DistributionManagerImpl()
          Default constructor
 
Method Summary
 void applyRemoteTxLog(List<WriteCommand> commands)
          Applies an ordered list of modifications to the current node.
 void applyState(ConsistentHash consistentHash, Map<Object,InternalCacheValue> state, RemoteTransactionLogger tlog, boolean forLeave)
           
 boolean awaitLeaveRehashAcks(Set<Address> stateReceivers, long timeout)
           
 List<Address> getAffectedNodes(Set<Object> affectedKeys)
          A helper method that retrieves a list of nodes affected by operations on a set of keys.
 CacheStore getCacheStoreForRehashing()
          Retrieves a cache store if one is available and set up for use in rehashing.
 ConsistentHash getConsistentHash()
          Retrieves the consistent hash instance currently in use, which may be an instance of the configured ConsistentHash instance (which defaults to DefaultConsistentHash, or an instance of UnionConsistentHash if a rehash is in progress.
 List<Address> getLeavers()
           
 DataLocality getLocality(Object key)
           
 TopologyInfo getTopologyInfo()
           
 TransactionLogger getTransactionLogger()
          Retrieves the transaction logger instance associated with this DistributionManager
 NodeTopologyInfo informRehashOnJoin(Address a, boolean starting, NodeTopologyInfo nodeTopologyInfo)
          This will cause all nodes to add the joiner to their consistent hash instance (usually by creating a UnionConsistentHash
 void informRehashOnLeave(Address sender)
           
 void init(Configuration configuration, RpcManager rpcManager, CacheManagerNotifier notifier, CommandsFactory cf, DataContainer dataContainer, InterceptorChain interceptorChain, InvocationContextContainer icc, CacheLoaderManager cacheLoaderManager, InboundInvocationHandler inboundInvocationHandler)
           
 boolean isAffectedByRehash(Object key)
          Tests whether a given key is affected by a rehash that may be in progress.
 boolean isInFinalJoinPhase()
           
 boolean isJoinComplete()
          Tests whether the current instance has completed joining the cluster
 boolean isLocatedLocally(String key)
           
 boolean isRehashInProgress()
          Tests whether a rehash is in progress
 List<Address> locate(Object key)
          Locates a key in a cluster.
 Map<Object,List<Address>> locateAll(Collection<Object> keys)
          Locates a list of keys in a cluster.
 Map<Object,List<Address>> locateAll(Collection<Object> keys, int numOwners)
          Same as DistributionManager.locateAll(java.util.Collection), but the list of addresses only contains numOwners owners.
 List<String> locateKey(String key)
           
 void markLeaverAsHandled(Address leaver)
           
 void rehash(List<Address> newMembers, List<Address> oldMembers)
           
 boolean removeLeaver(Address leaver)
           
 List<Address> requestPermissionToJoin(Address a)
          "Asks" a coordinator if a joiner may join.
 InternalCacheEntry retrieveFromRemoteSource(Object key, InvocationContext ctx)
          Retrieves a cache entry from a remote source.
 void setConsistentHash(ConsistentHash consistentHash)
          Sets the consistent hash implementation in use.
 void setJoinComplete(boolean joinComplete)
           
 void setOldConsistentHash(ConsistentHash oldConsistentHash)
           
 void setRehashInProgress(boolean value)
           
 void start()
           
 void stop()
           
 String toString()
           
 void transformForL1(CacheEntry entry)
          Transforms a cache entry so it is marked for L1 rather than the primary cache data structure.
 void waitForFinalJoin()
           
 void waitForJoinToComplete()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

DistributionManagerImpl

public DistributionManagerImpl()
Default constructor

Method Detail

init

public void init(Configuration configuration,
                 RpcManager rpcManager,
                 CacheManagerNotifier notifier,
                 CommandsFactory cf,
                 DataContainer dataContainer,
                 InterceptorChain interceptorChain,
                 InvocationContextContainer icc,
                 CacheLoaderManager cacheLoaderManager,
                 InboundInvocationHandler inboundInvocationHandler)

start

public void start()
           throws Exception
Throws:
Exception

waitForJoinToComplete

public void waitForJoinToComplete()
                           throws Throwable
Throws:
Throwable

stop

public void stop()

rehash

public void rehash(List<Address> newMembers,
                   List<Address> oldMembers)

getLeavers

public List<Address> getLeavers()

removeLeaver

public boolean removeLeaver(Address leaver)

getLocality

public DataLocality getLocality(Object key)
Specified by:
getLocality in interface DistributionManager

locate

public List<Address> locate(Object key)
Description copied from interface: DistributionManager
Locates a key in a cluster. The returned addresses may not be owners of the keys if a rehash happens to be in progress or is pending, so when querying these servers, invalid responses should be checked for and the next address checked accordingly.

Specified by:
locate in interface DistributionManager
Parameters:
key - key to test
Returns:
a list of addresses where the key may reside

locateAll

public Map<Object,List<Address>> locateAll(Collection<Object> keys)
Description copied from interface: DistributionManager
Locates a list of keys in a cluster. Like DistributionManager.locate(Object) the returned addresses may not be owners of the keys if a rehash happens to be in progress or is pending, so when querying these servers, invalid responses should be checked for and the next address checked accordingly.

Specified by:
locateAll in interface DistributionManager
Parameters:
keys - list of keys to test
Returns:
a list of addresses where the key may reside

locateAll

public Map<Object,List<Address>> locateAll(Collection<Object> keys,
                                           int numOwners)
Description copied from interface: DistributionManager
Same as DistributionManager.locateAll(java.util.Collection), but the list of addresses only contains numOwners owners.

Specified by:
locateAll in interface DistributionManager

transformForL1

public void transformForL1(CacheEntry entry)
Description copied from interface: DistributionManager
Transforms a cache entry so it is marked for L1 rather than the primary cache data structure. This should be done if it is deemed that the entry is targeted for L1 storage rather than storage in the primary data container.

Specified by:
transformForL1 in interface DistributionManager
Parameters:
entry - entry to transform

retrieveFromRemoteSource

public InternalCacheEntry retrieveFromRemoteSource(Object key,
                                                   InvocationContext ctx)
                                            throws Exception
Description copied from interface: DistributionManager
Retrieves a cache entry from a remote source. Would typically involve an RPC call using a ClusteredGetCommand and some form of quorum of responses if the responses returned are inconsistent - often the case if there is a rehash in progress, involving nodes that the key maps to.

Specified by:
retrieveFromRemoteSource in interface DistributionManager
Parameters:
key - key to look up
Returns:
an internal cache entry, or null if it cannot be located
Throws:
Exception - if something bad happens

getConsistentHash

public ConsistentHash getConsistentHash()
Description copied from interface: DistributionManager
Retrieves the consistent hash instance currently in use, which may be an instance of the configured ConsistentHash instance (which defaults to DefaultConsistentHash, or an instance of UnionConsistentHash if a rehash is in progress.

Specified by:
getConsistentHash in interface DistributionManager
Returns:
a ConsistentHash instance

setConsistentHash

public void setConsistentHash(ConsistentHash consistentHash)
Description copied from interface: DistributionManager
Sets the consistent hash implementation in use.

Specified by:
setConsistentHash in interface DistributionManager
Parameters:
consistentHash - consistent hash to set to

setOldConsistentHash

public void setOldConsistentHash(ConsistentHash oldConsistentHash)

isAffectedByRehash

public boolean isAffectedByRehash(Object key)
Description copied from interface: DistributionManager
Tests whether a given key is affected by a rehash that may be in progress. If no rehash is in progress, this method returns false. Helps determine whether additional steps are necessary in handling an operation with a given key.

Specified by:
isAffectedByRehash in interface DistributionManager
Parameters:
key - key to test
Returns:
whether a key is affected by a rehash

getTransactionLogger

public TransactionLogger getTransactionLogger()
Description copied from interface: DistributionManager
Retrieves the transaction logger instance associated with this DistributionManager

Specified by:
getTransactionLogger in interface DistributionManager
Returns:
a TransactionLogger

requestPermissionToJoin

public List<Address> requestPermissionToJoin(Address a)
Description copied from interface: DistributionManager
"Asks" a coordinator if a joiner may join. Used to serialize joins such that only a single joiner comes in at any given time.

Specified by:
requestPermissionToJoin in interface DistributionManager
Parameters:
a - joiner who wants to join
Returns:
a consistent hash prior to the joiner joining (if the joiner is allowed to join), otherwise null.

informRehashOnJoin

public NodeTopologyInfo informRehashOnJoin(Address a,
                                           boolean starting,
                                           NodeTopologyInfo nodeTopologyInfo)
Description copied from interface: DistributionManager
This will cause all nodes to add the joiner to their consistent hash instance (usually by creating a UnionConsistentHash

Specified by:
informRehashOnJoin in interface DistributionManager
Parameters:
a - address of joiner
starting - if true, the joiner is reporting that it is starting the join process. If false, the joiner is

informRehashOnLeave

public void informRehashOnLeave(Address sender)
Specified by:
informRehashOnLeave in interface DistributionManager

applyState

public void applyState(ConsistentHash consistentHash,
                       Map<Object,InternalCacheValue> state,
                       RemoteTransactionLogger tlog,
                       boolean forLeave)
Specified by:
applyState in interface DistributionManager

setRehashInProgress

public void setRehashInProgress(boolean value)
Specified by:
setRehashInProgress in interface DistributionManager

getCacheStoreForRehashing

public CacheStore getCacheStoreForRehashing()
Description copied from interface: DistributionManager
Retrieves a cache store if one is available and set up for use in rehashing. May return null!

Specified by:
getCacheStoreForRehashing in interface DistributionManager
Returns:
a cache store is one is available and configured for use in rehashing, or null otherwise.

isRehashInProgress

public boolean isRehashInProgress()
Description copied from interface: DistributionManager
Tests whether a rehash is in progress

Specified by:
isRehashInProgress in interface DistributionManager
Returns:
true if a rehash is in progress, false otherwise

markLeaverAsHandled

public void markLeaverAsHandled(Address leaver)

isJoinComplete

public boolean isJoinComplete()
Description copied from interface: DistributionManager
Tests whether the current instance has completed joining the cluster

Specified by:
isJoinComplete in interface DistributionManager
Returns:
true if join is in progress, false otherwise

waitForFinalJoin

public void waitForFinalJoin()
Specified by:
waitForFinalJoin in interface DistributionManager

isInFinalJoinPhase

public boolean isInFinalJoinPhase()
Specified by:
isInFinalJoinPhase in interface DistributionManager

setJoinComplete

public void setJoinComplete(boolean joinComplete)
Specified by:
setJoinComplete in interface DistributionManager

getAffectedNodes

public List<Address> getAffectedNodes(Set<Object> affectedKeys)
Description copied from interface: DistributionManager
A helper method that retrieves a list of nodes affected by operations on a set of keys. This helper will in turn call DistributionManager.locateAll(java.util.Collection) and then combine the result addresses.

Specified by:
getAffectedNodes in interface DistributionManager
Parameters:
affectedKeys - keys to locate
Returns:
a list of addresses which represent a combined set of all addresses affected by the set of keys.

applyRemoteTxLog

public void applyRemoteTxLog(List<WriteCommand> commands)
Description copied from interface: DistributionManager
Applies an ordered list of modifications to the current node. Typically used when state is pushed to the node (i.e., anotehr node leaves the cluster) and the transaction log needs to be flushed after pushing state.

Specified by:
applyRemoteTxLog in interface DistributionManager
Parameters:
commands - ordered list of mods

isLocatedLocally

public boolean isLocatedLocally(String key)

locateKey

public List<String> locateKey(String key)

toString

public String toString()
Overrides:
toString in class Object

getTopologyInfo

public TopologyInfo getTopologyInfo()
Specified by:
getTopologyInfo in interface DistributionManager

awaitLeaveRehashAcks

public boolean awaitLeaveRehashAcks(Set<Address> stateReceivers,
                                    long timeout)
                             throws InterruptedException
Throws:
InterruptedException


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