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);
}
}
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;
}
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;
}
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;
}
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;
}
Aggregations