use of com.hazelcast.spi.impl.NodeEngine in project hazelcast by hazelcast.
the class ExecutionPlanBuilder method getPartitionAssignment.
/**
* Assign the partitions to their owners. Partitions whose owner isn't in
* the {@code memberList}, are assigned to one of the members in a
* round-robin way.
*/
public static Map<MemberInfo, int[]> getPartitionAssignment(NodeEngine nodeEngine, List<MemberInfo> memberList) {
IPartitionService partitionService = nodeEngine.getPartitionService();
Map<Address, MemberInfo> membersByAddress = memberList.stream().collect(toMap(MemberInfo::getAddress, identity()));
final MemberInfo[] partitionOwners = new MemberInfo[partitionService.getPartitionCount()];
int memberIndex = 0;
for (int partitionId = 0; partitionId < partitionOwners.length; partitionId++) {
Address address = partitionService.getPartitionOwnerOrWait(partitionId);
MemberInfo member = membersByAddress.get(address);
if (member == null) {
// if the partition owner isn't in the current memberList, assign to one of the other members in
// round-robin fashion
member = memberList.get(memberIndex++ % memberList.size());
}
partitionOwners[partitionId] = member;
}
return IntStream.range(0, partitionOwners.length).mapToObj(i -> tuple2(partitionOwners[i], i)).collect(Collectors.groupingBy(Tuple2::f0, Collectors.mapping(Tuple2::f1, Collectors.collectingAndThen(Collectors.<Integer>toList(), intList -> intList.stream().mapToInt(Integer::intValue).toArray()))));
}
use of com.hazelcast.spi.impl.NodeEngine in project hazelcast by hazelcast.
the class MapContainer method initEvictor.
public final void initEvictor() {
NodeEngine nodeEngine = mapServiceContext.getNodeEngine();
EvictionPolicyComparator evictionPolicyComparator = getEvictionPolicyComparator(mapConfig.getEvictionConfig(), nodeEngine.getConfigClassLoader());
evictor = evictionPolicyComparator != null ? newEvictor(evictionPolicyComparator, nodeEngine.getProperties().getInteger(MAP_EVICTION_BATCH_SIZE), nodeEngine.getPartitionService()) : NULL_EVICTOR;
}
use of com.hazelcast.spi.impl.NodeEngine in project hazelcast by hazelcast.
the class NodeQueryCacheEventService method canPassFilter.
private boolean canPassFilter(LocalEntryEventData localEntryEventData, EventFilter filter, Extractors extractors) {
if (filter == null || filter instanceof TrueEventFilter) {
return true;
}
NodeEngine nodeEngine = mapServiceContext.getNodeEngine();
SerializationService serializationService = nodeEngine.getSerializationService();
Data keyData = localEntryEventData.getKeyData();
Object value = getValueOrOldValue(localEntryEventData);
QueryableEntry entry = new QueryEntry(serializationService, keyData, value, extractors);
return filter.eval(entry);
}
use of com.hazelcast.spi.impl.NodeEngine in project hazelcast by hazelcast.
the class MultiMapProxyImpl method toObjectSet.
private Set<K> toObjectSet(Set<Data> dataSet) {
NodeEngine nodeEngine = getNodeEngine();
Set<K> keySet = createHashSet(dataSet.size());
for (Data dataKey : dataSet) {
keySet.add((K) nodeEngine.toObject(dataKey));
}
if (config.isStatisticsEnabled()) {
getService().getLocalMultiMapStatsImpl(name).incrementOtherOperations();
}
return keySet;
}
use of com.hazelcast.spi.impl.NodeEngine in project hazelcast by hazelcast.
the class MultiMapProxySupport method clear.
public void clear() {
NodeEngine nodeEngine = getNodeEngine();
try {
Map<Integer, Object> resultMap = nodeEngine.getOperationService().invokeOnAllPartitions(MultiMapService.SERVICE_NAME, new MultiMapOperationFactory(name, OperationFactoryType.CLEAR));
if (config.isStatisticsEnabled()) {
getService().getLocalMultiMapStatsImpl(name).incrementOtherOperations();
}
int numberOfAffectedEntries = 0;
for (Object o : resultMap.values()) {
numberOfAffectedEntries += (Integer) o;
}
publishMultiMapEvent(numberOfAffectedEntries, EntryEventType.CLEAR_ALL);
} catch (Throwable throwable) {
throw ExceptionUtil.rethrow(throwable);
}
}
Aggregations