Search in sources :

Example 11 with OperationFactory

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);
    }
}
Also used : CacheException(javax.cache.CacheException) Data(com.hazelcast.internal.serialization.Data) AbstractDistributedObject(com.hazelcast.spi.impl.AbstractDistributedObject) OperationService(com.hazelcast.spi.impl.operationservice.OperationService) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) OperationFactory(com.hazelcast.spi.impl.operationservice.OperationFactory)

Example 12 with OperationFactory

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));
            }
        }
    }
}
Also used : Address(com.hazelcast.cluster.Address) CacheException(javax.cache.CacheException) IPartitionService(com.hazelcast.internal.partition.IPartitionService) Data(com.hazelcast.internal.serialization.Data) CacheException(javax.cache.CacheException) PartitionIdSet(com.hazelcast.internal.util.collection.PartitionIdSet) List(java.util.List) OperationService(com.hazelcast.spi.impl.operationservice.OperationService) MapUtil.createHashMap(com.hazelcast.internal.util.MapUtil.createHashMap) Map(java.util.Map) OperationFactory(com.hazelcast.spi.impl.operationservice.OperationFactory)

Example 13 with OperationFactory

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());
}
Also used : OperationFactoryWrapper(com.hazelcast.client.impl.operations.OperationFactoryWrapper) OperationServiceImpl(com.hazelcast.spi.impl.operationservice.impl.OperationServiceImpl) OperationFactory(com.hazelcast.spi.impl.operationservice.OperationFactory)

Example 14 with OperationFactory

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();
}
Also used : MapProxyImpl(com.hazelcast.map.impl.proxy.MapProxyImpl) Operation(com.hazelcast.spi.impl.operationservice.Operation) MapService(com.hazelcast.map.impl.MapService) MapServiceContext(com.hazelcast.map.impl.MapServiceContext) OperationServiceImpl(com.hazelcast.spi.impl.operationservice.impl.OperationServiceImpl) OperationFactory(com.hazelcast.spi.impl.operationservice.OperationFactory)

Example 15 with OperationFactory

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());
    }
}
Also used : NodeEngineImpl(com.hazelcast.spi.impl.NodeEngineImpl) Accessors.getNodeEngineImpl(com.hazelcast.test.Accessors.getNodeEngineImpl) MultipleEntryWithPredicateOperation(com.hazelcast.map.impl.operation.MultipleEntryWithPredicateOperation) MapConfig(com.hazelcast.config.MapConfig) IndexConfig(com.hazelcast.config.IndexConfig) MapStoreConfig(com.hazelcast.config.MapStoreConfig) Config(com.hazelcast.config.Config) BinaryOperationFactory(com.hazelcast.spi.impl.operationservice.BinaryOperationFactory) Data(com.hazelcast.internal.serialization.Data) MultipleEntryWithPredicateOperation(com.hazelcast.map.impl.operation.MultipleEntryWithPredicateOperation) Operation(com.hazelcast.spi.impl.operationservice.Operation) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) HazelcastInstance(com.hazelcast.core.HazelcastInstance) EntryObject(com.hazelcast.query.PredicateBuilder.EntryObject) MapConfig(com.hazelcast.config.MapConfig) OperationServiceImpl(com.hazelcast.spi.impl.operationservice.impl.OperationServiceImpl) HashSet(java.util.HashSet) BinaryOperationFactory(com.hazelcast.spi.impl.operationservice.BinaryOperationFactory) OperationFactory(com.hazelcast.spi.impl.operationservice.OperationFactory) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

OperationFactory (com.hazelcast.spi.impl.operationservice.OperationFactory)22 BinaryOperationFactory (com.hazelcast.spi.impl.operationservice.BinaryOperationFactory)9 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)9 IsEmptyOperationFactory (com.hazelcast.map.impl.operation.IsEmptyOperationFactory)8 IsPartitionLoadedOperationFactory (com.hazelcast.map.impl.operation.IsPartitionLoadedOperationFactory)8 AbstractDistributedObject (com.hazelcast.spi.impl.AbstractDistributedObject)8 Data (com.hazelcast.internal.serialization.Data)6 MapEntries (com.hazelcast.map.impl.MapEntries)6 InitializingObject (com.hazelcast.spi.impl.InitializingObject)6 Operation (com.hazelcast.spi.impl.operationservice.Operation)5 OperationServiceImpl (com.hazelcast.spi.impl.operationservice.impl.OperationServiceImpl)5 CacheException (javax.cache.CacheException)5 OperationService (com.hazelcast.spi.impl.operationservice.OperationService)4 PartitionPredicate (com.hazelcast.query.PartitionPredicate)3 InternalCompletableFuture (com.hazelcast.spi.impl.InternalCompletableFuture)3 Map (java.util.Map)3 OperationFactoryWrapper (com.hazelcast.client.impl.operations.OperationFactoryWrapper)2 MapUtil.createHashMap (com.hazelcast.internal.util.MapUtil.createHashMap)2 PartitionIdSet (com.hazelcast.internal.util.collection.PartitionIdSet)2 Address (com.hazelcast.cluster.Address)1