Search in sources :

Example 1 with OperationFactory

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

the class AbstractCacheProxy method size.

@Override
public int size() {
    ensureOpen();
    try {
        OperationFactory operationFactory = operationProvider.createSizeOperationFactory();
        Map<Integer, Object> results = getNodeEngine().getOperationService().invokeOnAllPartitions(getServiceName(), operationFactory);
        int total = 0;
        for (Object result : results.values()) {
            //noinspection RedundantCast
            total += (Integer) getNodeEngine().toObject(result);
        }
        return total;
    } catch (Throwable t) {
        throw rethrowAllowedTypeFirst(t, CacheException.class);
    }
}
Also used : CacheException(javax.cache.CacheException) OperationFactory(com.hazelcast.spi.OperationFactory)

Example 2 with OperationFactory

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

the class AbstractCacheProxy method getAll.

@Override
public Map<K, V> getAll(Set<? extends K> keys, ExpiryPolicy expiryPolicy) {
    ensureOpen();
    validateNotNull(keys);
    if (keys.isEmpty()) {
        return Collections.EMPTY_MAP;
    }
    Set<Data> ks = new HashSet<Data>(keys.size());
    for (K key : keys) {
        Data dataKey = serializationService.toData(key);
        ks.add(dataKey);
    }
    Map<K, V> result = new HashMap<K, V>();
    Collection<Integer> 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 : HashMap(java.util.HashMap) CacheException(javax.cache.CacheException) Data(com.hazelcast.nio.serialization.Data) MapEntries(com.hazelcast.map.impl.MapEntries) OperationService(com.hazelcast.spi.OperationService) HashSet(java.util.HashSet) OperationFactory(com.hazelcast.spi.OperationFactory)

Example 3 with OperationFactory

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

the class AbstractInternalCacheProxy method removeAllInternal.

void removeAllInternal(Set<? extends K> keys) {
    Set<Data> keysData = null;
    if (keys != null) {
        keysData = new HashSet<Data>();
        for (K key : keys) {
            keysData.add(serializationService.toData(key));
        }
    }
    int partitionCount = getNodeEngine().getPartitionService().getPartitionCount();
    Integer completionId = 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;
                }
            }
        }
        waitCompletionLatch(completionId, partitionCount - completionCount);
    } catch (Throwable t) {
        deregisterCompletionLatch(completionId);
        throw rethrowAllowedTypeFirst(t, CacheException.class);
    }
}
Also used : CacheException(javax.cache.CacheException) Data(com.hazelcast.nio.serialization.Data) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) OperationService(com.hazelcast.spi.OperationService) OperationFactory(com.hazelcast.spi.OperationFactory)

Example 4 with OperationFactory

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

the class AbstractMultiPartitionMessageTask method call.

@Override
protected Object call() throws Exception {
    ClientEndpoint endpoint = getEndpoint();
    OperationFactory operationFactory = new OperationFactoryWrapper(createOperationFactory(), endpoint.getUuid());
    final InternalOperationService operationService = nodeEngine.getOperationService();
    Map<Integer, Object> map = operationService.invokeOnPartitions(getServiceName(), operationFactory, getPartitions());
    return reduce(map);
}
Also used : OperationFactoryWrapper(com.hazelcast.client.impl.operations.OperationFactoryWrapper) InternalOperationService(com.hazelcast.spi.impl.operationservice.InternalOperationService) ClientEndpoint(com.hazelcast.client.ClientEndpoint) OperationFactory(com.hazelcast.spi.OperationFactory)

Example 5 with OperationFactory

use of com.hazelcast.spi.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.Operation) OperationFactory(com.hazelcast.spi.OperationFactory)

Aggregations

OperationFactory (com.hazelcast.spi.OperationFactory)18 IsEmptyOperationFactory (com.hazelcast.map.impl.operation.IsEmptyOperationFactory)7 IsPartitionLoadedOperationFactory (com.hazelcast.map.impl.operation.IsPartitionLoadedOperationFactory)7 BinaryOperationFactory (com.hazelcast.spi.impl.BinaryOperationFactory)7 AbstractDistributedObject (com.hazelcast.spi.AbstractDistributedObject)6 InitializingObject (com.hazelcast.spi.InitializingObject)6 MapEntries (com.hazelcast.map.impl.MapEntries)4 InternalOperationService (com.hazelcast.spi.impl.operationservice.InternalOperationService)4 CacheException (javax.cache.CacheException)4 Data (com.hazelcast.nio.serialization.Data)3 Operation (com.hazelcast.spi.Operation)3 OperationService (com.hazelcast.spi.OperationService)3 ClientEndpoint (com.hazelcast.client.ClientEndpoint)2 OperationFactoryWrapper (com.hazelcast.client.impl.operations.OperationFactoryWrapper)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 InternalSerializationService (com.hazelcast.internal.serialization.InternalSerializationService)1 MapService (com.hazelcast.map.impl.MapService)1 MapServiceContext (com.hazelcast.map.impl.MapServiceContext)1