org.openeai.jms.consumer
Class PubSubMessageBalancer


java.lang.Object

  |

  +--org.openeai.OpenEaiObject

        |

        +--org.openeai.jms.consumer.PubSubMessageBalancer


public class PubSubMessageBalancer
extends OpenEaiObject

This class is used by all PubSubConsumers to balance multiple instances of sync consumers. Since PubSub consumers all consume every message delivered to a topic (unlike PointToPointConsumers consuming from a Queue) they need a way to determine if another consumer is already processing the message. This is accomplished via this class and a property on the JMS Message (MESSAGE_ID) which popultated when the message is published from the source by the OpenEAI foundation APIs.

This MESSAGE_ID is unique among all messages published and is maintained automatically by the OpenEAI message production foundation (PubSubProducers and JMS Message Objects).

This particular Balancer uses a pre-defined database repository to store the MESSAGE_IDs and to determine if another consumer is processing or has processed the message.

Version:
3.0 beta2 - 28 January 2003
Author:
Tod Jackson (tod@openeai.org), Steve Wheat (steve@openeai.org)

Field Summary
 
Fields inherited from class org.openeai.OpenEaiObject
logger
 
Constructor Summary
PubSubMessageBalancer(DbConnectionPoolConfig dbConfig)
          This is the constructor used by PubSubConsumers when they initialize themselves.
 
Method Summary
 boolean canConsumerProcess(java.lang.String messageId)
          This is the method called by the PubSubConsumer to determine if it's safe for this consumer to process the message it consumed.
 
Methods inherited from class org.openeai.OpenEaiObject
addLog4jProperty, getAppName, getDebug, getFromAddr, getLog4jProperties, 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

PubSubMessageBalancer


public PubSubMessageBalancer(DbConnectionPoolConfig dbConfig)
                      throws java.io.IOException
This is the constructor used by PubSubConsumers when they initialize themselves. They pass the DbConnectionPoolConfig object associated to the Consumer to this constructor and then the balancer instantiates an EnterpriseConnectionPool that will be used to determine if another consumer is processing the message or not.

Method Detail

canConsumerProcess


public final boolean canConsumerProcess(java.lang.String messageId)
                                 throws java.sql.SQLException
This is the method called by the PubSubConsumer to determine if it's safe for this consumer to process the message it consumed. This method tries to insert the message id into the database store, if the insert succeeds it means no other consumer is processing the message. If the insert fails, it queries for the message id and if the message id is found on the query, it means another consumer is already processing the message.

Returns:
true if the consumer can process the message, false if another consumer is already processing the message.
Throws:
java.sql.SQLException - if errors occur querying for the id after a failed insert. NOTE: if any failures occur, the consumer will process the message because at that point it doesn't know if another consumer's processing the message so it must for safeties sake.


Copyright © 2002, OpenEAI Software Foundation