org.infinispan.distribution.impl.DistributionManagerImpl Maven / Gradle / Ivy
package org.infinispan.distribution.impl;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
import org.infinispan.configuration.cache.CacheMode;
import org.infinispan.configuration.cache.Configuration;
import org.infinispan.distribution.DataLocality;
import org.infinispan.distribution.DistributionInfo;
import org.infinispan.distribution.DistributionManager;
import org.infinispan.distribution.LocalizedCacheTopology;
import org.infinispan.distribution.ch.ConsistentHash;
import org.infinispan.distribution.ch.KeyPartitioner;
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.remoting.transport.Address;
import org.infinispan.remoting.transport.LocalModeAddress;
import org.infinispan.remoting.transport.Transport;
import org.infinispan.topology.CacheTopology;
import org.infinispan.util.logging.Log;
import org.infinispan.util.logging.LogFactory;
/**
* 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 Transport transport;
private KeyPartitioner keyPartitioner;
private CacheMode cacheMode;
private volatile LocalizedCacheTopology extendedTopology;
/**
* Default constructor
*/
public DistributionManagerImpl() {
}
@Inject
public void init(Transport transport, Configuration configuration, KeyPartitioner keyPartitioner) {
this.transport = transport;
this.keyPartitioner = keyPartitioner;
this.cacheMode = configuration.clustering().cacheMode();
}
// Start before RpcManagerImpl
@Start(priority = 8)
@SuppressWarnings("unused")
private void start() throws Exception {
if (trace) log.tracef("starting distribution manager on %s", getAddress());
// We need an extended topology for preload, before the start of StateTransferManagerImpl
Address localAddress = transport == null ? LocalModeAddress.INSTANCE : transport.getAddress();
extendedTopology = LocalizedCacheTopology.makeSingletonTopology(cacheMode, localAddress);
}
private Address getAddress() {
return transport.getAddress();
}
@Override
public DataLocality getLocality(Object key) {
LocalizedCacheTopology info = this.extendedTopology;
if (info == null) {
return DataLocality.NOT_LOCAL;
}
DistributionInfo segmentInfo = info.getDistribution(key);
if (segmentInfo.isReadOwner()) {
return DataLocality.LOCAL;
} else if (segmentInfo.isWriteOwner()) {
return DataLocality.LOCAL_UNCERTAIN;
} else {
return DataLocality.NOT_LOCAL;
}
}
@Override
public List locate(Object key) {
return extendedTopology.getDistribution(key).writeOwners();
}
@Override
public Address getPrimaryLocation(Object key) {
return extendedTopology.getDistribution(key).primary();
}
@Override
public Set locateAll(Collection
© 2015 - 2025 Weber Informatics LLC | Privacy Policy