org.openeai.jms.producer
Class PubSubProducer

java.lang.Object
  extended by org.openeai.OpenEaiObject
      extended by org.openeai.jms.producer.MessageProducer
          extended by org.openeai.jms.producer.PubSubProducer
All Implemented Interfaces:
SyncService

public class PubSubProducer
extends MessageProducer
implements SyncService

The PubSubProducer produces messages to a JMS Topic.

Version:
3.0 - 4 February 2003
Author:
Tod Jackson (tod@openeai.org), Steve Wheat (steve@openeai.org)
See Also:
PointToPointProducer, PubSubConsumer

Nested Class Summary
protected  class PubSubProducer.MonitorProducer
          This Thread will sleep for 30 seconds and then wake up and check the status of the producer by attempting to create/delete a TemporaryTopic.
protected  class PubSubProducer.ProducerShutdownHook
          This Thread will be started when the producer receives a shutdown signal from the os.
 
Field Summary
 
Fields inherited from class org.openeai.jms.producer.MessageProducer
COMMAND_NAME, m_messages, MESSAGE_ID, MESSAGE_NAME, NON_PERSISTENT_DELIVERY, PERSISTENT_DELIVERY, STARTED, STOPPED, STOPPING
 
Fields inherited from class org.openeai.OpenEaiObject
logger
 
Constructor Summary
PubSubProducer()
           
PubSubProducer(ProducerConfig pConfig)
          As AppConfig reads through an application's deployment document, it will build a ProducerConfig Java object and pass that object to this constructor.
 
Method Summary
 void commit()
          Commit any transactions pending on this publisher and on its LoggingProducer.
 void createSync(ActionableEnterpriseObject theObject)
          Create Sync message production.
 javax.jms.TextMessage createTextMessage()
          Convenience method that allows calling applications to use this producer to create a JMS TextMessage that is used during message production.
 void deleteSync(java.lang.String deleteAction, ActionableEnterpriseObject theObject)
          Delete Sync message production.
 PubSubProducer getLoggingProducer()
          Returns the Logging Producer associated to this producer which is simply another PubSubProducer that may be configured in the deployment document to publish messages published by this producer to a second "logging" destination.
 javax.jms.Topic getTopic()
          Returns the Producers's Topic object.
 javax.jms.TopicConnection getTopicConnection()
          Returns the Producers's TopicConnection object.
 javax.jms.TopicConnectionFactory getTopicConnectionFactory()
          Returns the Producers's TopicConnectionFactory object.
 javax.jms.TopicPublisher getTopicPublisher()
          Returns the Producers's TopicPublisher object.
 javax.jms.TopicSession getTopicSession()
          Returns the Producers's TopicSession object.
protected  void init(java.util.Properties props)
          Invokes MessageProducer.init(Properties).
 boolean publishMessage(ActionableEnterpriseObject theObject, org.jdom.Document doc)
          Publishes the message passed in to the Topic the producer is connected to.
 boolean publishMessage(javax.jms.Message aMessage)
          Publishes the message passed in to the Topic the producer is connected to.
 void rollback()
          Rollback any transactions pending on this publisher and on its LoggingProducer.
 void setLoggingProducer(PubSubProducer producer)
          Sets the Logging Producer associated to this producer which is simply another PubSubProducer that may be configured in the deployment document to publish messages published by this producer to a second "logging" destination.
 void setTopic(javax.jms.Topic topic)
          Sets the Producers's Topic object.
 void setTopicConnection(javax.jms.TopicConnection topicConnection)
          Sets the Producers's TopicConnection object.
 void setTopicConnectionFactory(javax.jms.TopicConnectionFactory tcf)
          Sets the Producers's TopicConnectionFactory object.
 void setTopicPublisher(javax.jms.TopicPublisher topicPublisher)
          Sets the Producers's TopicPublisher object.
 void setTopicSession(javax.jms.TopicSession session)
          Sets the Producers's TopicSession object.
 boolean start()
           
 void startMonitor()
          This method starts the Producer's "Monitor Thread".
 boolean startPublisher()
          Starts the producer making it ready to publish messages to the Topic that it connects to.
 void stop()
           
 void stopMonitor()
          This method stops the Producer's "Monitor Thread" so it won't attempt to restart the producer.
 void stopPublisher()
          Attempts to cleanly shutdown the Producer.
 void updateSync(ActionableEnterpriseObject theObject)
          Update Sync message production.
 
Methods inherited from class org.openeai.jms.producer.MessageProducer
getAcknowledgementMode, getConnectionFactoryName, getDefaultCommandName, getDeliveryMode, getDestinationName, getInitialContext, getInitialContextFactory, getMessageSeq, getPassword, getProducerId, getProducerId, getProducerIdUrl, getProducerName, getProducerStatus, getProviderUrl, getSecurityCredentials, getSecurityPrincipal, getStartOnInitialization, getTransacted, getUserName, incrementMessageSequence, isStarted, setAcknowledgementMode, setConnectionFactoryName, setDefaultCommandName, setDeliveryMode, setDestinationName, setInitialContextFactory, setMessageSeq, setPassword, setProducerId, setProducerId, setProducerIdUrl, setProducerName, setProducerStatus, setProviderUrl, setSecurityCredentials, setSecurityPrincipal, setStartOnInitialization, setTransacted, setUserName
 
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
 
