Search in sources :

Example 96 with OperationService

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

the class AbstractInternalCacheProxy method clearInternal.

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 : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) CacheException(javax.cache.CacheException) OperationService(com.hazelcast.spi.OperationService) OperationFactory(com.hazelcast.spi.OperationFactory)

Example 97 with OperationService

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

the class ClusterWideIterator method fetch.

protected List fetch() {
    final OperationService operationService = cacheProxy.getNodeEngine().getOperationService();
    if (prefetchValues) {
        Operation operation = cacheProxy.operationProvider.createEntryIteratorOperation(lastTableIndex, fetchSize);
        final InternalCompletableFuture<CacheEntryIterationResult> f = operationService.invokeOnPartition(CacheService.SERVICE_NAME, operation, partitionIndex);
        CacheEntryIterationResult iteratorResult = f.join();
        if (iteratorResult != null) {
            setLastTableIndex(iteratorResult.getEntries(), iteratorResult.getTableIndex());
            return iteratorResult.getEntries();
        }
    } else {
        Operation operation = cacheProxy.operationProvider.createKeyIteratorOperation(lastTableIndex, fetchSize);
        final InternalCompletableFuture<CacheKeyIterationResult> f = operationService.invokeOnPartition(CacheService.SERVICE_NAME, operation, partitionIndex);
        CacheKeyIterationResult iteratorResult = f.join();
        if (iteratorResult != null) {
            setLastTableIndex(iteratorResult.getKeys(), iteratorResult.getTableIndex());
            return iteratorResult.getKeys();
        }
    }
    return null;
}
Also used : OperationService(com.hazelcast.spi.OperationService) Operation(com.hazelcast.spi.Operation)

Example 98 with OperationService

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

the class CacheProxy method containsKey.

@Override
public boolean containsKey(K key) {
    ensureOpen();
    validateNotNull(key);
    Data dataKey = serializationService.toData(key);
    Operation operation = operationProvider.createContainsKeyOperation(dataKey);
    OperationService operationService = getNodeEngine().getOperationService();
    int partitionId = getPartitionId(dataKey);
    InternalCompletableFuture<Boolean> future = operationService.invokeOnPartition(getServiceName(), operation, partitionId);
    return future.join();
}
Also used : Data(com.hazelcast.nio.serialization.Data) CacheListenerRegistrationOperation(com.hazelcast.cache.impl.operation.CacheListenerRegistrationOperation) Operation(com.hazelcast.spi.Operation) OperationService(com.hazelcast.spi.OperationService)

Example 99 with OperationService

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

the class CacheProxy method updateCacheListenerConfigOnOtherNodes.

private void updateCacheListenerConfigOnOtherNodes(CacheEntryListenerConfiguration<K, V> cacheEntryListenerConfiguration, boolean isRegister) {
    OperationService operationService = getNodeEngine().getOperationService();
    Collection<Member> members = getNodeEngine().getClusterService().getMembers();
    for (Member member : members) {
        if (!member.localMember()) {
            Operation op = new CacheListenerRegistrationOperation(getDistributedObjectName(), cacheEntryListenerConfiguration, isRegister);
            operationService.invokeOnTarget(CacheService.SERVICE_NAME, op, member.getAddress());
        }
    }
}
Also used : CacheListenerRegistrationOperation(com.hazelcast.cache.impl.operation.CacheListenerRegistrationOperation) OperationService(com.hazelcast.spi.OperationService) CacheListenerRegistrationOperation(com.hazelcast.cache.impl.operation.CacheListenerRegistrationOperation) Operation(com.hazelcast.spi.Operation) Member(com.hazelcast.core.Member)

Example 100 with OperationService

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

the class FinalizeJoinOperation method sendPostJoinOperations.

private void sendPostJoinOperations() {
    final ClusterServiceImpl clusterService = getService();
    final NodeEngineImpl nodeEngine = clusterService.getNodeEngine();
    // Post join operations must be lock free; means no locks at all;
    // no partition locks, no key-based locks, no service level locks!
    final Operation[] postJoinOperations = nodeEngine.getPostJoinOperations();
    final OperationService operationService = nodeEngine.getOperationService();
    if (postJoinOperations != null && postJoinOperations.length > 0) {
        final Collection<Member> members = clusterService.getMembers();
        for (Member member : members) {
            if (!member.localMember()) {
                PostJoinOperation operation = new PostJoinOperation(postJoinOperations);
                operationService.createInvocationBuilder(ClusterServiceImpl.SERVICE_NAME, operation, member.getAddress()).setTryCount(POST_JOIN_TRY_COUNT).invoke();
            }
        }
    }
}
Also used : NodeEngineImpl(com.hazelcast.spi.impl.NodeEngineImpl) ClusterServiceImpl(com.hazelcast.internal.cluster.impl.ClusterServiceImpl) Operation(com.hazelcast.spi.Operation) InternalOperationService(com.hazelcast.spi.impl.operationservice.InternalOperationService) OperationService(com.hazelcast.spi.OperationService) Member(com.hazelcast.core.Member)

Aggregations

OperationService (com.hazelcast.spi.OperationService)135 Test (org.junit.Test)49 QuickTest (com.hazelcast.test.annotation.QuickTest)48 ParallelTest (com.hazelcast.test.annotation.ParallelTest)46 HazelcastInstance (com.hazelcast.core.HazelcastInstance)45 Operation (com.hazelcast.spi.Operation)39 NodeEngine (com.hazelcast.spi.NodeEngine)30 Address (com.hazelcast.nio.Address)26 Future (java.util.concurrent.Future)26 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)24 Config (com.hazelcast.config.Config)21 InternalCompletableFuture (com.hazelcast.spi.InternalCompletableFuture)21 Member (com.hazelcast.core.Member)19 Data (com.hazelcast.nio.serialization.Data)14 ArrayList (java.util.ArrayList)11 Node (com.hazelcast.instance.Node)7 InternalOperationService (com.hazelcast.spi.impl.operationservice.InternalOperationService)7 ExecutionException (java.util.concurrent.ExecutionException)7 TimeoutException (java.util.concurrent.TimeoutException)7 OperationTimeoutException (com.hazelcast.core.OperationTimeoutException)6