Package com.swiftmq.swiftlet.queue
Class AbstractQueue
java.lang.Object
com.swiftmq.swiftlet.queue.AbstractQueue
Abstract base class for queues used in SwiftMQ.
All operations on the queue will be controlled by the queue manager. Access to queues
are exclusively performed by the resp. accessor classes like QueuePull/PushTransaction.
- Author:
- IIT GmbH, Bremen/Germany, Copyright (c) 2000-2002, All Rights Reserved
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final int
static final int
protected long
protected int
static final int
protected final AtomicReference
<FlowController> protected int
static final int
protected int
static final int
protected final AtomicInteger
static final int
protected boolean
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
acknowledgeMessage
(Object transactionId, MessageIndex messageIndex) Acknowledges a message that was fetched within a pull transaction.void
acknowledgeMessage
(Object transactionId, MessageIndex messageIndex, AsyncCompletionCallback callback) Async acknowledges a message that was fetched within a pull transaction.void
acknowledgeMessages
(Object transactionId, List messageIndexList, AsyncCompletionCallback callback) Async acknowledges a list of messages that were fetched within a pull transaction.void
addWireTapSubscriber
(String name, WireTapSubscriber subscriber) buildPreparedTransaction
(PrepareLogRecord logRecord) Builds a new QueueTransaction on base of the PrepareLogRecord.void
Deletes all expired messages from the queueabstract void
Commit the transaction with the given transaction idabstract void
Commits a prepared transaction.abstract void
commit
(Object transactionId, AsyncCompletionCallback callback) Asynchronously commits the transaction with the given transaction idabstract Object
Creates a new pull transaction and returns a unique transaction idabstract Object
Creates a new push transaction and returns a unique transaction idint
createView
(Selector selector) Creates a new view, based on a selectorvoid
Decrements the queue receiver count.void
Removes all messages from the queue.void
deleteView
(int viewId) Creates a new view, based on a selectorvoid
long
Returns the average queue latency and resets itint
Returns the max.int
Returns the max cache size in KBlong
Returns the cleanup interval in millisecondsReturns the current composite store transactionint
Returns the total number of consumed messagesint
int
Returns the consuming rate in Msgs/Secint
Returns the current cache size in KBint
Returns the current cache size in number messages.getExpiredMessage
(Object transactionId, long timeout) Get the next expired message from the queue but wait only a specific period of time.Returns the flow controller.getIndexEntry
(MessageIndex messageIndex) Returns the actual index entry (the implementation of the MessageIndex class) used for this MessageIndexReturns the local name.int
Returns the max.getMessage
(Object transactionId) Get a message from the queue.getMessage
(Object transactionId, long timeout) Get a message from the queue but wait only a specific period of time.getMessage
(Object transactionId, Selector selector) Get a message from the queue that matches the selector.getMessage
(Object transactionId, Selector selector, int viewId) Get the next message from a view.getMessage
(Object transactionId, Selector selector, int viewId, long timeout) Get the next message from the view but wait only a specific period of time.getMessage
(Object transactionId, Selector selector, long timeout) Get a message from the queue that matches the selector but wait only a specific period of time.getMessageByIndex
(MessageIndex messageIndex) Returns the message with that given key.int
long
Returns the number of messages actually stored in the queueint
Returns the queue persistence mode.int
Returns the total number of produced messagesint
Returns the producing rate in Msgs/SecReturns a current snapshot of the queue index (message indexes)getQueueIndex
(int viewId) Returns a current snapshot of the viewReturns the queue nameint
Returns the queue receiver count.abstract boolean
hasReceiver
(MessageImpl message) Checks all registered receivers and, if set, their message selectors whether this message will be received by one of them.void
Increments the queue receiver count.boolean
boolean
Returns if the queue is running or notboolean
Returns the temporary flag.void
Locks this queue and holds it until unlockQueue is called.void
moveToTransaction
(MessageIndex messageIndex, Object destTxId) Moves a message with the given message index to the destination transaction.void
moveToTransaction
(MessageIndex messageIndex, Object sourceTxId, Object destTxId) Moves a message with the given message index from the source to the destination transaction.long
moveToTransactionReturnSize
(MessageIndex messageIndex, Object destTxId) Moves a message with the given message index to the destination transaction and returns the message size.long
moveToTransactionReturnSize
(MessageIndex messageIndex, Object sourceTxId, Object destTxId) Moves a message with the given message index from the source to the destination transaction and returns its size.abstract void
Prepares the transaction with the given transaction id.abstract void
putMessage
(Object transactionId, MessageImpl message) Put a message into the queuevoid
receiverClosed
(long receiverId) Internal usevoid
registerMessageProcessor
(MessageProcessor messageProcessor) Registers a message processor.void
removeMessageByIndex
(MessageIndex messageIndex) Removes a message with that given key outside a queue transaction.void
removeMessages
(Object transactionId, List<MessageIndex> messageIndexes) Remove messages from a queuevoid
removeWireTapSubscriber
(String name, WireTapSubscriber subscriber) void
Resets all consumed/produced countersabstract void
Rolls back the transaction with the given transaction id.abstract void
rollback
(Object transactionId, boolean setRedelivered, AsyncCompletionCallback callback) Asynchronously rolls back the transaction with the given transaction id.abstract void
Rolls back the transaction with the given transaction id, eventually prepared under a global transaction id.Selects the underlaying base queue of this queue.void
setCleanUpInterval
(long cleanUpInterval) Sets the cleanup interval.void
Sets a CompositeStoreTransaction to be used as the current transaction.void
setConsumerMode
(int consumerMode) void
setFlowController
(FlowController flowController) Sets the flow controller.void
setLocalName
(String localName) Sets the local name.void
setMaxMessages
(int maxMessages) Sets the max.void
setPersistenceMode
(int persistenceMode) Sets the queue persistence mode.void
setQueueName
(String queueName) Set the queue name.void
setQueueReceiverListener
(QueueReceiverListener queueReceiverListener) void
setTemporary
(boolean b) Sets the temporary flag.void
startAccounting
(Object accountingProfile) void
Starts the queue.void
void
Stops the queue.void
timeoutMessageProcessor
(long registrationTime, int id) Removes a message processor which has been timed out.void
unlockQueue
(Object txId, boolean markAsyncActive) Unlocks this queue.void
unmarkAsyncActive
(Object txId) Unblocks this queue from async activevoid
unregisterMessageProcessor
(MessageProcessor messageProcessor) Unregisters a message processor.
-
Field Details
-
SHARED
public static final int SHARED- See Also:
-
EXCLUSIVE
public static final int EXCLUSIVE- See Also:
-
ACTIVESTANDBY
public static final int ACTIVESTANDBY- See Also:
-
AS_MESSAGE
public static final int AS_MESSAGE- See Also:
-
PERSISTENT
public static final int PERSISTENT- See Also:
-
NON_PERSISTENT
public static final int NON_PERSISTENT- See Also:
-
maxMessages
protected volatile int maxMessages -
persistenceMode
protected volatile int persistenceMode -
temporary
protected boolean temporary -
flowController
-
receiverCount
-
cleanUpInterval
protected long cleanUpInterval -
consumerMode
protected int consumerMode
-
-
Constructor Details
-
AbstractQueue
public AbstractQueue()
-
-
Method Details
-
getQueueName
Returns the queue name- Returns:
- queue name
-
setQueueName
Set the queue name. Will be called from queue manager- Parameters:
queueName
- queue name
-
getLocalName
Returns the local name.- Returns:
- local name.
-
setLocalName
Sets the local name.- Parameters:
localName
- local name.
-
getCacheSize
public int getCacheSize()Returns the max. cache size in number messages.- Returns:
- cache size.
-
getCacheSizeKB
public int getCacheSizeKB()Returns the max cache size in KB- Returns:
- cache size.
-
getCurrentCacheSizeMessages
public int getCurrentCacheSizeMessages()Returns the current cache size in number messages.- Returns:
- cache size.
-
getCurrentCacheSizeKB
public int getCurrentCacheSizeKB()Returns the current cache size in KB- Returns:
- cache size.
-
isAccounting
public boolean isAccounting() -
getConsumerMode
public int getConsumerMode() -
setConsumerMode
public void setConsumerMode(int consumerMode) -
startAccounting
-
flushAccounting
public void flushAccounting() -
stopAccounting
public void stopAccounting() -
addWireTapSubscriber
-
removeWireTapSubscriber
-
getQueueReceiverListener
-
setQueueReceiverListener
-
getFlowController
Returns the flow controller.- Returns:
- flow controller.
-
setFlowController
Sets the flow controller.- Parameters:
flowController
- flow controller.
-
incReceiverCount
public void incReceiverCount()Increments the queue receiver count. -
decReceiverCount
public void decReceiverCount()Decrements the queue receiver count. -
getReceiverCount
public int getReceiverCount()Returns the queue receiver count.- Returns:
- queue receiver count
-
receiverClosed
public void receiverClosed(long receiverId) Internal use- Parameters:
receiverId
-
-
getMaxMessages
public int getMaxMessages()Returns the max. messages.- Returns:
- max messages.
-
setMaxMessages
public void setMaxMessages(int maxMessages) Sets the max. messages.- Parameters:
maxMessages
- max messages.
-
isTemporary
public boolean isTemporary()Returns the temporary flag.- Returns:
- temporary flag.
-
setTemporary
public void setTemporary(boolean b) Sets the temporary flag.- Parameters:
b
- temporary flag.
-
getPersistenceMode
public int getPersistenceMode()Returns the queue persistence mode.- Returns:
- queue persistence mode.
-
setPersistenceMode
public void setPersistenceMode(int persistenceMode) Sets the queue persistence mode.- Parameters:
persistenceMode
- persistence mode.
-
startQueue
Starts the queue.- Throws:
QueueException
- on error
-
stopQueue
Stops the queue.- Throws:
QueueException
- on error
-
isRunning
public boolean isRunning()Returns if the queue is running or not- Returns:
- true/false
-
buildPreparedTransaction
Builds a new QueueTransaction on base of the PrepareLogRecord.- Returns:
- transaction id
- Throws:
QueueException
- on error
-
createView
Creates a new view, based on a selector- Returns:
- view id
-
deleteView
public void deleteView(int viewId) Creates a new view, based on a selector -
createPushTransaction
Creates a new push transaction and returns a unique transaction id- Returns:
- transaction id
- Throws:
QueueException
- on error
-
createPullTransaction
Creates a new pull transaction and returns a unique transaction id- Returns:
- transaction id
- Throws:
QueueException
- on error
-
selectBaseQueue
Selects the underlaying base queue of this queue. If there is no base queue, this queue instance will be returned.- Returns:
- base queue
-
prepare
public abstract void prepare(Object localtransactionId, XidImpl globalTransactionId) throws QueueException Prepares the transaction with the given transaction id. Messages are stored in the queue (on disk when persistent) but not unlocked. The preparation is logged under the global transaction id.- Parameters:
localtransactionId
- local transaction idglobalTransactionId
- global transaction id- Throws:
QueueException
- on error
-
commit
public abstract void commit(Object localtransactionId, XidImpl globalTransactionId) throws QueueException Commits a prepared transaction.- Parameters:
localtransactionId
- local transaction idglobalTransactionId
- global transaction id- Throws:
QueueException
- on error
-
commit
Commit the transaction with the given transaction id- Parameters:
transactionId
- transaction id- Throws:
QueueException
- on error
-
commit
Asynchronously commits the transaction with the given transaction id- Parameters:
transactionId
- transaction idcallback
- async completion callback
-
rollback
public abstract void rollback(Object transactionId, XidImpl globalTransactionId, boolean setRedelivered) throws QueueException Rolls back the transaction with the given transaction id, eventually prepared under a global transaction id. If the flagsetRedelivered
is set then the JMS properties for redelivery and delivery count of messages pulled within this transaction are updated.- Parameters:
transactionId
- transaction idglobalTransactionId
- global transaction idsetRedelivered
- specifies JMS redelivery setting- Throws:
QueueException
- on error
-
rollback
Rolls back the transaction with the given transaction id. If the flagsetRedelivered
is set then the JMS properties for redelivery and delivery count of messages pulled within this transaction are updated- Parameters:
transactionId
- transaction idsetRedelivered
- specifies JMS redelivery setting- Throws:
QueueException
- on error
-
rollback
public abstract void rollback(Object transactionId, boolean setRedelivered, AsyncCompletionCallback callback) Asynchronously rolls back the transaction with the given transaction id. If the flagsetRedelivered
is set then the JMS properties for redelivery and delivery count of messages pulled within this transaction are updated- Parameters:
transactionId
- transaction idsetRedelivered
- specifies JMS redelivery settingcallback
- async completion callback
-
cleanUpExpiredMessages
Deletes all expired messages from the queue- Throws:
QueueException
- on error
-
getCleanUpInterval
Returns the cleanup interval in milliseconds- Returns:
- interval
- Throws:
QueueException
- on error
-
setCleanUpInterval
public void setCleanUpInterval(long cleanUpInterval) Sets the cleanup interval.- Parameters:
cleanUpInterval
- cleanup interval.
-
getNumberQueueMessages
Returns the number of messages actually stored in the queue- Returns:
- number of messages
- Throws:
QueueException
- on error
-
getConsumingRate
public int getConsumingRate()Returns the consuming rate in Msgs/Sec- Returns:
- consuming rate
-
getProducingRate
public int getProducingRate()Returns the producing rate in Msgs/Sec- Returns:
- producing rate
-
getConsumedTotal
public int getConsumedTotal()Returns the total number of consumed messages- Returns:
- total number of consumed messages
-
getProducedTotal
public int getProducedTotal()Returns the total number of produced messages- Returns:
- total number of produced messages
-
resetCounters
public void resetCounters()Resets all consumed/produced counters -
getAndResetAverageLatency
public long getAndResetAverageLatency()Returns the average queue latency and resets it- Returns:
- average queue latency
-
getMonitorAlertThreshold
public int getMonitorAlertThreshold() -
getMessage
Get a message from the queue. The method returns the next available message dependend on priority and message time stamp. If no message is available (queue empty) then this method blocks until a message becomes available.- Parameters:
transactionId
-- Returns:
- The message
- Throws:
QueueException
- on error
-
getMessage
Get a message from the queue that matches the selector. The method returns the next available message dependend on priority and message time stamp. If no message is available (queue empty) then this method blocks until a message becomes available.- Parameters:
transactionId
- a valid pull transaction idselector
- A message selector- Returns:
- The message
- Throws:
QueueException
- on error
-
getMessage
public MessageEntry getMessage(Object transactionId, Selector selector, int viewId) throws QueueException Get the next message from a view. The method returns the next available message dependend on priority and message time stamp. If no message is available (queue empty) then this method blocks until a message becomes available.- Parameters:
transactionId
- a valid pull transaction idselector
- a message selectorviewId
- view id- Returns:
- The message
- Throws:
QueueException
- on error
-
getMessage
public MessageEntry getMessage(Object transactionId, long timeout) throws QueueException, QueueTimeoutException Get a message from the queue but wait only a specific period of time. The method returns the next available message dependend on priority and message time stamp. If no message is available (queue empty) then this method blocks until a message becomes available or a timeout occurs.- Parameters:
transactionId
- a valid pull transaction idtimeout
- a timeout in ms- Returns:
- The message
- Throws:
QueueException
- on errorQueueTimeoutException
- if a timeout occurs
-
getExpiredMessage
public MessageEntry getExpiredMessage(Object transactionId, long timeout) throws QueueException, QueueTimeoutException Get the next expired message from the queue but wait only a specific period of time. The method returns the next available expired message dependend on priority and message time stamp. If no expired message is available then this method blocks until a message becomes available or a timeout occurs.- Parameters:
transactionId
- a valid pull transaction idtimeout
- a timeout in ms- Returns:
- The message
- Throws:
QueueException
- on errorQueueTimeoutException
- if a timeout occurs
-
getMessage
public MessageEntry getMessage(Object transactionId, Selector selector, long timeout) throws QueueException, QueueTimeoutException Get a message from the queue that matches the selector but wait only a specific period of time. The method returns the next available message dependend on priority and message time stamp. If no message is available (queue empty) then this method blocks until a message becomes available or a timeout occurs.- Parameters:
transactionId
- a valid pull transaction idselector
- a message selectortimeout
- a timeout in ms- Returns:
- The message
- Throws:
QueueException
- on errorQueueTimeoutException
- if a timeout occurs
-
getMessage
public MessageEntry getMessage(Object transactionId, Selector selector, int viewId, long timeout) throws QueueException, QueueTimeoutException Get the next message from the view but wait only a specific period of time. The method returns the next available message dependend on priority and message time stamp. If no message is available (queue empty) then this method blocks until a message becomes available or a timeout occurs.- Parameters:
transactionId
- a valid pull transaction idselector
- a message selectorviewId
- view Idtimeout
- a timeout in ms- Returns:
- The message
- Throws:
QueueException
- on errorQueueTimeoutException
- if a timeout occurs
-
registerMessageProcessor
Registers a message processor. The message processor will be called asynchrounsly when a message is available.- Parameters:
messageProcessor
- message processor.
-
unregisterMessageProcessor
Unregisters a message processor.- Parameters:
messageProcessor
- message processor.
-
timeoutMessageProcessor
public void timeoutMessageProcessor(long registrationTime, int id) Removes a message processor which has been timed out.- Parameters:
registrationTime
- registration time.id
- id of the message processor.
-
acknowledgeMessage
public void acknowledgeMessage(Object transactionId, MessageIndex messageIndex, AsyncCompletionCallback callback) Async acknowledges a message that was fetched within a pull transaction. The size of the message will be returned as a result of the callback. This is another way to commit a pull transaction because it commits a single message of the transaction. All other messages of the transaction remain locked.- Parameters:
transactionId
- a valid pull transaction idmessageIndex
- a valid message indexcallback
- async completion callback
-
acknowledgeMessages
public void acknowledgeMessages(Object transactionId, List messageIndexList, AsyncCompletionCallback callback) Async acknowledges a list of messages that were fetched within a pull transaction. The size of the messages will be returned as a result of the callback.- Parameters:
transactionId
- a valid pull transaction idmessageIndexList
- a list of valid message indexescallback
- async completion callback
-
acknowledgeMessage
public void acknowledgeMessage(Object transactionId, MessageIndex messageIndex) throws QueueException Acknowledges a message that was fetched within a pull transaction. This is another way to commit a pull transaction because it commits a single message of the transaction. All other messages of the transaction remain locked.- Parameters:
transactionId
- a valid pull transaction idmessageIndex
- a valid message index- Throws:
QueueException
- on error
-
moveToTransactionReturnSize
public long moveToTransactionReturnSize(MessageIndex messageIndex, Object sourceTxId, Object destTxId) throws QueueException Moves a message with the given message index from the source to the destination transaction and returns its size.- Parameters:
messageIndex
- message index.sourceTxId
- source transaction id.destTxId
- destination transaction id.- Returns:
- size of the corresponding message in bytes
- Throws:
QueueException
- on error.
-
moveToTransaction
public void moveToTransaction(MessageIndex messageIndex, Object sourceTxId, Object destTxId) throws QueueException Moves a message with the given message index from the source to the destination transaction.- Parameters:
messageIndex
- message index.sourceTxId
- source transaction id.destTxId
- destination transaction id.- Throws:
QueueException
- on error.
-
moveToTransactionReturnSize
public long moveToTransactionReturnSize(MessageIndex messageIndex, Object destTxId) throws QueueException Moves a message with the given message index to the destination transaction and returns the message size. The source transaction is determined by the message index.- Parameters:
messageIndex
- message index.destTxId
- destination transaction id.- Returns:
- size of the corresponding message in bytes
- Throws:
QueueException
- on error.
-
moveToTransaction
Moves a message with the given message index to the destination transaction. The source transaction is determined by the message index.- Parameters:
messageIndex
- message index.destTxId
- destination transaction id.- Throws:
QueueException
- on error.
-
hasReceiver
Checks all registered receivers and, if set, their message selectors whether this message will be received by one of them.- Parameters:
message
-- Returns:
- has receiver or not
-
putMessage
Put a message into the queue- Parameters:
transactionId
- a valid push transaction idmessage
- the message- Throws:
QueueException
- on error
-
removeMessages
public void removeMessages(Object transactionId, List<MessageIndex> messageIndexes) throws QueueException Remove messages from a queue- Parameters:
transactionId
- a valid push transaction idmessageIndexes
- List of MessageIndexes to remove- Throws:
QueueException
- on error
-
getQueueIndex
Returns a current snapshot of the queue index (message indexes)- Returns:
- queue index
- Throws:
QueueException
- on error
-
getQueueIndex
Returns a current snapshot of the view- Parameters:
viewId
- the view id- Returns:
- queue index
- Throws:
QueueException
- on error
-
getMessageByIndex
Returns the message with that given key. If the message is not available anymore, the method returns null.- Parameters:
messageIndex
- message index- Returns:
- message entry
- Throws:
QueueException
- on error
-
removeMessageByIndex
Removes a message with that given key outside a queue transaction.- Parameters:
messageIndex
-- Throws:
QueueException
- if the message is locked by another consumer
-
getIndexEntry
Returns the actual index entry (the implementation of the MessageIndex class) used for this MessageIndex- Parameters:
messageIndex
-- Returns:
- index entry
- Throws:
QueueException
- on error
-
deleteContent
Removes all messages from the queue.- Throws:
QueueException
- on error
-
lockQueue
Locks this queue and holds it until unlockQueue is called.- Parameters:
txId
- local transactionId
-
unlockQueue
Unlocks this queue.- Parameters:
txId
- local transactionIdmarkAsyncActive
- blocks queue as async is active
-
unmarkAsyncActive
Unblocks this queue from async active- Parameters:
txId
- local transactionId
-
setCompositeStoreTransaction
Sets a CompositeStoreTransaction to be used as the current transaction. At the same time it disables prepare/commit/rollback calls inside this queue so that multiple queues can use the same transaction and prepare/commit/rollback is done outside.- Parameters:
txId
- local transactionIdct
- composite transaction
-
getCompositeStoreTransaction
Returns the current composite store transaction- Parameters:
txId
- local transactionId- Returns:
- composite transaction
-