use of com.hazelcast.collection.impl.txnqueue.TxQueueItem in project hazelcast by hazelcast.
the class QueueContainer method readData.
@Override
public void readData(ObjectDataInput in) throws IOException {
name = in.readString();
pollWaitNotifyKey = new QueueWaitNotifyKey(name, "poll");
offerWaitNotifyKey = new QueueWaitNotifyKey(name, "offer");
int size = in.readInt();
// on cluster migration queue data are stored temporary to a default priority queue.
// those data are copied at a later point
itemQueue = new LinkedList<>();
for (int j = 0; j < size; j++) {
QueueItem item = in.readObject();
item.setContainer(this);
getItemQueue().offer(item);
setId(item.getItemId());
}
int txSize = in.readInt();
for (int j = 0; j < txSize; j++) {
TxQueueItem item = new TxQueueItem(this, -1, null);
item.readData(in);
txMap.put(item.getItemId(), item);
setId(item.getItemId());
}
}
use of com.hazelcast.collection.impl.txnqueue.TxQueueItem in project hazelcast by hazelcast.
the class QueueDataSerializerHook method createFactory.
public DataSerializableFactory createFactory() {
// noinspection unchecked
ConstructorFunction<Integer, IdentifiedDataSerializable>[] constructors = new ConstructorFunction[MERGE_BACKUP + 1];
constructors[OFFER] = arg -> new OfferOperation();
constructors[OFFER_BACKUP] = arg -> new OfferBackupOperation();
constructors[POLL] = arg -> new PollOperation();
constructors[POLL_BACKUP] = arg -> new PollBackupOperation();
constructors[PEEK] = arg -> new PeekOperation();
constructors[ADD_ALL_BACKUP] = arg -> new AddAllBackupOperation();
constructors[ADD_ALL] = arg -> new AddAllOperation();
constructors[CLEAR_BACKUP] = arg -> new ClearBackupOperation();
constructors[CLEAR] = arg -> new ClearOperation();
constructors[COMPARE_AND_REMOVE_BACKUP] = arg -> new CompareAndRemoveBackupOperation();
constructors[COMPARE_AND_REMOVE] = arg -> new CompareAndRemoveOperation();
constructors[CONTAINS] = arg -> new ContainsOperation();
constructors[DRAIN_BACKUP] = arg -> new DrainBackupOperation();
constructors[DRAIN] = arg -> new DrainOperation();
constructors[ITERATOR] = arg -> new IteratorOperation();
constructors[QUEUE_EVENT] = arg -> new QueueEvent();
constructors[QUEUE_EVENT_FILTER] = arg -> new QueueEventFilter();
constructors[QUEUE_ITEM] = arg -> new QueueItem();
constructors[QUEUE_REPLICATION] = arg -> new QueueReplicationOperation();
constructors[REMOVE_BACKUP] = arg -> new RemoveBackupOperation();
constructors[REMOVE] = arg -> new RemoveOperation();
constructors[SIZE] = arg -> new SizeOperation();
constructors[TXN_OFFER_BACKUP] = arg -> new TxnOfferBackupOperation();
constructors[TXN_OFFER] = arg -> new TxnOfferOperation();
constructors[TXN_POLL_BACKUP] = arg -> new TxnPollBackupOperation();
constructors[TXN_POLL] = arg -> new TxnPollOperation();
constructors[TXN_PREPARE_BACKUP] = arg -> new TxnPrepareBackupOperation();
constructors[TXN_PREPARE] = arg -> new TxnPrepareOperation();
constructors[TXN_RESERVE_OFFER] = arg -> new TxnReserveOfferOperation();
constructors[TXN_RESERVE_OFFER_BACKUP] = arg -> new TxnReserveOfferBackupOperation();
constructors[TXN_RESERVE_POLL] = arg -> new TxnReservePollOperation();
constructors[TXN_RESERVE_POLL_BACKUP] = arg -> new TxnReservePollBackupOperation();
constructors[TXN_ROLLBACK_BACKUP] = arg -> new TxnRollbackBackupOperation();
constructors[TXN_ROLLBACK] = arg -> new TxnRollbackOperation();
constructors[CHECK_EVICT] = arg -> new CheckAndEvictOperation();
constructors[QUEUE_CONTAINER] = arg -> new QueueContainer();
constructors[TRANSACTION_ROLLBACK] = arg -> new QueueTransactionRollbackOperation();
constructors[TX_QUEUE_ITEM] = arg -> new TxQueueItem();
constructors[TXN_PEEK] = arg -> new TxnPeekOperation();
constructors[IS_EMPTY] = arg -> new IsEmptyOperation();
constructors[REMAINING_CAPACITY] = arg -> new RemainingCapacityOperation();
constructors[TXN_COMMIT] = arg -> new TxnCommitOperation();
constructors[TXN_COMMIT_BACKUP] = arg -> new TxnCommitBackupOperation();
constructors[MERGE] = arg -> new QueueMergeOperation();
constructors[MERGE_BACKUP] = arg -> new QueueMergeBackupOperation();
return new ArrayDataSerializableFactory(constructors);
}
use of com.hazelcast.collection.impl.txnqueue.TxQueueItem in project hazelcast by hazelcast.
the class QueueContainer method txnOfferBackupReserve.
/**
* 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
* @param itemId the ID of the item being reserved
*/
public void txnOfferBackupReserve(long itemId, String transactionId) {
QueueItem item = new QueueItem(this, itemId, null);
Object o = txMap.put(itemId, new TxQueueItem(item).setPollOperation(false).setTransactionId(transactionId));
if (o != null) {
logger.severe("txnOfferBackupReserve operation-> Item exists already at txMap for itemId: " + itemId);
}
}
use of com.hazelcast.collection.impl.txnqueue.TxQueueItem in project hazelcast by hazelcast.
the class QueueContainer method rollbackTransaction.
public void rollbackTransaction(String transactionId) {
final Iterator<TxQueueItem> iterator = txMap.values().iterator();
while (iterator.hasNext()) {
final TxQueueItem item = iterator.next();
if (transactionId.equals(item.getTransactionId())) {
iterator.remove();
if (item.isPollOperation()) {
getItemQueue().offerFirst(item);
cancelEvictionIfExists();
}
}
}
}
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, UUID 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.getSerializedObject());
return item;
}
if (store.isEnabled() && item.getSerializedObject() == null) {
try {
load(item);
} catch (Exception e) {
throw new HazelcastException(e);
}
}
return item;
}
Aggregations