com.go.trove.util.tq
Class TransactionQueue

java.lang.Object
  |
  +--com.go.trove.util.tq.TransactionQueue

public class TransactionQueue
extends java.lang.Object

TransactionQueue processes Transactions concurrently using threads obtained from a ThreadPool. When a transaction is enqueued, it goes into a waiting queue, and it is serviced as soon as a thread is available.

Version:
31 , 01/02/15
Author:
Brian S O'Neill

Constructor Summary
TransactionQueue(ThreadPool tp, int maxSize, int maxThreads)
           
TransactionQueue(ThreadPool tp, java.lang.String name, int maxSize, int maxThreads)
           
 
Method Summary
 void addTransactionQueueListener(TransactionQueueListener listener)
           
 void addUncaughtExceptionListener(UncaughtExceptionListener listener)
           
 void applyProperties(PropertyMap properties)
          Understands and applies the following integer properties.
 boolean enqueue(Transaction transaction)
          Enqueues a transaction that will be serviced when a worker is available.
 long getIdleTimeout()
          Returns the timeout (in milliseconds) that the TransactionQueue will wait inactive before going into an idle state.
 int getMaximumSize()
          Returns the maximum allowed number of queued transactions.
 int getMaximumThreads()
          Returns the maximum allowed number of worker threads.
 java.lang.String getName()
          Returns the name of this TransactionQueue.
 int getQueueSize()
          Returns the number of currently queued transactions.
 TransactionQueueData getStatistics()
          Returns a snapshot of the statistics on this TransactionQueue.
 int getThreadCount()
          Returns the current amount of worker threads.
 long getTransactionTimeout()
          Returns the timeout (in milliseconds) to wait before an enqueued transaction expires.
 void idle()
          Make this TransactionQueue go into idle mode and allow it to be reclaimed by the garbage collector if it is no longer used.
 void removeTransactionQueueListener(TransactionQueueListener listener)
           
 void removeUncaughtExceptionListener(UncaughtExceptionListener listener)
           
 void resetStatistics()
          Resets all time lapse statistics.
 boolean resume()
          Resumes processing of transactions in the queue if suspend was called.
 void setIdleTimeout(long timeout)
          Sets the timeout (in milliseconds) for the TransactionQueue to wait inactive before going into an idle state.
 void setMaximumSize(int max)
          Setting the max size to zero disables enqueueing.
 void setMaximumThreads(int max)
           
 void setTransactionTimeout(long timeout)
          Sets the timeout (in milliseconds) to wait before an enqueued transaction expires.
 void suspend()
          Suspends processing of transactions in the queue until resume is called.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TransactionQueue

public TransactionQueue(ThreadPool tp,
                        int maxSize,
                        int maxThreads)

TransactionQueue

public TransactionQueue(ThreadPool tp,
                        java.lang.String name,
                        int maxSize,
                        int maxThreads)
Method Detail

setIdleTimeout

public void setIdleTimeout(long timeout)
Sets the timeout (in milliseconds) for the TransactionQueue to wait inactive before going into an idle state. When the TransactionQueue is idle, there are no internal worker threads. A negative value specifies that the TransactionQueue should never automatically go into idle mode.
See Also:
idle()

getIdleTimeout

public long getIdleTimeout()
Returns the timeout (in milliseconds) that the TransactionQueue will wait inactive before going into an idle state. The default value is the same as the ThreadPool's idle timeout.
See Also:
idle(), ThreadPool.getIdleTimeout()

setTransactionTimeout

public void setTransactionTimeout(long timeout)
Sets the timeout (in milliseconds) to wait before an enqueued transaction expires. If a worker receives an expired transaction, it is cancelled. A negative timeout specifies that enqueued transactions never expire.

getTransactionTimeout

public long getTransactionTimeout()
Returns the timeout (in milliseconds) to wait before an enqueued transaction expires. The default value is -1, indicating that enqueued transactions never expire.

getName

public java.lang.String getName()
Returns the name of this TransactionQueue.

getMaximumSize

public int getMaximumSize()
Returns the maximum allowed number of queued transactions.

setMaximumSize

public void setMaximumSize(int max)
Setting the max size to zero disables enqueueing.

getMaximumThreads

public int getMaximumThreads()
Returns the maximum allowed number of worker threads.

setMaximumThreads

public void setMaximumThreads(int max)

enqueue

public boolean enqueue(Transaction transaction)
Enqueues a transaction that will be serviced when a worker is available. If the queue is full or cannot accept new transactions, the transaction is not enqueued, and false is returned.
Returns:
true if enqueued, false if queue is full or cannot accept new transactions.

suspend

public void suspend()
Suspends processing of transactions in the queue until resume is called. If suspend is called on a TransactionQueue that is already suspended, the call has no effect.

resume

public boolean resume()
Resumes processing of transactions in the queue if suspend was called. If resume is called on a TransactionQueue that is already running, the call has no effect, but true is still returned.
Returns:
false if couldn't resume because no threads available from pool.

idle

public void idle()
Make this TransactionQueue go into idle mode and allow it to be reclaimed by the garbage collector if it is no longer used. Any pending transactions will be serviced, and any servicing transactions will finish. If any transactions are added to the TransactionQueue while idle, it will reactivate itself. New TransactionQueues start out in an idle state.
See Also:
setIdleTimeout(long), getIdleTimeout()

addTransactionQueueListener

public void addTransactionQueueListener(TransactionQueueListener listener)

removeTransactionQueueListener

public void removeTransactionQueueListener(TransactionQueueListener listener)

addUncaughtExceptionListener

public void addUncaughtExceptionListener(UncaughtExceptionListener listener)

removeUncaughtExceptionListener

public void removeUncaughtExceptionListener(UncaughtExceptionListener listener)

getQueueSize

public int getQueueSize()
Returns the number of currently queued transactions.

getThreadCount

public int getThreadCount()
Returns the current amount of worker threads.

getStatistics

public TransactionQueueData getStatistics()
Returns a snapshot of the statistics on this TransactionQueue.

resetStatistics

public void resetStatistics()
Resets all time lapse statistics.

applyProperties

public void applyProperties(PropertyMap properties)
Understands and applies the following integer properties.