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