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) |
int |
backupSize() |
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.
|
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() |
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) |
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) |
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) |
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) |
QueueItem |
txnPollReserve(long reservedOfferId,
String transactionId)
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.
|
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) throws Exception
Exception
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)
reservedOfferId
by invoking {@link #txnOfferReserve(String)}
.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)
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. Also adds a queue item with the itemId
to the backup
map if the backup
parameter is true or the queue.
Cancels the queue eviction if one is scheduled.itemId
- the ID of the item which was polled in a transactionbackup
- if this item wasitemId
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 backupTransactionException
- 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)
public 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 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)
public 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)
public 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)
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 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 © 2017 Hazelcast, Inc.. All Rights Reserved.