Search in sources :

Example 21 with OperationFactory

use of com.hazelcast.spi.impl.operationservice.OperationFactory in project hazelcast by hazelcast.

the class MapProxySupport method getAllInternal.

protected void getAllInternal(Set<K> keys, List<Data> dataKeys, List<Object> resultingKeyValuePairs) {
    if (keys == null || keys.isEmpty()) {
        return;
    }
    if (dataKeys.isEmpty()) {
        toDataCollectionWithNonNullKeyValidation(keys, dataKeys);
    }
    Collection<Integer> partitions = getPartitionsForKeys(dataKeys);
    Map<Integer, Object> responses;
    try {
        OperationFactory operationFactory = operationProvider.createGetAllOperationFactory(name, dataKeys);
        long startTimeNanos = Timer.nanos();
        responses = operationService.invokeOnPartitions(SERVICE_NAME, operationFactory, partitions);
        for (Object response : responses.values()) {
            MapEntries entries = toObject(response);
            for (int i = 0; i < entries.size(); i++) {
                resultingKeyValuePairs.add(entries.getKey(i));
                resultingKeyValuePairs.add(entries.getValue(i));
            }
        }
        localMapStats.incrementGetLatencyNanos(dataKeys.size(), Timer.nanosElapsed(startTimeNanos));
    } catch (Exception e) {
        throw rethrow(e);
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) MapEntries(com.hazelcast.map.impl.MapEntries) AbstractDistributedObject(com.hazelcast.spi.impl.AbstractDistributedObject) InitializingObject(com.hazelcast.spi.impl.InitializingObject) BinaryOperationFactory(com.hazelcast.spi.impl.operationservice.BinaryOperationFactory) IsPartitionLoadedOperationFactory(com.hazelcast.map.impl.operation.IsPartitionLoadedOperationFactory) OperationFactory(com.hazelcast.spi.impl.operationservice.OperationFactory) IsEmptyOperationFactory(com.hazelcast.map.impl.operation.IsEmptyOperationFactory)

Example 22 with OperationFactory

use of com.hazelcast.spi.impl.operationservice.OperationFactory in project hazelcast by hazelcast.

the class MapRemoveAllMessageTask method processMessage.

@Override
protected void processMessage() {
    if (!(predicate instanceof PartitionPredicate)) {
        super.processMessage();
        return;
    }
    int partitionId = clientMessage.getPartitionId();
    OperationFactory operationFactory = createOperationFactory();
    OperationServiceImpl operationService = nodeEngine.getOperationService();
    // We are running on a partition thread now and we are not allowed
    // to call invokeOnPartitions(Async) on operation service because of
    // that.
    Operation operation;
    if (operationFactory instanceof PartitionAwareOperationFactory) {
        // If operation factory is partition-aware, we should utilize this to our advantage
        // since for the on-heap storages this may speed up the operation via indexes
        // (see PartitionWideEntryWithPredicateOperationFactory.createFactoryOnRunner).
        PartitionAwareOperationFactory partitionAwareOperationFactory = (PartitionAwareOperationFactory) operationFactory;
        partitionAwareOperationFactory = partitionAwareOperationFactory.createFactoryOnRunner(nodeEngine, new int[] { partitionId });
        operation = partitionAwareOperationFactory.createPartitionOperation(partitionId);
    } else {
        operation = operationFactory.createOperation();
    }
    final int thisPartitionId = partitionId;
    operation.setCallerUuid(endpoint.getUuid());
    InvocationFuture<Object> future = operationService.invokeOnPartition(getServiceName(), operation, partitionId);
    future.whenCompleteAsync((response, throwable) -> {
        if (throwable == null) {
            sendResponse(reduce(Collections.singletonMap(thisPartitionId, response)));
        } else {
            handleProcessingFailure(throwable);
        }
    });
}
Also used : PartitionAwareOperationFactory(com.hazelcast.spi.impl.operationservice.impl.operations.PartitionAwareOperationFactory) PartitionPredicate(com.hazelcast.query.PartitionPredicate) Operation(com.hazelcast.spi.impl.operationservice.Operation) OperationServiceImpl(com.hazelcast.spi.impl.operationservice.impl.OperationServiceImpl) PartitionAwareOperationFactory(com.hazelcast.spi.impl.operationservice.impl.operations.PartitionAwareOperationFactory) OperationFactory(com.hazelcast.spi.impl.operationservice.OperationFactory)

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