Search in sources :

Example 56 with OperationService

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

the class CacheCreateConfigOperation method run.

@Override
public void run() throws Exception {
    ICacheService service = getService();
    if (!ignoreLocal) {
        response = service.putCacheConfigIfAbsent(config);
    }
    if (createAlsoOnOthers) {
        NodeEngine nodeEngine = getNodeEngine();
        Collection<Member> members = nodeEngine.getClusterService().getMembers();
        int remoteNodeCount = members.size() - 1;
        if (remoteNodeCount > 0) {
            postponeReturnResponse();
            ExecutionCallback<Object> callback = new CacheConfigCreateCallback(this, remoteNodeCount);
            OperationService operationService = nodeEngine.getOperationService();
            for (Member member : members) {
                if (!member.localMember()) {
                    CacheCreateConfigOperation op = new CacheCreateConfigOperation(config, false);
                    operationService.createInvocationBuilder(ICacheService.SERVICE_NAME, op, member.getAddress()).setExecutionCallback(callback).invoke();
                }
            }
        }
    }
}
Also used : NodeEngine(com.hazelcast.spi.NodeEngine) ICacheService(com.hazelcast.cache.impl.ICacheService) OperationService(com.hazelcast.spi.OperationService) Member(com.hazelcast.core.Member)

Example 57 with OperationService

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

the class CacheDestroyOperation method destroyCacheOnAllMembers.

private void destroyCacheOnAllMembers(String name, String callerUuid) {
    NodeEngine nodeEngine = getNodeEngine();
    OperationService operationService = nodeEngine.getOperationService();
    Collection<Member> members = nodeEngine.getClusterService().getMembers();
    for (Member member : members) {
        if (!member.localMember() && !member.getUuid().equals(callerUuid)) {
            CacheDestroyOperation op = new CacheDestroyOperation(name, true);
            operationService.invokeOnTarget(ICacheService.SERVICE_NAME, op, member.getAddress());
        }
    }
}
Also used : NodeEngine(com.hazelcast.spi.NodeEngine) OperationService(com.hazelcast.spi.OperationService) Member(com.hazelcast.core.Member)

Example 58 with OperationService

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

the class CollectionService method rollbackTransaction.

@Override
public void rollbackTransaction(String transactionId) {
    final Set<String> collectionNames = getContainerMap().keySet();
    IPartitionService partitionService = nodeEngine.getPartitionService();
    OperationService operationService = nodeEngine.getOperationService();
    for (String name : collectionNames) {
        int partitionId = partitionService.getPartitionId(StringPartitioningStrategy.getPartitionKey(name));
        Operation operation = new CollectionTransactionRollbackOperation(name, transactionId).setPartitionId(partitionId).setService(this).setNodeEngine(nodeEngine);
        operationService.execute(operation);
    }
}
Also used : CollectionTransactionRollbackOperation(com.hazelcast.collection.impl.txncollection.operations.CollectionTransactionRollbackOperation) IPartitionService(com.hazelcast.spi.partition.IPartitionService) OperationService(com.hazelcast.spi.OperationService) CollectionTransactionRollbackOperation(com.hazelcast.collection.impl.txncollection.operations.CollectionTransactionRollbackOperation) Operation(com.hazelcast.spi.Operation) MigrationEndpoint(com.hazelcast.spi.partition.MigrationEndpoint)

Example 59 with OperationService

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

the class DurableExecutorServiceProxy method shutdown.

@Override
public void shutdown() {
    NodeEngine nodeEngine = getNodeEngine();
    Collection<Member> members = nodeEngine.getClusterService().getMembers();
    OperationService operationService = nodeEngine.getOperationService();
    Collection<Future> calls = new LinkedList<Future>();
    for (Member member : members) {
        if (member.localMember()) {
            getService().shutdownExecutor(name);
        } else {
            ShutdownOperation op = new ShutdownOperation(name);
            Future f = operationService.invokeOnTarget(SERVICE_NAME, op, member.getAddress());
            calls.add(f);
        }
    }
    waitWithDeadline(calls, 1, TimeUnit.SECONDS, WHILE_SHUTDOWN_EXCEPTION_HANDLER);
}
Also used : NodeEngine(com.hazelcast.spi.NodeEngine) InternalCompletableFuture(com.hazelcast.spi.InternalCompletableFuture) DurableExecutorServiceFuture(com.hazelcast.durableexecutor.DurableExecutorServiceFuture) DelegatingFuture(com.hazelcast.util.executor.DelegatingFuture) Future(java.util.concurrent.Future) CompletedFuture(com.hazelcast.util.executor.CompletedFuture) ShutdownOperation(com.hazelcast.durableexecutor.impl.operations.ShutdownOperation) OperationService(com.hazelcast.spi.OperationService) Member(com.hazelcast.core.Member) LinkedList(java.util.LinkedList)

Example 60 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)

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