Search in sources :

Example 6 with TxQueueItem

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());
    }
}
Also used : TxQueueItem(com.hazelcast.collection.impl.txnqueue.TxQueueItem) TxQueueItem(com.hazelcast.collection.impl.txnqueue.TxQueueItem)

Example 7 with TxQueueItem

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);
}
Also used : TxnReserveOfferBackupOperation(com.hazelcast.collection.impl.txnqueue.operations.TxnReserveOfferBackupOperation) TxnOfferBackupOperation(com.hazelcast.collection.impl.txnqueue.operations.TxnOfferBackupOperation) OfferBackupOperation(com.hazelcast.collection.impl.queue.operations.OfferBackupOperation) AddAllOperation(com.hazelcast.collection.impl.queue.operations.AddAllOperation) QueueMergeOperation(com.hazelcast.collection.impl.queue.operations.QueueMergeOperation) QueueReplicationOperation(com.hazelcast.collection.impl.queue.operations.QueueReplicationOperation) TxnPrepareBackupOperation(com.hazelcast.collection.impl.txnqueue.operations.TxnPrepareBackupOperation) TxnReservePollBackupOperation(com.hazelcast.collection.impl.txnqueue.operations.TxnReservePollBackupOperation) PollBackupOperation(com.hazelcast.collection.impl.queue.operations.PollBackupOperation) TxnPollBackupOperation(com.hazelcast.collection.impl.txnqueue.operations.TxnPollBackupOperation) ClearBackupOperation(com.hazelcast.collection.impl.queue.operations.ClearBackupOperation) AddAllBackupOperation(com.hazelcast.collection.impl.queue.operations.AddAllBackupOperation) IsEmptyOperation(com.hazelcast.collection.impl.queue.operations.IsEmptyOperation) DrainOperation(com.hazelcast.collection.impl.queue.operations.DrainOperation) IteratorOperation(com.hazelcast.collection.impl.queue.operations.IteratorOperation) CompareAndRemoveBackupOperation(com.hazelcast.collection.impl.queue.operations.CompareAndRemoveBackupOperation) TxnReservePollOperation(com.hazelcast.collection.impl.txnqueue.operations.TxnReservePollOperation) TxnPollBackupOperation(com.hazelcast.collection.impl.txnqueue.operations.TxnPollBackupOperation) TxnReserveOfferBackupOperation(com.hazelcast.collection.impl.txnqueue.operations.TxnReserveOfferBackupOperation) TxnCommitOperation(com.hazelcast.collection.impl.txnqueue.operations.TxnCommitOperation) TxnReservePollBackupOperation(com.hazelcast.collection.impl.txnqueue.operations.TxnReservePollBackupOperation) TxnPrepareOperation(com.hazelcast.collection.impl.txnqueue.operations.TxnPrepareOperation) TxnReserveOfferOperation(com.hazelcast.collection.impl.txnqueue.operations.TxnReserveOfferOperation) TxQueueItem(com.hazelcast.collection.impl.txnqueue.TxQueueItem) TxnOfferOperation(com.hazelcast.collection.impl.txnqueue.operations.TxnOfferOperation) SizeOperation(com.hazelcast.collection.impl.queue.operations.SizeOperation) CheckAndEvictOperation(com.hazelcast.collection.impl.queue.operations.CheckAndEvictOperation) TxnReserveOfferOperation(com.hazelcast.collection.impl.txnqueue.operations.TxnReserveOfferOperation) TxnOfferOperation(com.hazelcast.collection.impl.txnqueue.operations.TxnOfferOperation) OfferOperation(com.hazelcast.collection.impl.queue.operations.OfferOperation) TxnRollbackOperation(com.hazelcast.collection.impl.txnqueue.operations.TxnRollbackOperation) TxnOfferBackupOperation(com.hazelcast.collection.impl.txnqueue.operations.TxnOfferBackupOperation) ContainsOperation(com.hazelcast.collection.impl.queue.operations.ContainsOperation) TxnPeekOperation(com.hazelcast.collection.impl.txnqueue.operations.TxnPeekOperation) RemoveOperation(com.hazelcast.collection.impl.queue.operations.RemoveOperation) CompareAndRemoveOperation(com.hazelcast.collection.impl.queue.operations.CompareAndRemoveOperation) ClearOperation(com.hazelcast.collection.impl.queue.operations.ClearOperation) CompareAndRemoveOperation(com.hazelcast.collection.impl.queue.operations.CompareAndRemoveOperation) TxnPeekOperation(com.hazelcast.collection.impl.txnqueue.operations.TxnPeekOperation) PeekOperation(com.hazelcast.collection.impl.queue.operations.PeekOperation) ConstructorFunction(com.hazelcast.internal.util.ConstructorFunction) QueueTransactionRollbackOperation(com.hazelcast.collection.impl.txnqueue.operations.QueueTransactionRollbackOperation) TxnCommitBackupOperation(com.hazelcast.collection.impl.txnqueue.operations.TxnCommitBackupOperation) PollOperation(com.hazelcast.collection.impl.queue.operations.PollOperation) TxnReservePollOperation(com.hazelcast.collection.impl.txnqueue.operations.TxnReservePollOperation) TxnPollOperation(com.hazelcast.collection.impl.txnqueue.operations.TxnPollOperation) TxQueueItem(com.hazelcast.collection.impl.txnqueue.TxQueueItem) TxnRollbackBackupOperation(com.hazelcast.collection.impl.txnqueue.operations.TxnRollbackBackupOperation) RemoveBackupOperation(com.hazelcast.collection.impl.queue.operations.RemoveBackupOperation) CompareAndRemoveBackupOperation(com.hazelcast.collection.impl.queue.operations.CompareAndRemoveBackupOperation) DrainBackupOperation(com.hazelcast.collection.impl.queue.operations.DrainBackupOperation) ArrayDataSerializableFactory(com.hazelcast.internal.serialization.impl.ArrayDataSerializableFactory) RemainingCapacityOperation(com.hazelcast.collection.impl.queue.operations.RemainingCapacityOperation) QueueMergeBackupOperation(com.hazelcast.collection.impl.queue.operations.QueueMergeBackupOperation) TxnPollOperation(com.hazelcast.collection.impl.txnqueue.operations.TxnPollOperation)

