use of com.hazelcast.spi.impl.operationservice.OperationFactory 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.OperationFactory 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.OperationFactory in project hazelcast by hazelcast.
the class AbstractMultiPartitionMessageTask method processInternal.
@Override
protected CompletableFuture<Map<Integer, Object>> processInternal() {
OperationFactory operationFactory = new OperationFactoryWrapper(createOperationFactory(), endpoint.getUuid());
OperationServiceImpl operationService = nodeEngine.getOperationService();
return operationService.invokeOnPartitionsAsync(getServiceName(), operationFactory, getPartitions());
}
use of com.hazelcast.spi.impl.operationservice.OperationFactory in project hazelcast by hazelcast.
the class ContainsValueOperationTest method executeOperation.
private InternalCompletableFuture<Object> executeOperation(Map map, String key, int value) {
int partitionId = getNode(member1).getPartitionService().getPartitionId(key);
MapProxyImpl mapProxy = (MapProxyImpl) map;
MapServiceContext mapServiceContext = ((MapService) mapProxy.getService()).getMapServiceContext();
MapOperationProvider operationProvider = mapServiceContext.getMapOperationProvider(mapProxy.getName());
OperationFactory operationFactory = operationProvider.createContainsValueOperationFactory(mapProxy.getName(), mapServiceContext.toData(value));
Operation operation = operationFactory.createOperation();
OperationServiceImpl operationService = getOperationService(member1);
return operationService.createInvocationBuilder(MapService.SERVICE_NAME, operation, partitionId).invoke();
}
use of com.hazelcast.spi.impl.operationservice.OperationFactory in project hazelcast by hazelcast.
the class EntryProcessorTest method multiple_entry_with_predicate_operation_returns_empty_response_when_map_is_empty.
@Test
public void multiple_entry_with_predicate_operation_returns_empty_response_when_map_is_empty() throws Exception {
Config config = getConfig();
MapConfig mapConfig = config.getMapConfig(MAP_NAME);
mapConfig.setInMemoryFormat(inMemoryFormat);
HazelcastInstance node = createHazelcastInstance(config);
NodeEngineImpl nodeEngineImpl = getNodeEngineImpl(node);
OperationServiceImpl operationService = nodeEngineImpl.getOperationService();
int keyCount = 1000;
Set<Data> dataKeys = new HashSet<>();
for (int i = 0; i < keyCount; i++) {
dataKeys.add(nodeEngineImpl.toData(i));
}
Operation operation = new MultipleEntryWithPredicateOperation(MAP_NAME, dataKeys, new NoOpEntryProcessor<>(), Predicates.sql("this < " + keyCount));
OperationFactory operationFactory = new BinaryOperationFactory(operation, nodeEngineImpl);
Map<Integer, Object> partitionResponses = operationService.invokeOnAllPartitions(MapService.SERVICE_NAME, operationFactory);
for (Object response : partitionResponses.values()) {
assertEquals(0, ((MapEntries) response).size());
}
}
Aggregations