use of com.hazelcast.spi.partition.IPartitionService in project hazelcast by hazelcast.
the class ListKeyValueSource method open.
@Override
public boolean open(NodeEngine nodeEngine) {
NodeEngineImpl nei = (NodeEngineImpl) nodeEngine;
ss = nei.getSerializationService();
Address thisAddress = nei.getThisAddress();
IPartitionService ps = nei.getPartitionService();
Data data = ss.toData(listName, StringAndPartitionAwarePartitioningStrategy.INSTANCE);
int partitionId = ps.getPartitionId(data);
Address partitionOwner = ps.getPartitionOwner(partitionId);
if (partitionOwner == null) {
return false;
}
if (thisAddress.equals(partitionOwner)) {
ListService listService = nei.getService(ListService.SERVICE_NAME);
ListContainer listContainer = listService.getOrCreateContainer(listName, false);
List<CollectionItem> items = new ArrayList<CollectionItem>(listContainer.getCollection());
iterator = items.iterator();
}
return true;
}
use of com.hazelcast.spi.partition.IPartitionService in project hazelcast by hazelcast.
the class MapReduceUtil method enforcePartitionTableWarmup.
public static void enforcePartitionTableWarmup(MapReduceService mapReduceService) throws TimeoutException {
IPartitionService partitionService = mapReduceService.getNodeEngine().getPartitionService();
int partitionCount = partitionService.getPartitionCount();
long startTime = Clock.currentTimeMillis();
for (int p = 0; p < partitionCount; p++) {
while (partitionService.getPartitionOwner(p) == null) {
try {
Thread.sleep(RETRY_PARTITION_TABLE_MILLIS);
} catch (Exception ignore) {
EmptyStatement.ignore(ignore);
}
if (Clock.currentTimeMillis() - startTime > PARTITION_READY_TIMEOUT) {
throw new TimeoutException("Partition get ready timeout reached!");
}
}
}
}
use of com.hazelcast.spi.partition.IPartitionService in project hazelcast by hazelcast.
the class ScheduledExecutorServiceProxy method accumulateTaskHandlersAsScheduledFutures.
@SuppressWarnings("unchecked")
private <V> void accumulateTaskHandlersAsScheduledFutures(Map<Member, List<IScheduledFuture<V>>> accumulator, Map<?, ?> taskHandlersMap) {
ClusterService clusterService = getNodeEngine().getClusterService();
IPartitionService partitionService = getNodeEngine().getPartitionService();
for (Map.Entry<?, ?> entry : taskHandlersMap.entrySet()) {
Member owner;
Object key = entry.getKey();
if (key instanceof Number) {
owner = clusterService.getMember(partitionService.getPartitionOwner((Integer) key));
} else {
owner = (Member) key;
}
List<ScheduledTaskHandler> handlers = (List<ScheduledTaskHandler>) entry.getValue();
List<IScheduledFuture<V>> futures = new ArrayList<IScheduledFuture<V>>();
for (ScheduledTaskHandler handler : handlers) {
IScheduledFuture future = new ScheduledFutureProxy(handler);
attachHazelcastInstance(future);
futures.add(future);
}
if (accumulator.containsKey(owner)) {
List<IScheduledFuture<V>> memberFutures = accumulator.get(owner);
memberFutures.addAll(futures);
} else {
accumulator.put(owner, futures);
}
}
}
use of com.hazelcast.spi.partition.IPartitionService in project hazelcast by hazelcast.
the class RingbufferService method clearRingbuffersHavingLesserBackupCountThan.
private void clearRingbuffersHavingLesserBackupCountThan(int partitionId, int thresholdReplicaIndex) {
Iterator<Map.Entry<String, RingbufferContainer>> iterator = containers.entrySet().iterator();
IPartitionService partitionService = nodeEngine.getPartitionService();
while (iterator.hasNext()) {
Map.Entry<String, RingbufferContainer> entry = iterator.next();
String name = entry.getKey();
int containerPartitionId = partitionService.getPartitionId(getPartitionKey(name));
if (containerPartitionId != partitionId) {
continue;
}
RingbufferContainer container = entry.getValue();
if (thresholdReplicaIndex < 0 || thresholdReplicaIndex > container.getConfig().getTotalBackupCount()) {
iterator.remove();
}
}
}
use of com.hazelcast.spi.partition.IPartitionService in project hazelcast by hazelcast.
the class AbstractCacheProxy method getPartitionsForKeys.
private Set<Integer> getPartitionsForKeys(Set<Data> keys) {
IPartitionService partitionService = getNodeEngine().getPartitionService();
int partitions = partitionService.getPartitionCount();
int capacity = Math.min(partitions, keys.size());
Set<Integer> partitionIds = new HashSet<Integer>(capacity);
Iterator<Data> iterator = keys.iterator();
while (iterator.hasNext() && partitionIds.size() < partitions) {
Data key = iterator.next();
partitionIds.add(partitionService.getPartitionId(key));
}
return partitionIds;
}
Aggregations