Search in sources :

Example 1 with QueueItem

use of com.hazelcast.collection.impl.queue.QueueItem in project hazelcast by hazelcast.

the class TransactionalQueueProxySupport method peekInternal.

public Data peekInternal(long timeout) {
    final QueueItem offer = offeredQueue.peek();
    long itemId = offer == null ? -1 : offer.getItemId();
    final TxnPeekOperation operation = new TxnPeekOperation(name, timeout, itemId, tx.getTxnId());
    try {
        final Future<QueueItem> f = invoke(operation);
        final QueueItem item = f.get();
        if (item != null) {
            if (offer != null && item.getItemId() == offer.getItemId()) {
                return offer.getData();
            }
            return item.getData();
        }
    } catch (Throwable t) {
        throw ExceptionUtil.rethrow(t);
    }
    return null;
}
Also used : TxnPeekOperation(com.hazelcast.collection.impl.txnqueue.operations.TxnPeekOperation) QueueItem(com.hazelcast.collection.impl.queue.QueueItem)

Example 2 with QueueItem

use of com.hazelcast.collection.impl.queue.QueueItem in project hazelcast by hazelcast.

the class TransactionalQueueProxySupport method offerInternal.

public boolean offerInternal(Data data, long timeout) {
    TxnReserveOfferOperation operation = new TxnReserveOfferOperation(name, timeout, offeredQueue.size(), tx.getTxnId());
    operation.setCallerUuid(tx.getOwnerUuid());
    try {
        Future<Long> f = invoke(operation);
        Long itemId = f.get();
        if (itemId != null) {
            if (!itemIdSet.add(itemId)) {
                throw new TransactionException("Duplicate itemId: " + itemId);
            }
            offeredQueue.offer(new QueueItem(null, itemId, data));
            TxnOfferOperation txnOfferOperation = new TxnOfferOperation(name, itemId, data);
            putToRecord(txnOfferOperation);
            return true;
        }
    } catch (Throwable t) {
        throw ExceptionUtil.rethrow(t);
    }
    return false;
}
Also used : TransactionException(com.hazelcast.transaction.TransactionException) TxnReserveOfferOperation(com.hazelcast.collection.impl.txnqueue.operations.TxnReserveOfferOperation) QueueItem(com.hazelcast.collection.impl.queue.QueueItem) TxnOfferOperation(com.hazelcast.collection.impl.txnqueue.operations.TxnOfferOperation)

Example 3 with QueueItem

use of com.hazelcast.collection.impl.queue.QueueItem in project hazelcast by hazelcast.

the class PeekOperation method run.

@Override
public void run() {
    QueueContainer queueContainer = getContainer();
    QueueItem item = queueContainer.peek();
    response = item != null ? item.getData() : null;
}
Also used : QueueContainer(com.hazelcast.collection.impl.queue.QueueContainer) QueueItem(com.hazelcast.collection.impl.queue.QueueItem)

Example 4 with QueueItem

use of com.hazelcast.collection.impl.queue.QueueItem 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 5 with QueueItem

use of com.hazelcast.collection.impl.queue.QueueItem in project hazelcast by hazelcast.

the class TxnReservePollOperation method getBackupOperation.

@Override
public Operation getBackupOperation() {
    final QueueItem item = (QueueItem) response;
    long itemId = item.getItemId();
    return new TxnReservePollBackupOperation(name, itemId, transactionId);
}
Also used : QueueItem(com.hazelcast.collection.impl.queue.QueueItem)

Aggregations

QueueItem (com.hazelcast.collection.impl.queue.QueueItem)5 TransactionException (com.hazelcast.transaction.TransactionException)2 QueueContainer (com.hazelcast.collection.impl.queue.QueueContainer)1 TxnOfferOperation (com.hazelcast.collection.impl.txnqueue.operations.TxnOfferOperation)1 TxnPeekOperation (com.hazelcast.collection.impl.txnqueue.operations.TxnPeekOperation)1 TxnPollOperation (com.hazelcast.collection.impl.txnqueue.operations.TxnPollOperation)1 TxnReserveOfferOperation (com.hazelcast.collection.impl.txnqueue.operations.TxnReserveOfferOperation)1 TxnReservePollOperation (com.hazelcast.collection.impl.txnqueue.operations.TxnReservePollOperation)1