Search in sources :

Example 1 with OperationService

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

the class AbstractTransactionalCollectionProxy method remove.

public boolean remove(E e) {
    checkTransactionActive();
    checkObjectNotNull(e);
    final NodeEngine nodeEngine = getNodeEngine();
    final Data value = nodeEngine.toData(e);
    final Iterator<CollectionItem> iterator = getCollection().iterator();
    long reservedItemId = -1;
    while (iterator.hasNext()) {
        final CollectionItem item = iterator.next();
        if (value.equals(item.getValue())) {
            reservedItemId = item.getItemId();
            break;
        }
    }
    final CollectionReserveRemoveOperation operation = new CollectionReserveRemoveOperation(name, reservedItemId, value, tx.getTxnId());
    try {
        final OperationService operationService = nodeEngine.getOperationService();
        Future<CollectionItem> f = operationService.invokeOnPartition(getServiceName(), operation, partitionId);
        CollectionItem item = f.get();
        if (item != null) {
            if (reservedItemId == item.getItemId()) {
                iterator.remove();
                removeFromRecord(reservedItemId);
                itemIdSet.remove(reservedItemId);
                return true;
            }
            if (!itemIdSet.add(item.getItemId())) {
                throw new TransactionException("Duplicate itemId: " + item.getItemId());
            }
            CollectionTxnRemoveOperation op = new CollectionTxnRemoveOperation(name, item.getItemId());
            putToRecord(op);
            return true;
        }
    } catch (Throwable t) {
        throw ExceptionUtil.rethrow(t);
    }
    return false;
}
Also used : NodeEngine(com.hazelcast.spi.NodeEngine) CollectionReserveRemoveOperation(com.hazelcast.collection.impl.txncollection.operations.CollectionReserveRemoveOperation) TransactionException(com.hazelcast.transaction.TransactionException) CollectionTxnRemoveOperation(com.hazelcast.collection.impl.txncollection.operations.CollectionTxnRemoveOperation) Data(com.hazelcast.nio.serialization.Data) CollectionItem(com.hazelcast.collection.impl.collection.CollectionItem) OperationService(com.hazelcast.spi.OperationService)

Example 2 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 3 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 4 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 5 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)

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