Example 8 with TxQueueItem

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);
    }
}
Also used : TxQueueItem(com.hazelcast.collection.impl.txnqueue.TxQueueItem) TxQueueItem(com.hazelcast.collection.impl.txnqueue.TxQueueItem)

Example 9 with TxQueueItem

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();
            }
        }
    }
}
Also used : TxQueueItem(com.hazelcast.collection.impl.txnqueue.TxQueueItem)

Example 10 with TxQueueItem

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;
}
Also used : HazelcastException(com.hazelcast.core.HazelcastException) TxQueueItem(com.hazelcast.collection.impl.txnqueue.TxQueueItem) TxQueueItem(com.hazelcast.collection.impl.txnqueue.TxQueueItem) TransactionException(com.hazelcast.transaction.TransactionException) HazelcastException(com.hazelcast.core.HazelcastException) IOException(java.io.IOException)

Aggregations

TxQueueItem (com.hazelcast.collection.impl.txnqueue.TxQueueItem)14 HazelcastException (com.hazelcast.core.HazelcastException)4 TransactionException (com.hazelcast.transaction.TransactionException)4 IOException (java.io.IOException)4 AddAllBackupOperation (com.hazelcast.collection.impl.queue.operations.AddAllBackupOperation)1 AddAllOperation (com.hazelcast.collection.impl.queue.operations.AddAllOperation)1 CheckAndEvictOperation (com.hazelcast.collection.impl.queue.operations.CheckAndEvictOperation)1 ClearBackupOperation (com.hazelcast.collection.impl.queue.operations.ClearBackupOperation)1 ClearOperation (com.hazelcast.collection.impl.queue.operations.ClearOperation)1 CompareAndRemoveBackupOperation (com.hazelcast.collection.impl.queue.operations.CompareAndRemoveBackupOperation)1 CompareAndRemoveOperation (com.hazelcast.collection.impl.queue.operations.CompareAndRemoveOperation)1 ContainsOperation (com.hazelcast.collection.impl.queue.operations.ContainsOperation)1 DrainBackupOperation (com.hazelcast.collection.impl.queue.operations.DrainBackupOperation)1 DrainOperation (com.hazelcast.collection.impl.queue.operations.DrainOperation)1 IsEmptyOperation (com.hazelcast.collection.impl.queue.operations.IsEmptyOperation)1 IteratorOperation (com.hazelcast.collection.impl.queue.operations.IteratorOperation)1 OfferBackupOperation (com.hazelcast.collection.impl.queue.operations.OfferBackupOperation)1 OfferOperation (com.hazelcast.collection.impl.queue.operations.OfferOperation)1 PeekOperation (com.hazelcast.collection.impl.queue.operations.PeekOperation)1 PollBackupOperation (com.hazelcast.collection.impl.queue.operations.PollBackupOperation)1