Search in sources :

Example 1 with OperationFactory

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

the class NodeInvokerWrapper method invokeOnAllPartitions.

@Override
public Map<Integer, Object> invokeOnAllPartitions(Object request, boolean urgent) throws Exception {
    checkInstanceOf(OperationFactory.class, request, "request");
    OperationFactory factory = (OperationFactory) request;
    return operationService.invokeOnAllPartitions(MapService.SERVICE_NAME, factory);
}
Also used : OperationFactory(com.hazelcast.spi.impl.operationservice.OperationFactory)

Example 2 with OperationFactory

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

the class TransactionalMapProxySupport method sizeInternal.

int sizeInternal() {
    try {
        OperationFactory sizeOperationFactory = operationProvider.createMapSizeOperationFactory(name);
        Map<Integer, Object> results = operationService.invokeOnAllPartitions(SERVICE_NAME, sizeOperationFactory);
        int total = 0;
        for (Object result : results.values()) {
            Integer size = getNodeEngine().toObject(result);
            total += size;
        }
        return total;
    } catch (Throwable t) {
        throw rethrow(t);
    }
}
Also used : TransactionalDistributedObject(com.hazelcast.spi.impl.TransactionalDistributedObject) OperationFactory(com.hazelcast.spi.impl.operationservice.OperationFactory)

Example 3 with OperationFactory

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

the class OperationDescriptors method toOperationDesc.

public static String toOperationDesc(Operation op) {
    Class<? extends Operation> operationClass = op.getClass();
    if (PartitionIteratingOperation.class.isAssignableFrom(operationClass)) {
        PartitionIteratingOperation partitionIteratingOperation = (PartitionIteratingOperation) op;
        OperationFactory operationFactory = partitionIteratingOperation.getOperationFactory();
        String desc = DESCRIPTORS.get(operationFactory.getClass().getName());
        if (desc == null) {
            desc = PartitionIteratingOperation.class.getSimpleName() + "(" + operationFactory.getClass().getName() + ")";
            DESCRIPTORS.put(operationFactory.getClass().getName(), desc);
        }
        return desc;
    } else if (Backup.class.isAssignableFrom(operationClass)) {
        Backup backup = (Backup) op;
        Operation backupOperation = backup.getBackupOp();
        String desc = DESCRIPTORS.get(backupOperation.getClass().getName());
        if (desc == null) {
            desc = Backup.class.getSimpleName() + "(" + backup.getBackupOp().getClass().getName() + ")";
            DESCRIPTORS.put(backupOperation.getClass().getName(), desc);
        }
        return desc;
    } else {
        return operationClass.getName();
    }
}
Also used : PartitionIteratingOperation(com.hazelcast.spi.impl.operationservice.impl.operations.PartitionIteratingOperation) Backup(com.hazelcast.spi.impl.operationservice.impl.operations.Backup) PartitionIteratingOperation(com.hazelcast.spi.impl.operationservice.impl.operations.PartitionIteratingOperation) Operation(com.hazelcast.spi.impl.operationservice.Operation) OperationFactory(com.hazelcast.spi.impl.operationservice.OperationFactory)

Example 4 with OperationFactory

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

the class MapProxySupport method submitToKeysInternal.

public <R> InternalCompletableFuture<Map<K, R>> submitToKeysInternal(Set<K> keys, Set<Data> dataKeys, EntryProcessor<K, V, R> entryProcessor) {
    if (dataKeys.isEmpty()) {
        toDataCollectionWithNonNullKeyValidation(keys, dataKeys);
    }
    Collection<Integer> partitionsForKeys = getPartitionsForKeys(dataKeys);
    OperationFactory operationFactory = operationProvider.createMultipleEntryOperationFactory(name, dataKeys, entryProcessor);
    final InternalCompletableFuture resultFuture = new InternalCompletableFuture();
    operationService.invokeOnPartitionsAsync(SERVICE_NAME, operationFactory, partitionsForKeys).whenCompleteAsync((response, throwable) -> {
        if (throwable == null) {
            Map<K, Object> result = null;
            try {
                result = createHashMap(response.size());
                for (Object object : response.values()) {
                    MapEntries mapEntries = (MapEntries) object;
                    mapEntries.putAllToMap(serializationService, result);
                }
            } catch (Throwable e) {
                resultFuture.completeExceptionally(e);
            }
            resultFuture.complete(result);
        } else {
            resultFuture.completeExceptionally(throwable);
        }
    });
    return resultFuture;
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) InternalCompletableFuture(com.hazelcast.spi.impl.InternalCompletableFuture) 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 5 with OperationFactory

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

the class MapProxySupport method waitUntilLoaded.

public void waitUntilLoaded() {
    try {
        int mapNamesPartitionId = partitionService.getPartitionId(name);
        // first we have to check if key-load finished - otherwise
        // the loading on other partitions might not have started.
        // In this case we can't invoke IsPartitionLoadedOperation
        // -> they will return "true", but it won't be correct
        int sleepDurationMillis = INITIAL_WAIT_LOAD_SLEEP_MILLIS;
        while (true) {
            Operation op = new IsKeyLoadFinishedOperation(name);
            Future<Boolean> loadingFuture = operationService.invokeOnPartition(SERVICE_NAME, op, mapNamesPartitionId);
            if (loadingFuture.get()) {
                break;
            }
            // sleep with some back-off
            TimeUnit.MILLISECONDS.sleep(sleepDurationMillis);
            sleepDurationMillis = (sleepDurationMillis * 2 < MAXIMAL_WAIT_LOAD_SLEEP_MILLIS) ? sleepDurationMillis * 2 : MAXIMAL_WAIT_LOAD_SLEEP_MILLIS;
        }
        OperationFactory opFactory = new IsPartitionLoadedOperationFactory(name);
        Map<Integer, Object> results = operationService.invokeOnAllPartitions(SERVICE_NAME, opFactory);
        // wait for all the data to be loaded on all partitions - wait forever
        waitAllTrue(results, opFactory);
    } catch (Throwable t) {
        throw rethrow(t);
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) IsKeyLoadFinishedOperation(com.hazelcast.map.impl.operation.IsKeyLoadFinishedOperation) IsPartitionLoadedOperationFactory(com.hazelcast.map.impl.operation.IsPartitionLoadedOperationFactory) AbstractDistributedObject(com.hazelcast.spi.impl.AbstractDistributedObject) InitializingObject(com.hazelcast.spi.impl.InitializingObject) AddIndexOperation(com.hazelcast.map.impl.operation.AddIndexOperation) AwaitMapFlushOperation(com.hazelcast.map.impl.operation.AwaitMapFlushOperation) IsKeyLoadFinishedOperation(com.hazelcast.map.impl.operation.IsKeyLoadFinishedOperation) Operation(com.hazelcast.spi.impl.operationservice.Operation) MapOperation(com.hazelcast.map.impl.operation.MapOperation) 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)

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