use of com.hazelcast.collection.impl.txnqueue.TxQueueItem in project hazelcast by hazelcast.
the class QueueContainer method txnPollReserve.
// TX Poll
/**
* Tries to obtain an item by removing the head of the
* queue or removing an item previously reserved by invoking
* {@link #txnOfferReserve(UUID)} with {@code reservedOfferId}.
* <p>
* If the queue item does not have data in-memory it will load the
* data from the queue store if the queue store is configured and enabled.
*
* @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, UUID 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.getSerializedObject());
return item;
}
if (store.isEnabled() && item.getSerializedObject() == 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 txnRollbackPoll.
/**
* Rolls back the effects of the {@link #txnPollReserve(long, UUID)}.
* The {@code backup} parameter defines whether this item was stored
* on a backup queue or a primary queue.
* It will return the item to the queue or backup map if it wasn't
* offered as a part of the transaction.
* Cancels the queue eviction if one is scheduled.
*
* @param itemId the ID of the item which was polled in a transaction
* @param backup if this is the primary or the backup replica for this queue
* @return if there was any polled item with the {@code itemId} inside a transaction
*/
public boolean txnRollbackPoll(long itemId, boolean backup) {
TxQueueItem item = txMap.remove(itemId);
if (item == null) {
return false;
}
if (backup) {
getBackupMap().put(itemId, item);
} else {
addTxItemOrdered(item);
}
cancelEvictionIfExists();
return true;
}
use of com.hazelcast.collection.impl.txnqueue.TxQueueItem in project hazelcast by hazelcast.
the class QueueContainer method writeData.
@Override
public void writeData(ObjectDataOutput out) throws IOException {
out.writeString(name);
out.writeInt(getItemQueue().size());
for (QueueItem item : getItemQueue()) {
out.writeObject(item);
}
out.writeInt(txMap.size());
for (TxQueueItem item : txMap.values()) {
item.writeData(out);
}
}
use of com.hazelcast.collection.impl.txnqueue.TxQueueItem in project hazelcast by hazelcast.
the class QueueContainer method getItemQueue.
/**
* Returns the item queue on the partition owner. This method
* will also move the items from the backup map if this
* member has been promoted from a backup replica to the
* partition owner and clear the backup map.
*
* @return the item queue
*/
public Queue<QueueItem> getItemQueue() {
if (itemQueue == null) {
itemQueue = isPriorityQueue ? createPriorityQueue() : createLinkedList();
if (!txMap.isEmpty()) {
long maxItemId = Long.MIN_VALUE;
for (TxQueueItem item : txMap.values()) {
maxItemId = Math.max(maxItemId, item.itemId);
}
setId(maxItemId + ID_PROMOTION_OFFSET);
}
}
return itemQueue;
}
Aggregations