Search in sources :

Example 6 with OperationFactory

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

the class MapProxySupport method size.

@Override
public int size() {
    try {
        OperationFactory sizeOperationFactory = operationProvider.createMapSizeOperationFactory(name);
        Map<Integer, Object> results = operationService.invokeOnAllPartitions(SERVICE_NAME, sizeOperationFactory);
        incrementOtherOperationsStat();
        long total = 0;
        for (Object result : results.values()) {
            Integer size = toObject(result);
            total += size;
        }
        return toIntSize(total);
    } 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 7 with OperationFactory

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

the class MapProxySupport method removeAllInternal.

protected void removeAllInternal(Predicate predicate) {
    try {
        if (predicate instanceof PartitionPredicate) {
            PartitionPredicate partitionPredicate = (PartitionPredicate) predicate;
            OperationFactory operation = operationProvider.createPartitionWideEntryWithPredicateOperationFactory(name, ENTRY_REMOVING_PROCESSOR, partitionPredicate.getTarget());
            Data partitionKey = toDataWithStrategy(partitionPredicate.getPartitionKey());
            int partitionId = partitionService.getPartitionId(partitionKey);
            // invokeOnPartitions is used intentionally here, instead of invokeOnPartition, since
            // the later one doesn't support PartitionAwareOperationFactory, which we need to use
            // to speed up the removal operation using global indexes
            // (see PartitionWideEntryWithPredicateOperationFactory.createFactoryOnRunner).
            operationService.invokeOnPartitions(SERVICE_NAME, operation, singletonList(partitionId));
        } else {
            OperationFactory operation = operationProvider.createPartitionWideEntryWithPredicateOperationFactory(name, ENTRY_REMOVING_PROCESSOR, predicate);
            operationService.invokeOnAllPartitions(SERVICE_NAME, operation);
        }
    } catch (Throwable t) {
        throw rethrow(t);
    }
}
Also used : PartitionPredicate(com.hazelcast.query.PartitionPredicate) 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 8 with OperationFactory

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

the class MultiMapProxySupport method invokePutAllOperation.

// NB: this method is generally copied from MapProxySupport#invokePutAllOperation
private InternalCompletableFuture<Void> invokePutAllOperation(Address address, List<Integer> memberPartitions, MapEntries[] entriesPerPartition) {
    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) {
        totalSize += entriesPerPartition[partitionId].size();
        entries[index++] = entriesPerPartition[partitionId];
        entriesPerPartition[partitionId] = null;
    }
    if (totalSize == 0) {
        return newCompletedFuture(null);
    }
    OperationFactory factory = new MultiMapPutAllOperationFactory(name, partitions, entries);
    long startTimeNanos = System.nanoTime();
    CompletableFuture<Map<Integer, Object>> future = operationService.invokeOnPartitionsAsync(MultiMapService.SERVICE_NAME, factory, singletonMap(address, asIntegerList(partitions)));
    InternalCompletableFuture<Void> resultFuture = new InternalCompletableFuture<>();
    long finalTotalSize = totalSize;
    future.whenCompleteAsync((response, t) -> {
        if (t == null) {
            getService().getLocalMultiMapStatsImpl(name).incrementPutLatencyNanos(finalTotalSize, System.nanoTime() - startTimeNanos);
            resultFuture.complete(null);
        } else {
            resultFuture.completeExceptionally(t);
        }
    }, CALLER_RUNS);
    return resultFuture;
}
Also used : InternalCompletableFuture(com.hazelcast.spi.impl.InternalCompletableFuture) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) MultiMapPutAllOperationFactory(com.hazelcast.multimap.impl.operations.MultiMapPutAllOperationFactory) MapEntries(com.hazelcast.map.impl.MapEntries) Map(java.util.Map) Collections.singletonMap(java.util.Collections.singletonMap) MultiMapOperationFactory(com.hazelcast.multimap.impl.operations.MultiMapOperationFactory) MultiMapPutAllOperationFactory(com.hazelcast.multimap.impl.operations.MultiMapPutAllOperationFactory) OperationFactory(com.hazelcast.spi.impl.operationservice.OperationFactory)

Example 9 with OperationFactory

use of com.hazelcast.spi.impl.operationservice.OperationFactory 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;
}
Also used : CacheException(javax.cache.CacheException) Data(com.hazelcast.internal.serialization.Data) PartitionIdSet(com.hazelcast.internal.util.collection.PartitionIdSet) MapEntries(com.hazelcast.map.impl.MapEntries) OperationService(com.hazelcast.spi.impl.operationservice.OperationService) OperationFactory(com.hazelcast.spi.impl.operationservice.OperationFactory)

Example 10 with OperationFactory

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

the class CacheProxy method size.

@Override
public int size() {
    ensureOpen();
    try {
        OperationFactory operationFactory = operationProvider.createSizeOperationFactory();
        Map<Integer, Object> results = getNodeEngine().getOperationService().invokeOnAllPartitions(getServiceName(), operationFactory);
        long total = 0;
        for (Object result : results.values()) {
            total += (Integer) getNodeEngine().toObject(result);
        }
        return toIntSize(total);
    } catch (Throwable t) {
        throw rethrowAllowedTypeFirst(t, CacheException.class);
    }
}
Also used : CacheException(javax.cache.CacheException) 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