org.openeai.jms.producer
Class TempQueuePool

java.lang.Object
  extended by org.openeai.OpenEaiObject
      extended by org.openeai.jms.producer.TempQueuePool

public class TempQueuePool
extends OpenEaiObject

The TempQueuePool contains a list of PooledTempQueue objects that will be used by a PointToPointProducer's QueueRequestor when a request is produced. The TempQueuePool is responsible for determining if a PooledTempQueue is in use and if so, allocate another one for temporary use.

Version:
3.0 - 28 January 2003
Author:
Tod Jackson (tod@openeai.org), Steve Wheat (steve@openeai.org)
See Also:
PooledTempQueue, PointToPointProducer, QueueRequestor

Field Summary
 
Fields inherited from class org.openeai.OpenEaiObject
logger
 
Constructor Summary
TempQueuePool(int size, javax.jms.QueueSession session)
          This constructor is used by the PointToPointProducer to create this TempQueuePool and set it on the QueueRequestor associated to the producer.
 
Method Summary
 void close()
          Releases all JMS resources allocated to all PooledTempQueues in this pool.
 PooledTempQueue getPooledTempQueue()
          Returns a PooledTempQueue that contains a pre-established TempoaryQueue and QueueReceiver.
 int getPoolSize()
          Returns the size of the pool.
 void reinitializePooledTempQueue(PooledTempQueue pq)
          This will be called by the QueueRequestor if a Timeout occurs during a "request".
 void releasePooledTempQueue(PooledTempQueue pq)
          Releases a PooledTempQueue back to the pool making it available for retrieval again.
 void setPoolSize(int size)
          Sets the size of the pool.
 
Methods inherited from class org.openeai.OpenEaiObject
getAppName, getDebug, getFromAddr, getMailHost, getMailService, getProperties, getToAddr, initializeLog4j, initializeLog4j, initializeLog4j, setAppName, setDebug, setFromAddr, setMailHost, setMailService, setProperties, setToAddr
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TempQueuePool

public TempQueuePool(int size,
                     javax.jms.QueueSession session)
              throws javax.jms.JMSException
This constructor is used by the PointToPointProducer to create this TempQueuePool and set it on the QueueRequestor associated to the producer. The QueueRequestor will then use this pool to retrieve pre-established TemporaryQueues and QueueReceivers with which it will send requests on behalf of the producer.

Parameters:
size - int the size of the pool
session - javax.jms.QueueSession the QueueSession associated to the Producer creating this pool that will be used to create TemporaryQueues that are added to the pool via the PooledTempQueue object.
Throws:
javax.jms.JMSException
See Also:
QueueRequestor, PooledTempQueue
Method Detail

setPoolSize

public void setPoolSize(int size)
Sets the size of the pool.

Parameters:
size - int the size of the pool

getPoolSize

public int getPoolSize()
Returns the size of the pool.

Returns:
int the size of the pool

getPooledTempQueue

public PooledTempQueue getPooledTempQueue()
                                   throws javax.jms.JMSException
Returns a PooledTempQueue that contains a pre-established TempoaryQueue and QueueReceiver. If no available PooledTempQueues exist in the pool at the time of the request, a new one will be created. Then, when that resource is released back to the pool, it will be cleaned up so the pool size will remain constant over time.

The QueueRequestor object calls this method to retreive a PooledTempQueue from the pool when it produces a request on behalf of a PointToPointProducer.

Returns:
PooleTempQueue either an existing PooledTempQueue from the pool if one is available or a newly created one if an available one does not exist.
Throws:
javax.jms.JMSException - if an error occurs creating a new PooledTempQueue if an available one can't be retrieved from the pool.

releasePooledTempQueue

public void releasePooledTempQueue(PooledTempQueue pq)
                            throws javax.jms.JMSException
Releases a PooledTempQueue back to the pool making it available for retrieval again. If the PooledTempQueue passed in was not originally retrieved from the pool (because it was created dynamically) it will be deleted altogether.

If the PooledTempQueue passed in was originally retrieved from the pool, its status will be set back to "not in use" so it may be retrieved from the pool by subsequent calls.

The OpenEAI QueueRequestor object calls this method when it's finished sending a request and has consumed the response. If a request times out, the QueueRequestor will call the reinitializePooledTempQueue method.

Parameters:
pq - PooledTempQueue the PooledTempQueue to be released.
Throws:
javax.jms.JMSException - if an error occurs deleting the resources allocated to a PooledTempQueue that was not originally a part of the pool.
See Also:
reinitializePooledTempQueue(org.openeai.jms.producer.PooledTempQueue)

reinitializePooledTempQueue

public void reinitializePooledTempQueue(PooledTempQueue pq)
                                 throws javax.jms.JMSException
This will be called by the QueueRequestor if a Timeout occurs during a "request". If a timeout occurs we need to remove the PooledTempQueue from our pool and delete it (close and delete the temporary queue and receiver associated to the PooledTempQueue. Then, we need to add a new PooledTempQueue to our pool. If the PooleTempQueue passed in wasn't a member of our pool to begin with, we'll just delete it.

We have to do this because if we send requests to gateways that are down, the messages sit on the Queue until the next time the gateway is brought up. At that time, the gateway will see that it has requests to process and it will process and respond to those requests. By that time, the TempQueuePool may be in use by another request and we don't want the gateway to mistakenly respond to those requests using the request sent by the original request that timed out. Instead, we want the gateway to receive a "queue not found" error at that time. By removing the PooledTempQueue from the pool and deleting it, we're ensuring that any PooledTempQueue used when a timeout occurred isn't used again when the gateway starts processing messages again.

Parameters:
pq - PooledTempQueue the PooledTempQueue to be re-initialized.
Throws:
javax.jms.JMSException - if any errors occur re-initiallizing the PooledTempQueue.

close

public void close()
           throws javax.jms.JMSException
Releases all JMS resources allocated to all PooledTempQueues in this pool. This includes deleting the TemporaryQueues and closing the QueueReceivers associated to each PooledTempQueue.

Throws:
javax.jms.JMSException - if errors occur. However, it will continue to iterate through all PooledTempQueue objects closing them all and only throw the exception after all resources that could be released are. It will save up any exceptions that occur during the cleanup process and include those messages in the exception that it throws.


Copyright © 2002,2003 OpenEAI Software Foundation