use of com.hazelcast.internal.util.collection.PartitionIdSet in project hazelcast by hazelcast.
the class MapServiceContextImpl method getOrInitCachedMemberPartitions.
@Override
public PartitionIdSet getOrInitCachedMemberPartitions() {
PartitionIdSet ownedPartitionIdSet = ownedPartitions;
if (ownedPartitionIdSet != null) {
return ownedPartitionIdSet;
}
synchronized (this) {
ownedPartitionIdSet = ownedPartitions;
if (ownedPartitionIdSet != null) {
return ownedPartitionIdSet;
}
IPartitionService partitionService = nodeEngine.getPartitionService();
Collection<Integer> partitions = partitionService.getMemberPartitions(nodeEngine.getThisAddress());
ownedPartitionIdSet = immutablePartitionIdSet(partitionService.getPartitionCount(), partitions);
ownedPartitions = ownedPartitionIdSet;
}
return ownedPartitionIdSet;
}
use of com.hazelcast.internal.util.collection.PartitionIdSet in project hazelcast by hazelcast.
the class MapProxySupport method waitAllTrue.
private void waitAllTrue(Map<Integer, Object> results, OperationFactory operationFactory) throws InterruptedException {
Iterator<Entry<Integer, Object>> iterator = results.entrySet().iterator();
boolean isFinished = false;
PartitionIdSet retrySet = new PartitionIdSet(partitionService.getPartitionCount());
while (!isFinished) {
while (iterator.hasNext()) {
Entry<Integer, Object> entry = iterator.next();
if (Boolean.TRUE.equals(entry.getValue())) {
iterator.remove();
} else {
retrySet.add(entry.getKey());
}
}
if (!retrySet.isEmpty()) {
results = retryPartitions(retrySet, operationFactory);
iterator = results.entrySet().iterator();
TimeUnit.SECONDS.sleep(1);
retrySet.clear();
} else {
isFinished = true;
}
}
}
use of com.hazelcast.internal.util.collection.PartitionIdSet in project hazelcast by hazelcast.
the class CacheProxy method getAll.
@Override
public Map<K, V> getAll(Set<? extends K> keys, ExpiryPolicy expiryPolicy) {
ensureOpen();
validateNotNull(keys);
if (keys.isEmpty()) {
return emptyMap();
}
final int keyCount = keys.size();
final Set<Data> ks = createHashSet(keyCount);
for (K key : keys) {
validateNotNull(key);
Data dataKey = serializationService.toData(key);
ks.add(dataKey);
}
Map<K, V> result = createHashMap(keyCount);
PartitionIdSet partitions = getPartitionsForKeys(ks);
try {
OperationFactory factory = operationProvider.createGetAllOperationFactory(ks, expiryPolicy);
OperationService operationService = getNodeEngine().getOperationService();
Map<Integer, Object> responses = operationService.invokeOnPartitions(getServiceName(), factory, partitions);
for (Object response : responses.values()) {
MapEntries mapEntries = serializationService.toObject(response);
mapEntries.putAllToMap(serializationService, result);
}
} catch (Throwable e) {
throw rethrowAllowedTypeFirst(e, CacheException.class);
}
return result;
}
use of com.hazelcast.internal.util.collection.PartitionIdSet in project hazelcast by hazelcast.
the class CacheProxyLoadAllTask method run.
@Override
public void run() {
try {
completionListener = injectDependencies(completionListener);
OperationService operationService = nodeEngine.getOperationService();
OperationFactory operationFactory;
IPartitionService partitionService = nodeEngine.getPartitionService();
Map<Address, List<Integer>> memberPartitionsMap = partitionService.getMemberPartitionsMap();
int partitionCount = partitionService.getPartitionCount();
Map<Integer, Object> results = createHashMap(partitionCount);
for (Map.Entry<Address, List<Integer>> memberPartitions : memberPartitionsMap.entrySet()) {
Set<Integer> partitions = new PartitionIdSet(partitionCount, memberPartitions.getValue());
Set<Data> ownerKeys = filterOwnerKeys(partitionService, partitions);
operationFactory = operationProvider.createLoadAllOperationFactory(ownerKeys, replaceExistingValues);
Map<Integer, Object> memberResults;
memberResults = operationService.invokeOnPartitions(serviceName, operationFactory, partitions);
results.putAll(memberResults);
}
validateResults(results);
if (completionListener != null) {
completionListener.onCompletion();
}
} catch (Exception e) {
if (completionListener != null) {
completionListener.onException(e);
}
} catch (Throwable t) {
if (t instanceof OutOfMemoryError) {
throw rethrow(t);
} else {
if (completionListener != null) {
completionListener.onException(new CacheException(t));
}
}
}
}
use of com.hazelcast.internal.util.collection.PartitionIdSet in project hazelcast by hazelcast.
the class QueryEngineImplTest method runQueryOnGivenPartition.
@Test
public void runQueryOnGivenPartition() {
Predicate predicate = Predicates.equal("this", value);
Query query = Query.of().mapName(map.getName()).predicate(predicate).iterationType(ENTRY).build();
QueryResult result = queryEngine.execute(query, createPartitionTarget(new PartitionIdSet(271, partitionId)));
assertEquals(1, result.size());
assertEquals(key, toObject(((Map.Entry) result.iterator().next()).getKey()));
assertEquals(map.get(key), toObject(((Map.Entry) result.iterator().next()).getValue()));
}
Aggregations