Search in sources :

Example 16 with OperationFactory

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

the class CacheProxySupport method clearInternal.

protected void clearInternal() {
    try {
        OperationService operationService = getNodeEngine().getOperationService();
        OperationFactory operationFactory = operationProvider.createClearOperationFactory();
        Map<Integer, Object> results = operationService.invokeOnAllPartitions(getServiceName(), operationFactory);
        for (Object result : results.values()) {
            if (result != null && result instanceof CacheClearResponse) {
                Object response = ((CacheClearResponse) result).getResponse();
                if (response instanceof Throwable) {
                    throw (Throwable) response;
                }
            }
        }
    } catch (Throwable t) {
        throw rethrowAllowedTypeFirst(t, CacheException.class);
    }
}
Also used : CacheException(javax.cache.CacheException) AbstractDistributedObject(com.hazelcast.spi.impl.AbstractDistributedObject) OperationService(com.hazelcast.spi.impl.operationservice.OperationService) OperationFactory(com.hazelcast.spi.impl.operationservice.OperationFactory)

Example 17 with OperationFactory

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

the class AbstractAllPartitionsMessageTask method processInternal.

@Override
protected CompletableFuture<Map<Integer, Object>> processInternal() {
    OperationFactory operationFactory = new OperationFactoryWrapper(createOperationFactory(), endpoint.getUuid());
    OperationServiceImpl operationService = nodeEngine.getOperationService();
    return operationService.invokeOnAllPartitionsAsync(getServiceName(), operationFactory);
}
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 18 with OperationFactory

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

the class MapProxySupport method executeOnEntriesInternal.

/**
 * {@link IMap#executeOnEntries(EntryProcessor, Predicate)}
 */
public void executeOnEntriesInternal(EntryProcessor entryProcessor, Predicate predicate, List<Data> result) {
    try {
        Map<Integer, Object> results;
        if (predicate instanceof PartitionPredicate) {
            PartitionPredicate partitionPredicate = (PartitionPredicate) predicate;
            Data key = toData(partitionPredicate.getPartitionKey());
            int partitionId = partitionService.getPartitionId(key);
            handleHazelcastInstanceAwareParams(partitionPredicate.getTarget());
            OperationFactory operation = operationProvider.createPartitionWideEntryWithPredicateOperationFactory(name, entryProcessor, partitionPredicate.getTarget());
            results = operationService.invokeOnPartitions(SERVICE_NAME, operation, singletonList(partitionId));
        } else {
            OperationFactory operation = operationProvider.createPartitionWideEntryWithPredicateOperationFactory(name, entryProcessor, predicate);
            results = operationService.invokeOnAllPartitions(SERVICE_NAME, operation);
        }
        for (Object object : results.values()) {
            if (object != null) {
                MapEntries mapEntries = (MapEntries) object;
                for (int i = 0; i < mapEntries.size(); i++) {
                    result.add(mapEntries.getKey(i));
                    result.add(mapEntries.getValue(i));
                }
            }
        }
    } catch (Throwable t) {
        throw rethrow(t);
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) PartitionPredicate(com.hazelcast.query.PartitionPredicate) MapEntries(com.hazelcast.map.impl.MapEntries) AbstractDistributedObject(com.hazelcast.spi.impl.AbstractDistributedObject) InitializingObject(com.hazelcast.spi.impl.InitializingObject) Data(com.hazelcast.internal.serialization.Data) 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 19 with OperationFactory

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

the class MapProxySupport method containsValueInternal.

public boolean containsValueInternal(Data dataValue) {
    try {
        OperationFactory operationFactory = operationProvider.createContainsValueOperationFactory(name, dataValue);
        Map<Integer, Object> results = operationService.invokeOnAllPartitions(SERVICE_NAME, operationFactory);
        incrementOtherOperationsStat();
        for (Object result : results.values()) {
            Boolean contains = toObject(result);
            if (contains) {
                return true;
            }
        }
        return false;
    } catch (Throwable t) {
        throw rethrow(t);
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) 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 20 with OperationFactory

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

the class MapProxySupport method invokePutAllOperation.

@Nonnull
private InternalCompletableFuture<Void> invokePutAllOperation(Address address, List<Integer> memberPartitions, MapEntries[] entriesPerPartition, boolean triggerMapLoader) {
    int size = memberPartitions.size();
    int[] partitions = new int[size];
    int index = 0;
    for (Integer partitionId : memberPartitions) {
        if (entriesPerPartition[partitionId] != null) {
            partitions[index++] = partitionId;
        }
    }
    if (index == 0) {
        return newCompletedFuture(null);
    }
    // trim partition array to real size
    if (index < size) {
        partitions = Arrays.copyOf(partitions, index);
        size = index;
    }
    index = 0;
    MapEntries[] entries = new MapEntries[size];
    long totalSize = 0;
    for (int partitionId : partitions) {
        int batchSize = entriesPerPartition[partitionId].size();
        assert (putAllBatchSize == 0 || batchSize <= putAllBatchSize);
        entries[index++] = entriesPerPartition[partitionId];
        totalSize += batchSize;
        entriesPerPartition[partitionId] = null;
    }
    if (totalSize == 0) {
        return newCompletedFuture(null);
    }
    OperationFactory factory = operationProvider.createPutAllOperationFactory(name, partitions, entries, triggerMapLoader);
    long startTimeNanos = Timer.nanos();
    CompletableFuture<Map<Integer, Object>> future = operationService.invokeOnPartitionsAsync(SERVICE_NAME, factory, singletonMap(address, asIntegerList(partitions)));
    InternalCompletableFuture<Void> resultFuture = new InternalCompletableFuture<>();
    long finalTotalSize = totalSize;
    future.whenCompleteAsync((response, t) -> {
        putAllVisitSerializedKeys(entries);
        if (t == null) {
            localMapStats.incrementPutLatencyNanos(finalTotalSize, Timer.nanosElapsed(startTimeNanos));
            resultFuture.complete(null);
        } else {
            resultFuture.completeExceptionally(t);
        }
    }, CALLER_RUNS);
    return resultFuture;
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) MapEntries(com.hazelcast.map.impl.MapEntries) InternalCompletableFuture(com.hazelcast.spi.impl.InternalCompletableFuture) Map(java.util.Map) HashMap(java.util.HashMap) MapUtil.createHashMap(com.hazelcast.internal.util.MapUtil.createHashMap) Collections.singletonMap(java.util.Collections.singletonMap) IMap(com.hazelcast.map.IMap) 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) Nonnull(javax.annotation.Nonnull)

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