}
return false;
}
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());
try {
Future<QueueItem> f = invoke(operation);
QueueItem item = f.get();
if (item != null) {
if (reservedOffer != null && item.getItemId() == reservedOffer.getItemId()) {
offeredQueue.poll();
tx.removeTransactionLog(new TransactionLogKey(reservedOffer.getItemId(), name));
itemIdSet.remove(reservedOffer.getItemId());
return reservedOffer.getData();
}
//
if (!itemIdSet.add(item.getItemId())) {
throw new TransactionException("Duplicate itemId: " + item.getItemId());
}
TxnPollOperation op = new TxnPollOperation(name, item.getItemId());
QueueTransactionLog transactionLog
= new QueueTransactionLog(tx.getTxnId(), item.getItemId(), name, partitionId, op);
tx.addTransactionLog(transactionLog);
return item.getData();
}
} catch (Throwable t) {
throw ExceptionUtil.rethrow(t);
}
return null;