Methods inherited from interface org.openeai.transport.SyncService
getProducerId, incrementMessageSequence, setProducerId
 

Constructor Detail

PubSubProducer

public PubSubProducer()

PubSubProducer

public PubSubProducer(ProducerConfig pConfig)
               throws java.io.IOException,
                      javax.jms.JMSException
As AppConfig reads through an application's deployment document, it will build a ProducerConfig Java object and pass that object to this constructor. Then this producer will have all the information it needs to initialize itself which.

Parameters:
pConfig - org.openeai.config.ProducerConfig
Throws:
java.io.IOException
javax.jms.JMSException
See Also:
ProducerConfig, PointToPointProducer
Method Detail

getTopicConnectionFactory

public final javax.jms.TopicConnectionFactory getTopicConnectionFactory()
Returns the Producers's TopicConnectionFactory object.

See the JMS Specification to learn more about JMS objects.

Returns:
javax.jms.TopicConnectionFactory

setTopicConnectionFactory

public final void setTopicConnectionFactory(javax.jms.TopicConnectionFactory tcf)
Sets the Producers's TopicConnectionFactory object.

See the JMS Specification to learn more about JMS objects.

Parameters:
tcf - javax.jms.TopicConnectionFactory

getTopic

public final javax.jms.Topic getTopic()
Returns the Producers's Topic object.

See the JMS Specification to learn more about JMS objects.

Returns:
javax.jms.Topic

setTopic

public final void setTopic(javax.jms.Topic topic)
Sets the Producers's Topic object.

See the JMS Specification to learn more about JMS objects.

Parameters:
topic - javax.jms.Topic

getTopicConnection

public final javax.jms.TopicConnection getTopicConnection()
Returns the Producers's TopicConnection object.

See the JMS Specification to learn more about JMS objects.

Returns:
javax.jms.TopicConnection

setTopicConnection

public final void setTopicConnection(javax.jms.TopicConnection topicConnection)
Sets the Producers's TopicConnection object.

See the JMS Specification to learn more about JMS objects.

Parameters:
topicConnection - javax.jms.TopicConnection

getTopicSession

public final javax.jms.TopicSession getTopicSession()
Returns the Producers's TopicSession object.

See the JMS Specification to learn more about JMS objects.

Returns:
javax.jms.TopicSession

setTopicSession

public final void setTopicSession(javax.jms.TopicSession session)
Sets the Producers's TopicSession object.

See the JMS Specification to learn more about JMS objects.

Parameters:
session - javax.jms.TopicSession

getTopicPublisher

public final javax.jms.TopicPublisher getTopicPublisher()
Returns the Producers's TopicPublisher object.

See the JMS Specification to learn more about JMS objects.

Returns:
javax.jms.TopicPublisher

setTopicPublisher

public final void setTopicPublisher(javax.jms.TopicPublisher topicPublisher)
Sets the Producers's TopicPublisher object.

See the JMS Specification to learn more about JMS objects.


setLoggingProducer

public final void setLoggingProducer(PubSubProducer producer)
Sets the Logging Producer associated to this producer which is simply another PubSubProducer that may be configured in the deployment document to publish messages published by this producer to a second "logging" destination.

Parameters:
producer - PubSubProducer the "logging producer"
See Also:
ProducerConfig

getLoggingProducer

public final PubSubProducer getLoggingProducer()
Returns the Logging Producer associated to this producer which is simply another PubSubProducer that may be configured in the deployment document to publish messages published by this producer to a second "logging" destination.

Returns:
PubSubProducer the "logging producer"
See Also:
ProducerConfig

stopMonitor

public void stopMonitor()
This method stops the Producer's "Monitor Thread" so it won't attempt to restart the producer.

When the producer is started it starts a Thread that monitors the Producer's connection to the broker. If that connection is broken for some reason, that "Monitor Thread" will attempt to restart the producer. This continues indefinitely until the producer is able to re-connect to the broker.

This method allows an application to in effect stop that monitor thread so they can shut the producer down without it restarting itself.


startMonitor

public void startMonitor()
This method starts the Producer's "Monitor Thread". This is a thread that runs for the life of the producer and checks the status of the producer's connection to the broker every thirty seconds. If that connection is broken for some reason, the Monitor Thread will attempt to restart the producer, re-connecting it to the broker. It will continue to do this until either the producer is able to re-connect or the producer is shutdown.


stop

public final void stop()
Specified by:
stop in class MessageProducer

stopPublisher

