Search in sources :

Example 76 with Operation

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

the class TransactionManagerServiceImpl method finalize.

private boolean finalize(String uuid, String txnId, TxBackupLog log) {
    OperationService operationService = nodeEngine.getOperationService();
    if (!uuid.equals(log.callerUuid)) {
        return false;
    }
    if (log.state == ACTIVE) {
        if (logger.isFinestEnabled()) {
            logger.finest("Rolling-back transaction[id:" + txnId + ", state:ACTIVE] of endpoint " + uuid);
        }
        Collection<Member> memberList = nodeEngine.getClusterService().getMembers();
        Collection<Future> futures = new ArrayList<Future>(memberList.size());
        for (Member member : memberList) {
            Operation op = new BroadcastTxRollbackOperation(txnId);
            Future f = operationService.invokeOnTarget(SERVICE_NAME, op, member.getAddress());
            futures.add(f);
        }
        long timeoutMillis = TransactionOptions.getDefault().getTimeoutMillis();
        waitWithDeadline(futures, timeoutMillis, TimeUnit.MILLISECONDS, finalizeExceptionHandler);
    } else {
        TransactionImpl tx;
        if (log.allowedDuringPassiveState) {
            tx = new AllowedDuringPassiveStateTransactionImpl(this, nodeEngine, txnId, log.records, log.timeoutMillis, log.startTime, log.callerUuid);
        } else {
            tx = new TransactionImpl(this, nodeEngine, txnId, log.records, log.timeoutMillis, log.startTime, log.callerUuid);
        }
        if (log.state == COMMITTING) {
            if (logger.isFinestEnabled()) {
                logger.finest("Committing transaction[id:" + txnId + ", state:COMMITTING] of endpoint " + uuid);
            }
            try {
                tx.commit();
            } catch (Throwable e) {
                logger.warning("Error during committing from tx backup!", e);
            }
        } else {
            if (logger.isFinestEnabled()) {
                logger.finest("Rolling-back transaction[id:" + txnId + ", state:" + log.state + "] of endpoint " + uuid);
            }
            try {
                tx.rollback();
            } catch (Throwable e) {
                logger.warning("Error during rolling-back from tx backup!", e);
            }
        }
    }
    return true;
}
Also used : ArrayList(java.util.ArrayList) Future(java.util.concurrent.Future) OperationService(com.hazelcast.spi.OperationService) BroadcastTxRollbackOperation(com.hazelcast.transaction.impl.operations.BroadcastTxRollbackOperation) Operation(com.hazelcast.spi.Operation) Member(com.hazelcast.core.Member) BroadcastTxRollbackOperation(com.hazelcast.transaction.impl.operations.BroadcastTxRollbackOperation)

Example 77 with Operation

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

the class InvokeOnPartitions method retryFailedPartitions.

private void retryFailedPartitions() throws InterruptedException, ExecutionException {
    List<Integer> failedPartitions = new LinkedList<Integer>();
    for (Map.Entry<Integer, Object> partitionResult : partitionResults.entrySet()) {
        int partitionId = partitionResult.getKey();
        Object result = partitionResult.getValue();
        if (result instanceof Throwable) {
            failedPartitions.add(partitionId);
        }
    }
    for (Integer failedPartition : failedPartitions) {
        Operation operation;
        PartitionAwareOperationFactory partitionAwareFactory = extractPartitionAware(operationFactory);
        if (partitionAwareFactory != null) {
            operation = partitionAwareFactory.createPartitionOperation(failedPartition);
        } else {
            operation = operationFactory.createOperation();
        }
        Future future = operationService.createInvocationBuilder(serviceName, operation, failedPartition).invoke();
        partitionResults.put(failedPartition, future);
    }
    for (Integer failedPartition : failedPartitions) {
        Future future = (Future) partitionResults.get(failedPartition);
        Object result = future.get();
        partitionResults.put(failedPartition, result);
    }
}
Also used : PartitionAwareOperationFactory(com.hazelcast.spi.impl.operationservice.impl.operations.PartitionAwareOperationFactory) Future(java.util.concurrent.Future) Operation(com.hazelcast.spi.Operation) PartitionIteratingOperation(com.hazelcast.spi.impl.operationservice.impl.operations.PartitionIteratingOperation) HashMap(java.util.HashMap) Map(java.util.Map) LinkedList(java.util.LinkedList)

