use of com.hazelcast.spi.impl.operationservice.OperationService in project hazelcast by hazelcast.
the class CheckReplicaVersionOperation method requestDataFromOwner.
private void requestDataFromOwner(String name) {
OperationService operationService = getNodeEngine().getOperationService();
Operation op = new RequestMapDataOperation(name);
operationService.createInvocationBuilder(SERVICE_NAME, op, getPartitionId()).setTryCount(INVOCATION_TRY_COUNT).invoke();
}
use of com.hazelcast.spi.impl.operationservice.OperationService 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.spi.impl.operationservice.OperationService in project hazelcast by hazelcast.
the class CacheProxySupport method removeAllInternal.
protected void removeAllInternal(Set<? extends K> keys) {
Set<Data> keysData = null;
if (keys != null) {
keysData = createHashSet(keys.size());
for (K key : keys) {
validateNotNull(key);
keysData.add(serializationService.toData(key));
}
}
int partitionCount = getNodeEngine().getPartitionService().getPartitionCount();
Integer completionId = listenerCompleter.registerCompletionLatch(partitionCount);
OperationService operationService = getNodeEngine().getOperationService();
OperationFactory operationFactory = operationProvider.createRemoveAllOperationFactory(keysData, completionId);
try {
Map<Integer, Object> results = operationService.invokeOnAllPartitions(getServiceName(), operationFactory);
int completionCount = 0;
for (Object result : results.values()) {
if (result != null && result instanceof CacheClearResponse) {
Object response = ((CacheClearResponse) result).getResponse();
if (response instanceof Boolean) {
completionCount++;
}
if (response instanceof Throwable) {
throw (Throwable) response;
}
}
}
listenerCompleter.waitCompletionLatch(completionId, partitionCount - completionCount);
} catch (Throwable t) {
listenerCompleter.deregisterCompletionLatch(completionId);
throw rethrowAllowedTypeFirst(t, CacheException.class);
}
}
use of com.hazelcast.spi.impl.operationservice.OperationService 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.spi.impl.operationservice.OperationService in project hazelcast by hazelcast.
the class QueueEvictionProcessor method process.
@Override
public void process(EntryTaskScheduler<String, Void> scheduler, Collection<ScheduledEntry<String, Void>> entries) {
if (entries.isEmpty()) {
return;
}
IPartitionService partitionService = nodeEngine.getPartitionService();
OperationService operationService = nodeEngine.getOperationService();
for (ScheduledEntry<String, Void> entry : entries) {
String name = entry.getKey();
int partitionId = partitionService.getPartitionId(nodeEngine.toData(name));
Operation op = new CheckAndEvictOperation(entry.getKey()).setPartitionId(partitionId);
operationService.invokeOnPartition(op).joinInternal();
}
}
Aggregations