public final void stopPublisher()
Attempts to cleanly shutdown the Producer. This includes closing all JMS resources (TopicPublisher, TopicSession and TopicConnection). If errors occur, it will log those errors as warnings. However, regardless of the outcome of the "clean" shutdown attempt, the producer will be stopped. This method is called anytime the producer detects connection problems to the broker or when specifically called from an application or gateway using this Producer.

See Also:
PubSubProducer.MonitorProducer

commit

public final void commit()
                  throws javax.jms.JMSException
Commit any transactions pending on this publisher and on its LoggingProducer.

Throws:
javax.jms.JMSException

rollback

public final void rollback()
                    throws javax.jms.JMSException
Rollback any transactions pending on this publisher and on its LoggingProducer.

Throws:
javax.jms.JMSException

start

public final boolean start()
                    throws javax.jms.JMSException
Specified by:
start in class MessageProducer
Throws:
javax.jms.JMSException

startPublisher

public final boolean startPublisher()
                             throws javax.jms.JMSException
Starts the producer making it ready to publish messages to the Topic that it connects to. This follows the typical JMS pattern of starting a message producer. This includes:

Returns:
boolean indicating whether or not the start was successful.
Throws:
javax.jms.JMSException
See Also:
PointToPointProducer.startProducer()

createTextMessage

public final javax.jms.TextMessage createTextMessage()
Convenience method that allows calling applications to use this producer to create a JMS TextMessage that is used during message production. This is used most commonly by the OpenEAI Message Object API (MOA) foundation.

Returns:
a JMS TextMessage

publishMessage

public final boolean publishMessage(javax.jms.Message aMessage)
                             throws javax.jms.JMSException
Publishes the message passed in to the Topic the producer is connected to. If an error occurs publishing the message the first time, the producer will be restarted and the producer will attempt to publish the message again. If it cannot successfully restart and re-publish the message, an exception will be thrown.

If the "logging producer" is started, the message will also be published to the Topic it is connected to.

Parameters:
aMessage - javax.jms.Message the message to produce
Throws:
javax.jms.JMSException - if errors occur.

publishMessage

public boolean publishMessage(ActionableEnterpriseObject theObject,
                              org.jdom.Document doc)
                       throws TransportException
Publishes the message passed in to the Topic the producer is connected to. If an error occurs publishing the message the first time, the producer will be restarted and the producer will attempt to publish the message again. If it cannot successfully restart and re-publish the message, an exception will be thrown.

If the "logging producer" is started, the message will also be published to the Topic it is connected to.

Specified by:
publishMessage in interface SyncService
Parameters:
theObject - the ActionableEnterpriseObject on which the action is being performed
doc - the XML document that has been built from the contents of theObject
Throws:
TransportExceptom - if errors occur.
TransportException

createSync

public void createSync(ActionableEnterpriseObject theObject)
                throws TransportException
Description copied from interface: SyncService
Create Sync message production. Builds an XML document (using the primed create sync document as a baseline) out of the current contents of the object. While building the XML Create Sync document, it will validate contents of the object checking for any malformed, missing or invalid fields. Field data values are also checked for validitity against the EnterpriseObjects document. Publishes the XML document in a JMS message to the topic connected to by producer.

Specified by:
createSync in interface SyncService
Throws:
TransportException

updateSync

public void updateSync(ActionableEnterpriseObject theObject)
                throws TransportException
Description copied from interface: SyncService
Update Sync message production. Builds an XML document (using the primed update sync document as a "template") out of the current contents of the object. It will use the current contents of the object as the NewData portion of the message and it will use the m_baseline object as the Baseline portion of the message. The m_baseline object is set when this object was "queried" for previously. While building the XML Update Sync document, it will validate contents of the object checking for any malformed, missing or invalid fields. Field data values are also checked for validitity against the EnterpriseObjects document. Publishes the XML document in a JMS message to the topic connected to by producer.

Specified by:
updateSync in interface SyncService
Throws:
TransportException

deleteSync

public void deleteSync(java.lang.String deleteAction,
                       ActionableEnterpriseObject theObject)
                throws TransportException
Description copied from interface: SyncService
Delete Sync message production. Builds an XML document (using the primed delete sync document as a baseline) out of the current contents of the object. While building the XML Delete Sync document, it will validate contents of the object checking for any malformed, missing or invalid fields. Field data values are also checked for validitity against the EnterpriseObjects document. Publishes the XML document in a JMS message to the topic connected to by producer.

Specified by:
deleteSync in interface SyncService
Parameters:
deleteAction - String delete action ('purge' or 'delete')

Throws:
TransportException

init

protected void init(java.util.Properties props)
             throws java.io.IOException
Invokes MessageProducer.init(Properties). Additionally, adds the shutdown hook.

Overrides:
init in class MessageProducer
Parameters:
props - Properties
Throws:
java.io.IOException
See Also:
MessageProducer.init(Properties)


Copyright © 2002,2003 OpenEAI Software Foundation