public class QueueContainer extends Object implements IdentifiedDataSerializable
QueueContainer
contains the actual queue and provides functionalities such as :
Constructor and Description |
---|
QueueContainer()
The default no-args constructor is only meant for factory usage.
|
QueueContainer(String name) |
QueueContainer(String name,
QueueConfig config,
NodeEngine nodeEngine,
QueueService service) |
Modifier and Type | Method and Description |
---|---|
Map<Long,Data> |
addAll(Collection<Data> dataList)
Adds all items from the
dataList to the queue. |
void |
addAllBackup(Map<Long,Data> dataMap)
Offers the items to the backup map in bulk.
|
int |
backupSize()
Returns the number of queue items contained on this
backup replica.
|
void |
cancelEvictionIfExists() |
Map<Long,Data> |
clear() |
void |
clearBackup(Set<Long> itemIdSet) |
Map<Long,Data> |
compareAndRemove(Collection<Data> dataList,
boolean retain)
Compares if the queue contains the items in the dataList and removes them according to the retain parameter.
|
void |
compareAndRemoveBackup(Set<Long> itemIdSet) |
boolean |
contains(Collection<Data> dataSet)
Checks if the queue contains all items in the dataSet.
|
void |
destroy() |
Map<Long,Data> |
drain(int maxSize)
Removes items from the queue and the queue store (if configured), up to
maxSize or the size of the queue,
whichever is smaller. |
void |
drainFromBackup(Set<Long> itemIdSet) |
List<Data> |
getAsDataList()
Returns data in the queue.
|
Map<Long,QueueItem> |
getBackupMap()
Return the map containing queue items when this instance is
a backup replica.
|
QueueConfig |
getConfig() |
Data |
getDataFromMap(long itemId) |
int |
getFactoryId()
Returns DataSerializableFactory factory ID for this class.
|
int |
getId()
Returns type identifier for this class.
|
Deque<QueueItem> |
getItemQueue()
Returns the item queue on the partition owner.
|
QueueWaitNotifyKey |
getOfferWaitNotifyKey() |
QueueWaitNotifyKey |
getPollWaitNotifyKey() |
QueueStoreWrapper |
getStore() |
boolean |
hasEnoughCapacity()
Returns if this queue can accommodate one item.
|
boolean |
hasEnoughCapacity(int delta)
Returns if this queue can accommodate for
delta items. |
void |
init(boolean fromBackup)
Initializes the item queue with items from the queue store if the store is enabled and if item queue is not being
initialized as a part of a backup operation.
|
boolean |
isEvictable() |
void |
mapDrainIterator(int maxSize,
Map map) |
void |
mapIterateAndRemove(Map<Long,Data> map)
Deletes items from the queue which have IDs contained in the key set of the given map.
|
long |
offer(Data data) |
void |
offerBackup(Data data,
long itemId)
Offers the item to the backup map.
|
QueueItem |
peek()
Retrieves, but does not remove, the head of this queue, or returns
null if this queue is empty. |
QueueItem |
poll()
Retrieves and removes the head of the queue (in other words, the first item), or returns
null if it is empty. |
void |
pollBackup(long itemId)
Polls an item on the backup replica.
|
void |
readData(ObjectDataInput in)
Reads fields from the input stream
|
long |
remove(Data data)
iterates all items, checks equality with data
This method does not trigger store load.
|
void |
removeBackup(long itemId)
Removes a queue item from the backup map.
|
void |
rollbackTransaction(String transactionId) |
void |
setConfig(QueueConfig config,
NodeEngine nodeEngine,
QueueService service) |
void |
setStats(LocalQueueStatsImpl stats) |
int |
size() |
int |
txMapSize() |
boolean |
txnCheckReserve(long itemId)
Checks if there is a reserved item (within a transaction) with the given
itemId . |
boolean |
txnCommitOffer(long itemId,
Data data,
boolean backup)
Sets the data of a reserved item and commits the change so it can be
visible outside a transaction.
|
Data |
txnCommitPoll(long itemId) |
Data |
txnCommitPollBackup(long itemId)
Commits the effects of the
txnPollReserve(long, String) }. |
void |
txnEnsureBackupReserve(long itemId,
String transactionId,
boolean pollOperation) |
void |
txnOfferBackupReserve(long itemId,
String transactionId)
Reserves an ID for a future queue item and associates it with the given
transactionId . |
long |
txnOfferReserve(String transactionId)
Reserves an ID for a future queue item and associates it with the given
transactionId . |
QueueItem |
txnPeek(long offerId,
String transactionId)
Retrieves, but does not remove, the head of the queue.
|
void |
txnPollBackupReserve(long itemId,
String transactionId)
Makes a reservation for a poll operation.
|
QueueItem |
txnPollReserve(long reservedOfferId,
String transactionId)
Tries to obtain an item by removing the head of the
queue or removing an item previously reserved by invoking
txnOfferReserve(String) with reservedOfferId . |
boolean |
txnRollbackOffer(long itemId)
Removes a reserved item with the given
itemId . |
boolean |
txnRollbackOfferBackup(long itemId)
Removes a reserved item with the given
itemId . |
boolean |
txnRollbackPoll(long itemId,
boolean backup)
Rolls back the effects of the
txnPollReserve(long, String) . |
void |
writeData(ObjectDataOutput out)
Writes object fields to output stream
|
public QueueContainer()
public QueueContainer(String name)
public QueueContainer(String name, QueueConfig config, NodeEngine nodeEngine, QueueService service)
public void init(boolean fromBackup)
fromBackup
- indicates if this item queue is being initialized from a backup operation. If false, the
item queue will initialize from the queue store. If true, it will not initializepublic QueueStoreWrapper getStore()
public boolean txnCheckReserve(long itemId)
itemId
.itemId
- the ID which is to be checkedTransactionException
- if there is no reserved item with the IDpublic void txnEnsureBackupReserve(long itemId, String transactionId, boolean pollOperation)
public QueueItem txnPollReserve(long reservedOfferId, String transactionId)
txnOfferReserve(String)
with reservedOfferId
.
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.
reservedOfferId
- the ID of the reserved item to be returned if the queue is emptytransactionId
- the transaction ID for which this poll is invokedreservedOfferId
if there is anypublic void txnPollBackupReserve(long itemId, String transactionId)
itemId
- the ID of the reserved item to be polledtransactionId
- the transaction IDtxnPollReserve(long, String)
,
TxnReservePollOperation
public Data txnCommitPoll(long itemId)
public Data txnCommitPollBackup(long itemId)
txnPollReserve(long, String)
}. Also deletes the item data from the queue
data store if it is configured and enabled.itemId
- the ID of the item which was polled inside a transactionHazelcastException
- if there was any exception while removing the item from the queue data storepublic boolean txnRollbackPoll(long itemId, boolean backup)
txnPollReserve(long, String)
.
The 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.itemId
- the ID of the item which was polled in a transactionbackup
- if this is the primary or the backup replica for this queueitemId
inside a transactionpublic long txnOfferReserve(String transactionId)
transactionId
.
The item is not yet visible in the queue, it is just reserved for future insertion.transactionId
- the ID of the transaction offering this itempublic void txnOfferBackupReserve(long itemId, String transactionId)
transactionId
.
The item is not yet visible in the queue, it is just reserved for future insertion.transactionId
- the ID of the transaction offering this itemitemId
- the ID of the item being reservedpublic boolean txnCommitOffer(long itemId, Data data, boolean backup)
backup
is false or saved into a backup map if backup
is true
.
This is because a node can hold backups for queues on other nodes.
Cancels the queue eviction if one is scheduled.itemId
- the ID of the reserved itemdata
- the data to be associated with the reserved itembackup
- if the item is to be offered to the underlying queue or stored as a backuptrue
if the commit succeededTransactionException
- if there is no reserved item with the itemId
public boolean txnRollbackOffer(long itemId)
itemId
. Also schedules the queue for destruction if it is empty or
destroys it immediately if it is empty and QueueConfig.getEmptyQueueTtl()
is 0.itemId
- the ID of the reserved item to be removeditemId
public boolean txnRollbackOfferBackup(long itemId)
itemId
.itemId
- the ID of the reserved item to be removeditemId
public QueueItem txnPeek(long offerId, String transactionId)
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.offerId
- the ID of the reserved item to be returned if the queue is emptytransactionId
- currently ignoredofferId
if the queue is emptyHazelcastException
- if there is an exception while loading the data from the queue storepublic long offer(Data data)
public void offerBackup(Data data, long itemId)
data
- the item dataitemId
- the item ID as determined by the primary replicapublic Map<Long,Data> addAll(Collection<Data> dataList)
dataList
to the queue. The data will be stored in the queue store if configured and
enabled. If the store is enabled, only QueueStoreWrapper.getMemoryLimit()
item data will be stored in memory.
Cancels the eviction if one is scheduled.dataList
- the items to be added to the queue and stored in the queue storepublic void addAllBackup(Map<Long,Data> dataMap)
dataMap
- the map from item ID to queue itemofferBackup(Data, long)
public QueueItem peek()
null
if this queue is empty.
Loads the data from the queue store if the item data is empty.public QueueItem poll()
null
if it is empty.
Also calls the queue store for item deletion by item ID.public void pollBackup(long itemId)
itemId
- the item ID as determined by the primary replicapublic Map<Long,Data> drain(int maxSize)
maxSize
or the size of the queue,
whichever is smaller. Also schedules the queue for destruction if it is empty or destroys it immediately if it is
empty and QueueConfig.getEmptyQueueTtl()
is 0.maxSize
- the maximum number of items to be removedpublic void mapDrainIterator(int maxSize, Map map)
public int size()
public int txMapSize()
public int backupSize()
public long remove(Data data)
public void removeBackup(long itemId)
itemId
- the queue item IDpublic boolean contains(Collection<Data> dataSet)
dataSet
- the items which should be stored in the queuepublic List<Data> getAsDataList()
public Map<Long,Data> compareAndRemove(Collection<Data> dataList, boolean retain)
Note: this method will trigger store load.
dataList
- the list of items which are to be retained in the queue or which are to be removed from the queueretain
- does the method retain the items in the list (true) or remove them from the queue (false)public void mapIterateAndRemove(Map<Long,Data> map)
QueueConfig.getEmptyQueueTtl()
is 0.map
- the map of items which to be removed.public boolean hasEnoughCapacity()
public boolean hasEnoughCapacity(int delta)
delta
items.delta
- the number of items that should be stored in the queuepublic Deque<QueueItem> getItemQueue()
public Map<Long,QueueItem> getBackupMap()
public Data getDataFromMap(long itemId)
public void setConfig(QueueConfig config, NodeEngine nodeEngine, QueueService service)
public QueueWaitNotifyKey getPollWaitNotifyKey()
public QueueWaitNotifyKey getOfferWaitNotifyKey()
public QueueConfig getConfig()
public void setStats(LocalQueueStatsImpl stats)
public void cancelEvictionIfExists()
public boolean isEvictable()
public void rollbackTransaction(String transactionId)
public void writeData(ObjectDataOutput out) throws IOException
DataSerializable
writeData
in interface DataSerializable
out
- outputIOException
public void readData(ObjectDataInput in) throws IOException
DataSerializable
readData
in interface DataSerializable
in
- inputIOException
public void destroy()
public int getFactoryId()
IdentifiedDataSerializable
getFactoryId
in interface IdentifiedDataSerializable
public int getId()
IdentifiedDataSerializable
getId
in interface IdentifiedDataSerializable
Copyright © 2018 Hazelcast, Inc.. All Rights Reserved.