Class AbstractQueue

  • Direct Known Subclasses:
    ClusteredQueue, CompositeQueue, MessageQueue, TopicBroker

    public abstract class AbstractQueue
    extends java.lang.Object
    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 Detail

      • maxMessages

        protected volatile int maxMessages
      • persistenceMode

        protected volatile int persistenceMode
      • temporary

        protected boolean temporary
      • receiverCount

        protected int receiverCount
      • cleanUpInterval

        protected long cleanUpInterval
      • consumerMode

        protected int consumerMode
    • Constructor Detail

      • AbstractQueue

        public AbstractQueue()
    • Method Detail

      • getQueueName

        public java.lang.String getQueueName()
        Returns the queue name
        Returns:
        queue name
      • setQueueName

        public void setQueueName​(java.lang.String queueName)
        Set the queue name. Will be called from queue manager
        Parameters:
        queueName - queue name
      • getLocalName

        public java.lang.String getLocalName()
        Returns the local name.
        Returns:
        local name.
      • setLocalName

        public void setLocalName​(java.lang.String localName)
        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

        public void startAccounting​(java.lang.Object accountingProfile)
      • flushAccounting

        public void flushAccounting()
      • stopAccounting

        public void stopAccounting()
      • addWireTapSubscriber

        public void addWireTapSubscriber​(java.lang.String name,
                                         WireTapSubscriber subscriber)
      • removeWireTapSubscriber

        public void removeWireTapSubscriber​(java.lang.String name,
                                            WireTapSubscriber subscriber)
      • setQueueReceiverListener

        public void setQueueReceiverListener​(QueueReceiverListener queueReceiverListener)
      • getFlowController

        public FlowController getFlowController()
        Returns the flow controller.
        Returns:
        flow controller.
      • setFlowController

        public void setFlowController​(FlowController flowController)
        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.
      • isRunning

        public boolean isRunning()
        Returns if the queue is running or not
        Returns:
        true/false
      • buildPreparedTransaction

        public java.lang.Object buildPreparedTransaction​(PrepareLogRecord logRecord)
                                                  throws QueueException
        Builds a new QueueTransaction on base of the PrepareLogRecord.
        Returns:
        transaction id
        Throws:
        QueueException - on error
      • createView

        public int createView​(Selector selector)
        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

        public abstract java.lang.Object createPushTransaction()
                                                        throws QueueException
        Creates a new push transaction and returns a unique transaction id
        Returns:
        transaction id
        Throws:
        QueueException - on error
      • createPullTransaction

        public abstract java.lang.Object createPullTransaction()
                                                        throws QueueException
        Creates a new pull transaction and returns a unique transaction id
        Returns:
        transaction id
        Throws:
        QueueException - on error
      • selectBaseQueue

        public AbstractQueue 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​(java.lang.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 id
        globalTransactionId - global transaction id
        Throws:
        QueueException - on error
      • commit

        public abstract void commit​(java.lang.Object localtransactionId,
                                    XidImpl globalTransactionId)
                             throws QueueException
        Commits a prepared transaction.
        Parameters:
        localtransactionId - local transaction id
        globalTransactionId - global transaction id
        Throws:
        QueueException - on error
      • commit

        public abstract void commit​(java.lang.Object transactionId)
                             throws QueueException
        Commit the transaction with the given transaction id
        Parameters:
        transactionId - transaction id
        Throws:
        QueueException - on error
      • commit

        public abstract void commit​(java.lang.Object transactionId,
                                    AsyncCompletionCallback callback)
        Asynchronously commits the transaction with the given transaction id
        Parameters:
        transactionId - transaction id
        callback - async completion callback
      • rollback

        public abstract void rollback​(java.lang.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 flag setRedelivered is set then the JMS properties for redelivery and delivery count of messages pulled within this transaction are updated.
        Parameters:
        transactionId - transaction id
        globalTransactionId - global transaction id
        setRedelivered - specifies JMS redelivery setting
        Throws:
        QueueException - on error
      • rollback

        public abstract void rollback​(java.lang.Object transactionId,
                                      boolean setRedelivered)
                               throws QueueException
        Rolls back the transaction with the given transaction id. If the flag setRedelivered is set then the JMS properties for redelivery and delivery count of messages pulled within this transaction are updated
        Parameters:
        transactionId - transaction id
        setRedelivered - specifies JMS redelivery setting
        Throws:
        QueueException - on error
      • rollback

        public abstract void rollback​(java.lang.Object transactionId,
                                      boolean setRedelivered,
                                      AsyncCompletionCallback callback)
        Asynchronously rolls back the transaction with the given transaction id. If the flag setRedelivered is set then the JMS properties for redelivery and delivery count of messages pulled within this transaction are updated
        Parameters:
        transactionId - transaction id
        setRedelivered - specifies JMS redelivery setting
        callback - async completion callback
      • cleanUpExpiredMessages

        public void cleanUpExpiredMessages()
                                    throws QueueException
        Deletes all expired messages from the queue
        Throws:
        QueueException - on error
      • getCleanUpInterval

        public long getCleanUpInterval()
                                throws QueueException
        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

        public long getNumberQueueMessages()
                                    throws QueueException
        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
      • getMonitorAlertThreshold

        public int getMonitorAlertThreshold()
      • getMessage

        public MessageEntry getMessage​(java.lang.Object transactionId)
                                throws QueueException
        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

        public MessageEntry getMessage​(java.lang.Object transactionId,
                                       Selector selector)
                                throws QueueException
        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 id
        selector - A message selector
        Returns:
        The message
        Throws:
        QueueException - on error
      • getMessage

        public MessageEntry getMessage​(java.lang.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 id
        selector - a message selector
        viewId - view id
        Returns:
        The message
        Throws:
        QueueException - on error
      • getMessage

        public MessageEntry getMessage​(java.lang.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 id
        timeout - a timeout in ms
        Returns:
        The message
        Throws:
        QueueException - on error
        QueueTimeoutException - if a timeout occurs
      • getExpiredMessage

        public MessageEntry getExpiredMessage​(java.lang.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 id
        timeout - a timeout in ms
        Returns:
        The message
        Throws:
        QueueException - on error
        QueueTimeoutException - if a timeout occurs
      • getMessage

        public MessageEntry getMessage​(java.lang.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 id
        selector - a message selector
        timeout - a timeout in ms
        Returns:
        The message
        Throws:
        QueueException - on error
        QueueTimeoutException - if a timeout occurs
      • getMessage

        public MessageEntry getMessage​(java.lang.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 id
        selector - a message selector
        viewId - view Id
        timeout - a timeout in ms
        Returns:
        The message
        Throws:
        QueueException - on error
        QueueTimeoutException - if a timeout occurs
      • registerMessageProcessor

        public void registerMessageProcessor​(MessageProcessor messageProcessor)
        Registers a message processor. The message processor will be called asynchrounsly when a message is available.
        Parameters:
        messageProcessor - message processor.
      • unregisterMessageProcessor

        public void unregisterMessageProcessor​(MessageProcessor messageProcessor)
        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​(java.lang.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 id
        messageIndex - a valid message index
        callback - async completion callback
      • acknowledgeMessages

        public void acknowledgeMessages​(java.lang.Object transactionId,
                                        java.util.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 id
        messageIndexList - a list of valid message indexes
        callback - async completion callback
      • acknowledgeMessage

        public void acknowledgeMessage​(java.lang.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 id
        messageIndex - a valid message index
        Throws:
        QueueException - on error
      • moveToTransactionReturnSize

        public long moveToTransactionReturnSize​(MessageIndex messageIndex,
                                                java.lang.Object sourceTxId,
                                                java.lang.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,
                                      java.lang.Object sourceTxId,
                                      java.lang.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,
                                                java.lang.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

        public void moveToTransaction​(MessageIndex messageIndex,
                                      java.lang.Object destTxId)
                               throws QueueException
        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

        public 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.
        Parameters:
        message -
        Returns:
        has receiver or not
      • putMessage

        public abstract void putMessage​(java.lang.Object transactionId,
                                        MessageImpl message)
                                 throws QueueException
        Put a message into the queue
        Parameters:
        transactionId - a valid push transaction id
        message - the message
        Throws:
        QueueException - on error
      • removeMessages

        public void removeMessages​(java.lang.Object transactionId,
                                   java.util.List<MessageIndex> messageIndexes)
                            throws QueueException
        Remove messages from a queue
        Parameters:
        transactionId - a valid push transaction id
        messageIndexes - List of MessageIndexes to remove
        Throws:
        QueueException - on error
      • getQueueIndex

        public java.util.SortedSet getQueueIndex()
                                          throws QueueException
        Returns a current snapshot of the queue index (message indexes)
        Returns:
        queue index
        Throws:
        QueueException - on error
      • getQueueIndex

        public java.util.SortedSet getQueueIndex​(int viewId)
                                          throws QueueException
        Returns a current snapshot of the view
        Parameters:
        viewId - the view id
        Returns:
        queue index
        Throws:
        QueueException - on error
      • getMessageByIndex

        public MessageEntry getMessageByIndex​(MessageIndex messageIndex)
                                       throws QueueException
        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

        public void removeMessageByIndex​(MessageIndex messageIndex)
                                  throws QueueException
        Removes a message with that given key outside a queue transaction.
        Parameters:
        messageIndex -
        Throws:
        QueueException - if the message is locked by another consumer
      • getIndexEntry

        public MessageIndex getIndexEntry​(MessageIndex messageIndex)
                                   throws QueueException
        Returns the actual index entry (the implementation of the MessageIndex class) used for this MessageIndex
        Parameters:
        messageIndex -
        Returns:
        index entry
        Throws:
        QueueException - on error
      • lockQueue

        public void lockQueue​(java.lang.Object txId)
        Locks this queue and holds it until unlockQueue is called.
        Parameters:
        txId - local transactionId
      • unlockQueue

        public void unlockQueue​(java.lang.Object txId,
                                boolean markAsyncActive)
        Unlocks this queue.
        Parameters:
        txId - local transactionId
        markAsyncActive - blocks queue as async is active
      • unmarkAsyncActive

        public void unmarkAsyncActive​(java.lang.Object txId)
        Unblocks this queue from async active
        Parameters:
        txId - local transactionId
      • setCompositeStoreTransaction

        public void setCompositeStoreTransaction​(java.lang.Object txId,
                                                 CompositeStoreTransaction ct)
        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 transactionId
        ct - composite transaction
      • getCompositeStoreTransaction

        public CompositeStoreTransaction getCompositeStoreTransaction​(java.lang.Object txId)
        Returns the current composite store transaction
        Parameters:
        txId - local transactionId
        Returns:
        composite transaction