Search in sources :

Example 71 with OperationService

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

the class CheckReplicaVersionOperation method requestDataFromOwner.

private void requestDataFromOwner(String name) {
    OperationService operationService = getNodeEngine().getOperationService();
    Operation op = new RequestMapDataOperation(name);
    operationService.createInvocationBuilder(SERVICE_NAME, op, getPartitionId()).setTryCount(INVOCATION_TRY_COUNT).invoke();
}
Also used : OperationService(com.hazelcast.spi.impl.operationservice.OperationService) PartitionAwareOperation(com.hazelcast.spi.impl.operationservice.PartitionAwareOperation) Operation(com.hazelcast.spi.impl.operationservice.Operation)

Example 72 with OperationService

use of com.hazelcast.spi.impl.operationservice.OperationService 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 73 with OperationService

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

the class CacheProxySupport method removeAllInternal.

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

Example 74 with OperationService

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

the class CacheProxyLoadAllTask method run.

@Override
public void run() {
    try {
        completionListener = injectDependencies(completionListener);
        OperationService operationService = nodeEngine.getOperationService();
        OperationFactory operationFactory;
        IPartitionService partitionService = nodeEngine.getPartitionService();
        Map<Address, List<Integer>> memberPartitionsMap = partitionService.getMemberPartitionsMap();
        int partitionCount = partitionService.getPartitionCount();
        Map<Integer, Object> results = createHashMap(partitionCount);
        for (Map.Entry<Address, List<Integer>> memberPartitions : memberPartitionsMap.entrySet()) {
            Set<Integer> partitions = new PartitionIdSet(partitionCount, memberPartitions.getValue());
            Set<Data> ownerKeys = filterOwnerKeys(partitionService, partitions);
            operationFactory = operationProvider.createLoadAllOperationFactory(ownerKeys, replaceExistingValues);
            Map<Integer, Object> memberResults;
            memberResults = operationService.invokeOnPartitions(serviceName, operationFactory, partitions);
            results.putAll(memberResults);
        }
        validateResults(results);
        if (completionListener != null) {
            completionListener.onCompletion();
        }
    } catch (Exception e) {
        if (completionListener != null) {
            completionListener.onException(e);
        }
    } catch (Throwable t) {
        if (t instanceof OutOfMemoryError) {
            throw rethrow(t);
        } else {
            if (completionListener != null) {
                completionListener.onException(new CacheException(t));
            }
        }
    }
}
Also used : Address(com.hazelcast.cluster.Address) CacheException(javax.cache.CacheException) IPartitionService(com.hazelcast.internal.partition.IPartitionService) Data(com.hazelcast.internal.serialization.Data) CacheException(javax.cache.CacheException) PartitionIdSet(com.hazelcast.internal.util.collection.PartitionIdSet) List(java.util.List) OperationService(com.hazelcast.spi.impl.operationservice.OperationService) MapUtil.createHashMap(com.hazelcast.internal.util.MapUtil.createHashMap) Map(java.util.Map) OperationFactory(com.hazelcast.spi.impl.operationservice.OperationFactory)

Example 75 with OperationService

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

the class QueueEvictionProcessor method process.

@Override
public void process(EntryTaskScheduler<String, Void> scheduler, Collection<ScheduledEntry<String, Void>> entries) {
    if (entries.isEmpty()) {
        return;
    }
    IPartitionService partitionService = nodeEngine.getPartitionService();
    OperationService operationService = nodeEngine.getOperationService();
    for (ScheduledEntry<String, Void> entry : entries) {
        String name = entry.getKey();
        int partitionId = partitionService.getPartitionId(nodeEngine.toData(name));
        Operation op = new CheckAndEvictOperation(entry.getKey()).setPartitionId(partitionId);
        operationService.invokeOnPartition(op).joinInternal();
    }
}
Also used : CheckAndEvictOperation(com.hazelcast.collection.impl.queue.operations.CheckAndEvictOperation) IPartitionService(com.hazelcast.internal.partition.IPartitionService) OperationService(com.hazelcast.spi.impl.operationservice.OperationService) Operation(com.hazelcast.spi.impl.operationservice.Operation) CheckAndEvictOperation(com.hazelcast.collection.impl.queue.operations.CheckAndEvictOperation)

Aggregations

OperationService (com.hazelcast.spi.impl.operationservice.OperationService)140 Operation (com.hazelcast.spi.impl.operationservice.Operation)55 Test (org.junit.Test)54 HazelcastInstance (com.hazelcast.core.HazelcastInstance)46 QuickTest (com.hazelcast.test.annotation.QuickTest)41 Accessors.getOperationService (com.hazelcast.test.Accessors.getOperationService)40 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)40 Address (com.hazelcast.cluster.Address)31 NodeEngine (com.hazelcast.spi.impl.NodeEngine)31 InternalCompletableFuture (com.hazelcast.spi.impl.InternalCompletableFuture)24 Future (java.util.concurrent.Future)24 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)23 Config (com.hazelcast.config.Config)22 Member (com.hazelcast.cluster.Member)21 Data (com.hazelcast.internal.serialization.Data)12 SlowTest (com.hazelcast.test.annotation.SlowTest)12 ClusterService (com.hazelcast.internal.cluster.ClusterService)9 ILogger (com.hazelcast.logging.ILogger)7 ArrayList (java.util.ArrayList)7 IPartitionService (com.hazelcast.internal.partition.IPartitionService)6