Example 78 with Operation

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

the class LockProxySupport method getLockCount.

public int getLockCount(NodeEngine nodeEngine, Data key) {
    Operation operation = new GetLockCountOperation(namespace, key);
    InternalCompletableFuture<Number> f = invoke(nodeEngine, operation, key);
    return f.join().intValue();
}
Also used : GetLockCountOperation(com.hazelcast.concurrent.lock.operations.GetLockCountOperation) UnlockOperation(com.hazelcast.concurrent.lock.operations.UnlockOperation) Operation(com.hazelcast.spi.Operation) LockOperation(com.hazelcast.concurrent.lock.operations.LockOperation) IsLockedOperation(com.hazelcast.concurrent.lock.operations.IsLockedOperation) GetLockCountOperation(com.hazelcast.concurrent.lock.operations.GetLockCountOperation) GetRemainingLeaseTimeOperation(com.hazelcast.concurrent.lock.operations.GetRemainingLeaseTimeOperation)

Example 79 with Operation

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

the class LockProxySupport method getRemainingLeaseTime.

public long getRemainingLeaseTime(NodeEngine nodeEngine, Data key) {
    Operation operation = new GetRemainingLeaseTimeOperation(namespace, key);
    InternalCompletableFuture<Number> f = invoke(nodeEngine, operation, key);
    return f.join().longValue();
}
Also used : UnlockOperation(com.hazelcast.concurrent.lock.operations.UnlockOperation) Operation(com.hazelcast.spi.Operation) LockOperation(com.hazelcast.concurrent.lock.operations.LockOperation) IsLockedOperation(com.hazelcast.concurrent.lock.operations.IsLockedOperation) GetLockCountOperation(com.hazelcast.concurrent.lock.operations.GetLockCountOperation) GetRemainingLeaseTimeOperation(com.hazelcast.concurrent.lock.operations.GetRemainingLeaseTimeOperation) GetRemainingLeaseTimeOperation(com.hazelcast.concurrent.lock.operations.GetRemainingLeaseTimeOperation)

Example 80 with Operation

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

the class CountDownLatchProxy method getCount.

@Override
public int getCount() {
    Operation op = new GetCountOperation(name).setPartitionId(partitionId);
    InternalCompletableFuture<Integer> f = invokeOnPartition(op);
    return f.join();
}
Also used : GetCountOperation(com.hazelcast.concurrent.countdownlatch.operations.GetCountOperation) CountDownOperation(com.hazelcast.concurrent.countdownlatch.operations.CountDownOperation) Operation(com.hazelcast.spi.Operation) GetCountOperation(com.hazelcast.concurrent.countdownlatch.operations.GetCountOperation) AwaitOperation(com.hazelcast.concurrent.countdownlatch.operations.AwaitOperation) SetCountOperation(com.hazelcast.concurrent.countdownlatch.operations.SetCountOperation)

Aggregations

Operation (com.hazelcast.spi.Operation)94 OperationService (com.hazelcast.spi.OperationService)14 Member (com.hazelcast.core.Member)13 Address (com.hazelcast.nio.Address)11 InternalCompletableFuture (com.hazelcast.spi.InternalCompletableFuture)8 ArrayList (java.util.ArrayList)8 ILogger (com.hazelcast.logging.ILogger)7 UrgentSystemOperation (com.hazelcast.spi.UrgentSystemOperation)7 ParallelTest (com.hazelcast.test.annotation.ParallelTest)7 QuickTest (com.hazelcast.test.annotation.QuickTest)7 Test (org.junit.Test)7 AcquireOperation (com.hazelcast.concurrent.semaphore.operations.AcquireOperation)6 AvailableOperation (com.hazelcast.concurrent.semaphore.operations.AvailableOperation)6 DrainOperation (com.hazelcast.concurrent.semaphore.operations.DrainOperation)6 InitOperation (com.hazelcast.concurrent.semaphore.operations.InitOperation)6 ReduceOperation (com.hazelcast.concurrent.semaphore.operations.ReduceOperation)6 ReleaseOperation (com.hazelcast.concurrent.semaphore.operations.ReleaseOperation)6 MemberInfo (com.hazelcast.internal.cluster.MemberInfo)6 NodeEngine (com.hazelcast.spi.NodeEngine)6 NodeEngineImpl (com.hazelcast.spi.impl.NodeEngineImpl)6