Search in sources :

Example 61 with OperationService

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

the class QueueProxySupport method invokeAndGetData.

private Object invokeAndGetData(QueueOperation operation) {
    final NodeEngine nodeEngine = getNodeEngine();
    try {
        OperationService operationService = nodeEngine.getOperationService();
        Future f = operationService.invokeOnPartition(QueueService.SERVICE_NAME, operation, partitionId);
        return f.get();
    } catch (Throwable throwable) {
        throw ExceptionUtil.rethrow(throwable);
    }
}
Also used : NodeEngine(com.hazelcast.spi.NodeEngine) InternalCompletableFuture(com.hazelcast.spi.InternalCompletableFuture) Future(java.util.concurrent.Future) OperationService(com.hazelcast.spi.OperationService)

Example 62 with OperationService

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

the class QueueProxySupport method invoke.

private InternalCompletableFuture invoke(Operation operation) {
    final NodeEngine nodeEngine = getNodeEngine();
    OperationService operationService = nodeEngine.getOperationService();
    return operationService.invokeOnPartition(QueueService.SERVICE_NAME, operation, getPartitionId());
}
Also used : NodeEngine(com.hazelcast.spi.NodeEngine) OperationService(com.hazelcast.spi.OperationService)

Example 63 with OperationService

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

the class ConnectedClientOperationTest method testGetConnectedClientsOperation_WhenMoreThanZeroClientConnects.

@Test
public void testGetConnectedClientsOperation_WhenMoreThanZeroClientConnects() throws Exception {
    HazelcastInstance instance = factory.newHazelcastInstance();
    factory.newHazelcastClient();
    factory.newHazelcastClient();
    Node node = TestUtil.getNode(instance);
    Operation operation = new GetConnectedClientsOperation();
    OperationService operationService = node.nodeEngine.getOperationService();
    Future<Map<String, ClientType>> future = operationService.invokeOnTarget(ClientEngineImpl.SERVICE_NAME, operation, node.address);
    Map<String, ClientType> clients = future.get();
    assertEquals(2, clients.size());
}
Also used : ClientType(com.hazelcast.core.ClientType) HazelcastInstance(com.hazelcast.core.HazelcastInstance) Node(com.hazelcast.instance.Node) Operation(com.hazelcast.spi.Operation) GetConnectedClientsOperation(com.hazelcast.client.impl.operations.GetConnectedClientsOperation) GetConnectedClientsOperation(com.hazelcast.client.impl.operations.GetConnectedClientsOperation) OperationService(com.hazelcast.spi.OperationService) Map(java.util.Map) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 64 with OperationService

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

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

the class CacheProxy method invoke.

@Override
public <T> T invoke(K key, EntryProcessor<K, V, T> entryProcessor, Object... arguments) throws EntryProcessorException {
    ensureOpen();
    validateNotNull(key);
    checkNotNull(entryProcessor, "Entry Processor is null");
    Data keyData = serializationService.toData(key);
    Integer completionId = registerCompletionLatch(1);
    Operation op = operationProvider.createEntryProcessorOperation(keyData, completionId, entryProcessor, arguments);
    try {
        OperationService operationService = getNodeEngine().getOperationService();
        int partitionId = getPartitionId(keyData);
        InternalCompletableFuture<T> future = operationService.invokeOnPartition(getServiceName(), op, partitionId);
        T safely = future.join();
        waitCompletionLatch(completionId);
        return safely;
    } catch (CacheException ce) {
        deregisterCompletionLatch(completionId);
        throw ce;
    } catch (Exception e) {
        deregisterCompletionLatch(completionId);
        throw new EntryProcessorException(e);
    }
}
Also used : EntryProcessorException(javax.cache.processor.EntryProcessorException) CacheException(javax.cache.CacheException) Data(com.hazelcast.nio.serialization.Data) CacheListenerRegistrationOperation(com.hazelcast.cache.impl.operation.CacheListenerRegistrationOperation) Operation(com.hazelcast.spi.Operation) OperationService(com.hazelcast.spi.OperationService) EntryProcessorException(javax.cache.processor.EntryProcessorException) CacheException(javax.cache.CacheException)

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