org.infinispan.distribution.impl.DistributionManagerImpl Maven / Gradle / Ivy
package org.infinispan.distribution.impl;
import org.infinispan.distribution.DataLocality;
import org.infinispan.distribution.DistributionManager;
import org.infinispan.distribution.ch.ConsistentHash;
import org.infinispan.factories.annotations.Inject;
import org.infinispan.factories.annotations.Start;
import org.infinispan.jmx.annotations.MBean;
import org.infinispan.jmx.annotations.ManagedOperation;
import org.infinispan.jmx.annotations.Parameter;
import org.infinispan.statetransfer.StateTransferManager;
import org.infinispan.remoting.rpc.RpcManager;
import org.infinispan.remoting.transport.Address;
import org.infinispan.topology.CacheTopology;
import org.infinispan.util.logging.Log;
import org.infinispan.util.logging.LogFactory;
import java.util.*;
/**
* The default distribution manager implementation
*
* @author Manik Surtani
* @author Vladimir Blagojevic
* @author [email protected]
* @author Bela Ban
* @author Dan Berindei
* @author [email protected]
* @since 4.0
*/
@MBean(objectName = "DistributionManager", description = "Component that handles distribution of content across a cluster")
public class DistributionManagerImpl implements DistributionManager {
private static final Log log = LogFactory.getLog(DistributionManagerImpl.class);
private static final boolean trace = log.isTraceEnabled();
// Injected components
private RpcManager rpcManager;
private StateTransferManager stateTransferManager;
/**
* Default constructor
*/
public DistributionManagerImpl() {
}
@Inject
public void init(RpcManager rpcManager, StateTransferManager stateTransferManager) {
this.rpcManager = rpcManager;
this.stateTransferManager = stateTransferManager;
}
// The DMI is cache-scoped, so it will always start after the RMI, which is global-scoped
@Start(priority = 20)
@SuppressWarnings("unused")
private void start() throws Exception {
if (trace) log.tracef("starting distribution manager on %s", getAddress());
}
private Address getAddress() {
return rpcManager.getAddress();
}
@Override
public DataLocality getLocality(Object key) {
boolean transferInProgress = stateTransferManager.isStateTransferInProgressForKey(key);
CacheTopology topology = stateTransferManager.getCacheTopology();
// Null topology means state transfer has not occurred,
// hence data should be stored locally.
boolean local = topology == null
|| topology.getWriteConsistentHash().isKeyLocalToNode(getAddress(), key);
if (transferInProgress) {
if (local) {
return DataLocality.LOCAL_UNCERTAIN;
} else {
return DataLocality.NOT_LOCAL_UNCERTAIN;
}
} else {
if (local) {
return DataLocality.LOCAL;
} else {
return DataLocality.NOT_LOCAL;
}
}
}
@Override
public List locate(Object key) {
return getConsistentHash().locateOwners(key);
}
@Override
public Address getPrimaryLocation(Object key) {
return getConsistentHash().locatePrimaryOwner(key);
}
@Override
public Set locateAll(Collection
© 2015 - 2025 Weber Informatics LLC | Privacy Policy