org.openeai.jms.producer
Class PointToPointProducer

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

public class PointToPointProducer
extends MessageProducer
implements RequestService

The PointToPointProducer produces messages to a Queue. If the method being called to produce the message is 'produceRequest' the Producer will use the QueueRequestor object to produce the message and wait for a response from the consuming application. If the method called is 'produceMessage' it will not wait for a response.

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

Nested Class Summary
protected  class PointToPointProducer.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 TemporaryQueue.
protected  class PointToPointProducer.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
PointToPointProducer()
           
PointToPointProducer(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
 XmlEnterpriseObject create(ActionableEnterpriseObject theObject)
          Create 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.
 XmlEnterpriseObject delete(java.lang.String deleteAction, ActionableEnterpriseObject theObject)
          Delete message production.
 java.util.List generate(XmlEnterpriseObject keyObject, ActionableEnterpriseObject theObject)
          Generate message production.
 javax.jms.Queue getQueue()
          Returns the Producers's Queue object.
 javax.jms.QueueConnection getQueueConnection()
          Returns the Producers's QueueConnection object.
 javax.jms.QueueConnectionFactory getQueueConnectionFactory()
          Returns the Producers's QueueConnectionFactory object.
 QueueRequestor getQueueRequestor()
          Returns the Producers's QueueRequestor object.
 javax.jms.QueueSender getQueueSender()
          Returns the Producers's QueueSender object.
 javax.jms.QueueSession getQueueSession()
          Returns the Producers's QueueSession object.
 int getRequestTimeoutInterval()
          Returns the request timeout interval that will be used by this producer to determine when a timeout occurrs.
protected  void init(java.util.Properties props)
          Invokes MessageProducer.init(Properties).
 void produceMessage(javax.jms.Message aMessage)
          Deprecated. As of OpenEAI version 4.0
 org.jdom.Document produceRequest(ActionableEnterpriseObject theObject, org.jdom.Document doc)
          Uses the pre-started QueueRequestor to send a request to a consumer and wait for a response.
 javax.jms.Message produceRequest(javax.jms.Message aMessage)
          Uses the pre-started QueueRequestor to send a request to a consumer and wait for a response.
 java.util.List query(XmlEnterpriseObject keyObject, ActionableEnterpriseObject theObject)
          Query message production.
 void setQueue(javax.jms.Queue queue)
          Sets the Producers's Queue object.
 void setQueueConnection(javax.jms.QueueConnection queueConnection)
          Sets the Producers's QueueConnection object.
 void setQueueConnectionFactory(javax.jms.QueueConnectionFactory qcf)
          Sets the Producers's QueueConnectionFactory object.
 void setQueueRequestor(QueueRequestor queueRequestor)
          Sets the Producers's QueueRequestor object.
 void setQueueSender(javax.jms.QueueSender queueSender)
          Sets the Producers's QueueSender object.
 void setQueueSession(javax.jms.QueueSession session)
          Sets the Producers's QueueSession object.
 void setRequestTimeoutInterval(int timeout)
          Sets the request timeout interval that will be used by this producer to determine when a timeout occurrs.
 boolean start()
           
 void startMonitor()
          This method starts the Producer's "Monitor Thread".
 boolean startProducer()
          Starts the producer making it ready to produce messages to the Queue 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 stopProducer()
          Attempts to cleanly shutdown the Producer.
 XmlEnterpriseObject update(ActionableEnterpriseObject theObject)
          Update 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.RequestService
getProducerId, incrementMessageSequence, setProducerId
 

Constructor Detail

PointToPointProducer

public PointToPointProducer()

PointToPointProducer

public PointToPointProducer(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, PubSubProducer
Method Detail

init

protected void init(java.util.Properties props)
             throws java.io.IOException
Invokes MessageProducer.init(Properties). Additionally, since this is a PointToPointProducer it sets the default "request timeout interval" and the TempPoolSize based on information found in the deployment document for this Producer.

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

getRequestTimeoutInterval

public final int getRequestTimeoutInterval()
Returns the request timeout interval that will be used by this producer to determine when a timeout occurrs. The default value is 10000 or 10 seconds. This is how long the producer will wait on a response to a request it makes. If the response takes longer than this, it will catch a 'Timeout' exception from the QueueRequestor and try the request again. If the second attempt fails, it will throw a JMSException that will be caught by the requesting application.

Returns:
int timeout interval in milliseconds.

setRequestTimeoutInterval

public final void setRequestTimeoutInterval(int timeout)
Sets the request timeout interval that will be used by this producer to determine when a timeout occurrs. The default value is 10000 or 10 seconds. This is how long the producer will wait on a response to a request it makes. If the response takes longer than this, it will catch a 'Timeout' exception from the QueueRequestor and try the request again. If the second attempt fails, it will throw a JMSException that will be caught by the requesting application. This method can be called at runtime prior to sending a request if an application needs to use something larger than the default.

Parameters:
timeout - int timeout interval in milliseconds.

getQueueConnectionFactory

public final javax.jms.QueueConnectionFactory getQueueConnectionFactory()
Returns the Producers's QueueConnectionFactory object.

See the JMS Specification to learn more about JMS objects.

Returns:
javax.jms.QueueConnectionFactory

setQueueConnectionFactory

public final void setQueueConnectionFactory(javax.jms.QueueConnectionFactory qcf)
Sets the Producers's QueueConnectionFactory object.

See the JMS Specification to learn more about JMS objects.

Parameters:
qcf - javax.jms.QueueConnectionFactory

getQueue

public final javax.jms.Queue getQueue()
Returns the Producers's Queue object.

See the JMS Specification to learn more about JMS objects.

Returns:
javax.jms.Queue

setQueue

public final void setQueue(javax.jms.Queue queue)
Sets the Producers's Queue object.

See the JMS Specification to learn more about JMS objects.

Parameters:
queue - javax.jms.Queue

getQueueConnection

public final javax.jms.QueueConnection getQueueConnection()
Returns the Producers's QueueConnection object.

See the JMS Specification to learn more about JMS objects.

Returns:
javax.jms.QueueConnection

setQueueConnection

public final void setQueueConnection(javax.jms.QueueConnection queueConnection)
Sets the Producers's QueueConnection object.

See the JMS Specification to learn more about JMS objects.

Parameters:
queueConnection - javax.jms.QueueConnection

getQueueSession

public final javax.jms.QueueSession getQueueSession()
Returns the Producers's QueueSession object.

See the JMS Specification to learn more about JMS objects.

Returns:
javax.jms.QueueSession

setQueueSession

public final void setQueueSession(javax.jms.QueueSession session)
Sets the Producers's QueueSession object.

See the JMS Specification to learn more about JMS objects.

Parameters:
session - javax.jms.QueueSession

getQueueSender

public final javax.jms.QueueSender getQueueSender()
Returns the Producers's QueueSender object.

See the JMS Specification to learn more about JMS objects.

Returns:
javax.jms.QueueSender

setQueueSender

public final void setQueueSender(javax.jms.QueueSender queueSender)
Sets the Producers's QueueSender object.

See the JMS Specification to learn more about JMS objects.

Parameters:
queueSender - javax.jms.QueueSender

getQueueRequestor

public final QueueRequestor getQueueRequestor()
Returns the Producers's QueueRequestor object.

See the JMS Specification to learn more about JMS objects.

Returns:
org.openeai.jms.QueueRequestor
See Also:
QueueRequestor

setQueueRequestor

public final void setQueueRequestor(QueueRequestor queueRequestor)
Sets the Producers's QueueRequestor object.

See the JMS Specification to learn more about JMS objects.

Parameters:
queueRequestor - org.openeai.jms.producer.QueueRequestor
See Also:
QueueRequestor

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

stopProducer

public final void stopProducer()
Attempts to cleanly shutdown the Producer. This includes closing all JMS resources (QueueRequestor, QueueSession and QueueConnection). 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:
PointToPointProducer.MonitorProducer

start

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

startProducer

public boolean startProducer()
                      throws javax.jms.JMSException
Starts the producer making it ready to produce messages to the Queue 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:
PubSubProducer.startPublisher(), QueueRequestor

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

create

public XmlEnterpriseObject create(ActionableEnterpriseObject theObject)
                           throws TransportException
Description copied from interface: RequestService
Create message production. Builds an XML document (using the primed create document as a "template") out of the current contents of the object. While building the XML Create 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. Uses the producer passed in to send the XML document as a JMS request to the queue connected to by the producer which then processes the response checking for any errors in the response.

Specified by:
create in interface RequestService
Returns:
XmlEnterpriseObject a generic response which will indicate success or failure. If failure, any error information will be included in that result. The object returned is actually a org.openeai.moa.objects.Result object.

Throws:
TransportException

update

public XmlEnterpriseObject update(ActionableEnterpriseObject theObject)
                           throws TransportException
Description copied from interface: RequestService
Update message production. Builds an XML document (using the primed update document as a "template") out of the current contents of the object (this). It will use the current contents of the object as the NewData portion of the message and it will use this object's "baseline" object as the Baseline portion of the message. The "baseline" object is set when this object was "queried" for previously. While building the XML Update message, it will validate contents checking for any malformed, missing or invalid fields. Field data values are also checked for validitity against the EnterpriseObjects document. Uses the producer passed in to send the XML document as a JMS request to the queue connected to by the producer which then processes the response checking for any errors in the response.

Specified by:
update in interface RequestService
Returns:
XmlEnterpriseObject (Result) this will indicate the success or failure of the Update request. In an error condition, this will include any error information.

Throws:
TransportException

delete

public XmlEnterpriseObject delete(java.lang.String deleteAction,
                                  ActionableEnterpriseObject theObject)
                           throws TransportException
Description copied from interface: RequestService
Delete message production. Builds an XML document (using the primed delete document as a "template") out of the current contents of the object. While building the XML Delete 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. Uses the producer passed in to send the XML document as a JMS request to the queue connected to by the producer which then processes the response checking for any errors in the response.

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

Returns:
XmlEnterpriseObject a generic response which will indicate success or failure. If failure, any error information will be included in that result. The object returned is actually a org.openeai.moa.objects.Result object.

Throws:
TransportException

query

public java.util.List query(XmlEnterpriseObject keyObject,
                            ActionableEnterpriseObject theObject)
                     throws TransportException
Description copied from interface: RequestService
Query message production. Builds an XML document (using the primed query document as a "template") out of the current contents of the keyObject passed in. While building the XML Query message, it will validate contents of the keyObject checking for any malformed, missing or invalid fields. Field data values are also checked for validitity against the EnterpriseObjects document. Uses the producer passed in to send the XML document as a JMS request to the queue connected to by the producer which then processes the response checking for any errors in the response.

Specified by:
query in interface RequestService
Parameters:
keyObject - XmlEnterpriseObject to use as retreival arguments in the Query. The contents of this object are inserted into the Query document prior to sending the query request. Under normal conditions, this object is actually a LightweightPerson object since that's the most common query object used.

NOTE: This method should be over-ridden by lower level classes if the keyObject isn't a LightweightPerson.

Returns:
java.util.List this is a list of XmlEnterpriseObject objects (like BasicPerson, BasicEmployee etc.) provided by the authoritative source (the application consuming the query request).

Throws:
TransportException

generate

public java.util.List generate(XmlEnterpriseObject keyObject,
                               ActionableEnterpriseObject theObject)
                        throws TransportException
Description copied from interface: RequestService
Generate message production. Builds an XML document (using the primed generate document as a "template") out of the current contents of the object. While building the XML Generate 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. Uses the producer passed in to send the XML document as a JMS request to the queue connected to by the producer which then processes the response checking for any errors in the response.

Specified by:
generate in interface RequestService
Parameters:
keyObject - XmlEnterpriseObject to use as generation "seed" data (like an UnknownPerson for an InstitutionalIdentity-Generate-Request).

Returns:
java.util.List this is a list of XmlEnterpriseObject objects generated by the authoritative source (the application consuming the request to generate). Typically, this will be only one object (like an InstitutionalIdentity).

Throws:
TransportException

produceMessage

public final void produceMessage(javax.jms.Message aMessage)
                          throws javax.jms.JMSException
Deprecated. As of OpenEAI version 4.0

Creates a QueueSender and produces the message passed in to the Queue the producer is connected to. Does not wait for any response from the consumer of that message.

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

produceRequest

public final javax.jms.Message produceRequest(javax.jms.Message aMessage)
                                       throws javax.jms.JMSException
Uses the pre-started QueueRequestor to send a request to a consumer and wait for a response. If a JMSException occurs producing the request it will attempt to restart the Producer and try to send the message again. This typically occurs when there have been critical network issues and the Producer's Monitor has not restarted it yet.

Parameters:
aMessage - javax.jms.Message the message to send in the request
Returns:
javax.jms.Message the response from the consumer that processed the request
Throws:
javax.jms.JMSException - if errors occur and the producer can't successfully restart itself and re-send the message.

produceRequest

public final org.jdom.Document produceRequest(ActionableEnterpriseObject theObject,
                                              org.jdom.Document doc)
                                       throws TransportException
Uses the pre-started QueueRequestor to send a request to a consumer and wait for a response. If a JMSException occurs producing the request it will attempt to restart the Producer and try to send the message again. This typically occurs when there have been critical network issues and the Producer's Monitor has not restarted it yet.

Specified by:
produceRequest in interface RequestService
Parameters:
theObject - an ActionableEnterpriseObject that the action is being performed on
doc - the Document that was built from the content of the object
Returns:
Document the response from the consumer that processed the request
Throws:
TransportException - if errors occur and the producer can't successfully restart itself and re-send the message.


Copyright © 2002,2003 OpenEAI Software Foundation