Search in sources :

Example 76 with TransactionException

use of com.hazelcast.transaction.TransactionException in project hazelcast by hazelcast.

the class XATransactionProxy method commit.

void commit(boolean onePhase) {
    checkTimeout();
    try {
        if (onePhase && state != ACTIVE) {
            throw new TransactionException("Transaction is not active");
        }
        if (!onePhase && state != PREPARED) {
            throw new TransactionException("Transaction is not prepared");
        }
        state = COMMITTING;
        ClientMessage request = XATransactionCommitCodec.encodeRequest(txnId, onePhase);
        invoke(request);
        state = COMMITTED;
    } catch (Exception e) {
        state = COMMIT_FAILED;
        throw ExceptionUtil.rethrow(e);
    }
}
Also used : TransactionException(com.hazelcast.transaction.TransactionException) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage) TransactionException(com.hazelcast.transaction.TransactionException) TransactionNotActiveException(com.hazelcast.transaction.TransactionNotActiveException) XAException(javax.transaction.xa.XAException)

Example 77 with TransactionException

use of com.hazelcast.transaction.TransactionException in project hazelcast by hazelcast.

the class TransactionalQueueProxySupport method pollInternal.

public Data pollInternal(long timeout) {
    QueueItem reservedOffer = offeredQueue.peek();
    long itemId = reservedOffer == null ? -1 : reservedOffer.getItemId();
    TxnReservePollOperation operation = new TxnReservePollOperation(name, timeout, itemId, tx.getTxnId());
    operation.setCallerUuid(tx.getOwnerUuid());
    try {
        Future<QueueItem> f = invoke(operation);
        QueueItem item = f.get();
        if (item != null) {
            if (reservedOffer != null && item.getItemId() == reservedOffer.getItemId()) {
                offeredQueue.poll();
                removeFromRecord(reservedOffer.getItemId());
                itemIdSet.remove(reservedOffer.getItemId());
                return reservedOffer.getData();
            }
            //
            if (!itemIdSet.add(item.getItemId())) {
                throw new TransactionException("Duplicate itemId: " + item.getItemId());
            }
            TxnPollOperation txnPollOperation = new TxnPollOperation(name, item.getItemId());
            putToRecord(txnPollOperation);
            return item.getData();
        }
    } catch (Throwable t) {
        throw ExceptionUtil.rethrow(t);
    }
    return null;
}
Also used : TransactionException(com.hazelcast.transaction.TransactionException) TxnReservePollOperation(com.hazelcast.collection.impl.txnqueue.operations.TxnReservePollOperation) QueueItem(com.hazelcast.collection.impl.queue.QueueItem) TxnPollOperation(com.hazelcast.collection.impl.txnqueue.operations.TxnPollOperation)

Example 78 with TransactionException

use of com.hazelcast.transaction.TransactionException in project hazelcast by hazelcast.

the class AbstractTransactionalCollectionProxy method add.

public boolean add(E e) {
    checkTransactionActive();
    checkObjectNotNull(e);
    final NodeEngine nodeEngine = getNodeEngine();
    final Data value = nodeEngine.toData(e);
    CollectionReserveAddOperation operation = new CollectionReserveAddOperation(name, tx.getTxnId(), null);
    try {
        Future<Long> f = nodeEngine.getOperationService().invokeOnPartition(getServiceName(), operation, partitionId);
        Long itemId = f.get();
        if (itemId != null) {
            if (!itemIdSet.add(itemId)) {
                throw new TransactionException("Duplicate itemId: " + itemId);
            }
            getCollection().add(new CollectionItem(itemId, value));
            CollectionTxnAddOperation op = new CollectionTxnAddOperation(name, itemId, value);
            putToRecord(op);
            return true;
        }
    } catch (Throwable t) {
        throw ExceptionUtil.rethrow(t);
    }
    return false;
}
Also used : NodeEngine(com.hazelcast.spi.NodeEngine) TransactionException(com.hazelcast.transaction.TransactionException) CollectionTxnAddOperation(com.hazelcast.collection.impl.txncollection.operations.CollectionTxnAddOperation) CollectionReserveAddOperation(com.hazelcast.collection.impl.txncollection.operations.CollectionReserveAddOperation) Data(com.hazelcast.nio.serialization.Data) CollectionItem(com.hazelcast.collection.impl.collection.CollectionItem)

Example 79 with TransactionException

use of com.hazelcast.transaction.TransactionException in project hazelcast by hazelcast.

the class TxnLockAndGetOperation method run.

@Override
public void run() throws Exception {
    MultiMapContainer container = getOrCreateContainer();
    if (!container.txnLock(dataKey, getCallerUuid(), threadId, getCallId(), ttl, blockReads)) {
        throw new TransactionException("Transaction couldn't obtain lock!");
    }
    MultiMapValue multiMapValue = getMultiMapValueOrNull();
    boolean isLocal = executedLocally();
    Collection<MultiMapRecord> collection = multiMapValue == null ? null : multiMapValue.getCollection(isLocal);
    MultiMapResponse multiMapResponse = new MultiMapResponse(collection, getValueCollectionType(container));
    multiMapResponse.setNextRecordId(container.nextId());
    response = multiMapResponse;
}
Also used : MultiMapRecord(com.hazelcast.multimap.impl.MultiMapRecord) TransactionException(com.hazelcast.transaction.TransactionException) MultiMapValue(com.hazelcast.multimap.impl.MultiMapValue) MultiMapContainer(com.hazelcast.multimap.impl.MultiMapContainer) MultiMapResponse(com.hazelcast.multimap.impl.operations.MultiMapResponse)

Example 80 with TransactionException

use of com.hazelcast.transaction.TransactionException in project hazelcast by hazelcast.

the class TxnPrepareOperation method run.

@Override
public void run() throws Exception {
    MultiMapContainer container = getOrCreateContainer();
    if (!container.extendLock(dataKey, getCallerUuid(), threadId, LOCK_EXTENSION_TIME_IN_MILLIS)) {
        throw new TransactionException("Lock is not owned by the transaction! -> " + container.getLockOwnerInfo(dataKey));
    }
    response = true;
}
Also used : TransactionException(com.hazelcast.transaction.TransactionException) MultiMapContainer(com.hazelcast.multimap.impl.MultiMapContainer)

Aggregations

TransactionException (com.hazelcast.transaction.TransactionException)91 Test (org.junit.Test)74 HazelcastInstance (com.hazelcast.core.HazelcastInstance)68 QuickTest (com.hazelcast.test.annotation.QuickTest)66 ParallelTest (com.hazelcast.test.annotation.ParallelTest)62 TransactionalTaskContext (com.hazelcast.transaction.TransactionalTaskContext)62 TransactionalMap (com.hazelcast.core.TransactionalMap)60 NightlyTest (com.hazelcast.test.annotation.NightlyTest)51 Config (com.hazelcast.config.Config)39 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)39 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)35 MapStoreConfig (com.hazelcast.config.MapStoreConfig)32 IMap (com.hazelcast.core.IMap)18 TransactionContext (com.hazelcast.transaction.TransactionContext)14 HazelcastInstanceNotActiveException (com.hazelcast.core.HazelcastInstanceNotActiveException)7 ExpectedRuntimeException (com.hazelcast.test.ExpectedRuntimeException)7 TransactionOptions (com.hazelcast.transaction.TransactionOptions)7 Mockito.anyObject (org.mockito.Mockito.anyObject)7 TransactionNotActiveException (com.hazelcast.transaction.TransactionNotActiveException)6 MapStoreAdapter (com.hazelcast.core.MapStoreAdapter)5