use of com.hazelcast.collection.impl.txnqueue.TxQueueItem in project hazelcast by hazelcast.
the class QueueContainer method txnPeek.
/**
* Retrieves, but does not remove, the head of the queue. If the queue is empty checks if there is a reserved item with
* the associated {@code offerId} and returns it.
* If the item was retrieved from the queue but does not contain any data and the queue store is enabled, this method will
* try load the data from the data store.
*
* @param offerId the ID of the reserved item to be returned if the queue is empty
* @param transactionId currently ignored
* @return the head of the queue or a reserved item associated with the {@code offerId} if the queue is empty
* @throws HazelcastException if there is an exception while loading the data from the queue store
*/
public QueueItem txnPeek(long offerId, String transactionId) {
QueueItem item = getItemQueue().peek();
if (item == null) {
if (offerId == -1) {
return null;
}
TxQueueItem txItem = txMap.get(offerId);
if (txItem == null) {
return null;
}
item = new QueueItem(this, txItem.getItemId(), txItem.getData());
return item;
}
if (store.isEnabled() && item.getData() == null) {
try {
load(item);
} catch (Exception e) {
throw new HazelcastException(e);
}
}
return item;
}
use of com.hazelcast.collection.impl.txnqueue.TxQueueItem in project hazelcast by hazelcast.
the class QueueContainer method txnOfferReserve.
//TX Offer
/**
* Reserves an ID for a future queue item and associates it with the given {@code transactionId}.
* The item is not yet visible in the queue, it is just reserved for future insertion.
*
* @param transactionId the ID of the transaction offering this item
* @return the ID of the reserved item
*/
public long txnOfferReserve(String transactionId) {
TxQueueItem item = new TxQueueItem(this, nextId(), null).setTransactionId(transactionId).setPollOperation(false);
txMap.put(item.getItemId(), item);
return item.getItemId();
}
use of com.hazelcast.collection.impl.txnqueue.TxQueueItem in project hazelcast by hazelcast.
the class QueueContainer method txnPollBackupReserve.
public void txnPollBackupReserve(long itemId, String transactionId) {
QueueItem item = getBackupMap().remove(itemId);
if (item == null) {
logger.warning("Backup reserve failed, itemId: " + itemId + " is not found");
return;
}
txMap.put(itemId, new TxQueueItem(item).setPollOperation(true).setTransactionId(transactionId));
}
use of com.hazelcast.collection.impl.txnqueue.TxQueueItem in project hazelcast by hazelcast.
the class QueueContainer method txnPollReserve.
//TX Poll
/**
* Retrieves and removes the head of the queue and loads the data from the queue store if the data is not stored in-memory
* and the queue store is configured and enabled. If the queue is empty returns an item which was previously reserved with
* the {@code reservedOfferId} by invoking {@code {@link #txnOfferReserve(String)}}.
*
* @param reservedOfferId the ID of the reserved item to be returned if the queue is empty
* @param transactionId the transaction ID for which this poll is invoked
* @return the head of the queue or a reserved item with the {@code reservedOfferId} if there is any
*/
public QueueItem txnPollReserve(long reservedOfferId, String transactionId) {
QueueItem item = getItemQueue().peek();
if (item == null) {
TxQueueItem txItem = txMap.remove(reservedOfferId);
if (txItem == null) {
return null;
}
item = new QueueItem(this, txItem.getItemId(), txItem.getData());
return item;
}
if (store.isEnabled() && item.getData() == null) {
try {
load(item);
} catch (Exception e) {
throw new HazelcastException(e);
}
}
getItemQueue().poll();
txMap.put(item.getItemId(), new TxQueueItem(item).setPollOperation(true).setTransactionId(transactionId));
return item;
}
use of com.hazelcast.collection.impl.txnqueue.TxQueueItem in project hazelcast by hazelcast.
the class QueueContainer method addTxItemOrdered.
private void addTxItemOrdered(TxQueueItem txQueueItem) {
if (isPriorityQueue) {
getItemQueue().add(txQueueItem);
} else {
ListIterator<QueueItem> iterator = ((List<QueueItem>) getItemQueue()).listIterator();
while (iterator.hasNext()) {
QueueItem queueItem = iterator.next();
if (txQueueItem.itemId < queueItem.itemId) {
iterator.previous();
break;
}
}
iterator.add(txQueueItem);
}
}
Aggregations