biz.hammurapi.jms
Class Adapter

java.lang.Object
  extended by biz.hammurapi.config.ComponentBase
      extended by biz.hammurapi.jms.MessageProcessor
          extended by biz.hammurapi.jms.Adapter
All Implemented Interfaces:
biz.hammurapi.config.Component, biz.hammurapi.config.Context, biz.hammurapi.config.Restartable, biz.hammurapi.metrics.MeasurementCollector, biz.hammurapi.metrics.MeasurementConsumer

public abstract class Adapter
extends MessageProcessor

Base class for JMS adapters which operate on two queue pairs.

Author:
Pavel Vlasov

Field Summary
protected  int backEndAcknowledgeMode
           
protected  javax.jms.Connection backEndConnection
           
protected  javax.jms.ConnectionFactory backEndConnectionFactory
           
protected  javax.naming.Context backEndInitialContext
           
protected  long backEndRequestTimeToLive
           
protected  long backEndTimeout
           
protected  boolean isBackEndTransacted
           
protected  long replyTimeToLive
           
 
Fields inherited from class biz.hammurapi.jms.MessageProcessor
acknowledgeMode, connection, connectionFactory, initialContext, isTransacted, logger, restartCommand, worker
 
Fields inherited from class biz.hammurapi.config.ComponentBase
owner
 
Constructor Summary
Adapter()
           
 
Method Summary
protected  javax.jms.Session borrowBackEndSession()
          This implementation simply creates a new session.
protected  java.lang.Object getChild(java.lang.String name)
          Provides access to back-end destination, reply destinations, initial context, and connection in addition to objects accessible through superclass getChild() method.
protected  javax.jms.Message handleException(java.lang.Exception exception, javax.jms.Session frontEndSession)
          Method to report exceptions to fron-end (excluding JMS exceptions in front-end JMS objects).
protected  java.lang.String messageSelector(javax.jms.Message backEndRequest)
          Extracts message selector for reply back-end message from the back-end request message.
protected  void processMessage(javax.jms.Message request, javax.jms.Session session)
          Processes request message by passing to processRequest() and processResponse() methods.
protected abstract  javax.jms.Message processReply(javax.jms.Message backEndReply, javax.jms.Message frontEndRequest, javax.jms.Session frontEndSession, javax.jms.Session backEndSession)
          Processes back-end reply and forms reply to front-end.
protected abstract  javax.jms.Message processRequest(javax.jms.Message frontEndRequest, javax.jms.Session frontEndSession, javax.jms.Session backEndSession)
          Processes front-end request message and builds back-end request message.
protected  void releaseBackEndSession(javax.jms.Session session)
          This implementation simply closes the session.
 void setBackEndAcknowledgeMode(java.lang.String acknowledgeModeName)
          Back-end acknoledge mode.
 void setBackEndConnection(javax.jms.Connection connection)
          Explicitly sets back-end connection.
 void setBackEndConnectionFactory(java.lang.String connectionFactoryName)
          Back-end JMS connection name.
 void setBackEndDestination(java.lang.String destinationName)
          Back-end request destination (queue or topic) name.
 void setBackEndInitialContext(javax.naming.Context initialContext)
          Initial context to look-up back-end destinations and connection factory.
 void setBackEndReplyDestination(java.lang.String destinationName)
          Back-end reply destination (queue or topic) name.
 void setBackEndRequestTimeToLive(long backEndRequestTimeToLive)
          Time to live for back-end request
 void setBackEndTimeout(long backEndTimeout)
          Timeout for backend reply.
 void setBackEndTransacted(boolean isTransacted)
          Transactional attribute of back-end JMS Session.
 void setBackEndUser(java.lang.String user)
          Back-end JMS Connection user name.
 void setPassword(java.lang.String pwd)
          Back-end JMS Connection password.
 void setReplyDestination(java.lang.String destinationName)
          Front-end reply destination (queue or topic) name.
 void setReplyTimeToLive(long replyTimeToLive)
          Time to live for reply.
 void start()
           
 void stop()
          Stops worker (thread pool), if any, and connection.
 
Methods inherited from class biz.hammurapi.jms.MessageProcessor
_processMessage, borrowSession, releaseSession, setAcknowledgeMode, setConnection, setConnectionFactory, setDestination, setInitialContext, setListeners, setLogger, setMessageSelector, setNoLocal, setRestartCommand, setTransacted, setUser, setWorker
 
Methods inherited from class biz.hammurapi.config.ComponentBase
addMeasurement, get, getMeasurementConsumer, getOwner, getOwner, setMeasurementConsumer, setOwner
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

backEndInitialContext

protected javax.naming.Context backEndInitialContext

backEndConnection

protected javax.jms.Connection backEndConnection

isBackEndTransacted

protected boolean isBackEndTransacted

backEndAcknowledgeMode

protected int backEndAcknowledgeMode

replyTimeToLive

protected long replyTimeToLive

backEndRequestTimeToLive

protected long backEndRequestTimeToLive

backEndTimeout

protected long backEndTimeout

backEndConnectionFactory

protected javax.jms.ConnectionFactory backEndConnectionFactory
Constructor Detail

Adapter

public Adapter()
Method Detail

setBackEndInitialContext

public void setBackEndInitialContext(javax.naming.Context initialContext)
Initial context to look-up back-end destinations and connection factory. If back-end initial context is not set then back-end JMS objects are looked up in the "front-end" initial context.

Parameters:
initialContext -

setBackEndDestination

public void setBackEndDestination(java.lang.String destinationName)
Back-end request destination (queue or topic) name.

Parameters:
destinationName -

setBackEndReplyDestination

public void setBackEndReplyDestination(java.lang.String destinationName)
Back-end reply destination (queue or topic) name.

Parameters:
destinationName -

setReplyDestination

public void setReplyDestination(java.lang.String destinationName)
Front-end reply destination (queue or topic) name.

Parameters:
destinationName -

setBackEndConnectionFactory

public void setBackEndConnectionFactory(java.lang.String connectionFactoryName)
Back-end JMS connection name. It it is not set then the "front-end" connection factory is used.

Parameters:
connectionName -

setBackEndTimeout

public void setBackEndTimeout(long backEndTimeout)
Timeout for backend reply.

Parameters:
backEndTimeout -

setReplyTimeToLive

public void setReplyTimeToLive(long replyTimeToLive)
Time to live for reply.

Parameters:
replyTimeToLive -

setBackEndRequestTimeToLive

public void setBackEndRequestTimeToLive(long backEndRequestTimeToLive)
Time to live for back-end request

Parameters:
backEndRequestTimeToLive -

setBackEndAcknowledgeMode

public void setBackEndAcknowledgeMode(java.lang.String acknowledgeModeName)
Back-end acknoledge mode. Valid values: AUTO (default), CLIENT, DUPS_OK.

Parameters:
acknowledgeModeName -

setBackEndConnection

public void setBackEndConnection(javax.jms.Connection connection)
Explicitly sets back-end connection. This method is useful when several components share one connection.

Parameters:
connection -

setBackEndTransacted

public void setBackEndTransacted(boolean isTransacted)
Transactional attribute of back-end JMS Session.

Parameters:
isTransacted -

setBackEndUser

public void setBackEndUser(java.lang.String user)
Back-end JMS Connection user name. Optional.

Parameters:
user -

setPassword

public void setPassword(java.lang.String pwd)
Back-end JMS Connection password. Optional.

Overrides:
setPassword in class MessageProcessor
Parameters:
pwd -

start

public void start()
           throws biz.hammurapi.config.ConfigurationException
Specified by:
start in interface biz.hammurapi.config.Component
Overrides:
start in class MessageProcessor
Throws:
biz.hammurapi.config.ConfigurationException

processMessage

protected void processMessage(javax.jms.Message request,
                              javax.jms.Session session)
Processes request message by passing to processRequest() and processResponse() methods.

Specified by:
processMessage in class MessageProcessor
Parameters:
request - Request message
session - Session if message is processed in the message listener thread (worker is null or cannot process jobs), null otherwise.

processRequest

protected abstract javax.jms.Message processRequest(javax.jms.Message frontEndRequest,
                                                    javax.jms.Session frontEndSession,
                                                    javax.jms.Session backEndSession)
Processes front-end request message and builds back-end request message.

Parameters:
request - Request from front-end
frontEndSession - Front-end JMS session
backEndSession - Back-end JMS session. Equals to the front-end session if back end connection is not set and the front-end connection is used to connect to both front and back end.
Returns:
Message to be sent to the back-end request queue. Null if no message shall be sent (e.g. in the case of exception).

processReply

protected abstract javax.jms.Message processReply(javax.jms.Message backEndReply,
                                                  javax.jms.Message frontEndRequest,
                                                  javax.jms.Session frontEndSession,
                                                  javax.jms.Session backEndSession)
Processes back-end reply and forms reply to front-end. This method is responsible for setting correlation ID.

Parameters:
backEndReply - Reply message from back-end. Null if request timed out.
frontEndRequest - Original request from front end.
frontEndSession - Front-end JMS session.
backEndSession - Back-end JMS session. Equals to the front-end session if back end connection is not set and the front-end connection is used to connect to both front and back end.
Returns:
Message to be sent to the front-end reply queue. Null if no message shall be sent (e.g. in the case of exception).

handleException

protected javax.jms.Message handleException(java.lang.Exception exception,
                                            javax.jms.Session frontEndSession)
Method to report exceptions to fron-end (excluding JMS exceptions in front-end JMS objects). This implementation returns null.

Parameters:
exception - Exception to report
frontEndSession - Front-end JMS session
Returns:
Message to send to front-end to reply queue. Null if no message shall be sent.

messageSelector

protected java.lang.String messageSelector(javax.jms.Message backEndRequest)
                                    throws javax.jms.JMSException
Extracts message selector for reply back-end message from the back-end request message. This implementation returns "JMSCorrelationID='" +backEndRequest.getJMSMessageID()+"'"

Parameters:
backEndRequest -
Returns:
Message selector to retrieve back-end reply.
Throws:
javax.jms.JMSException

stop

public void stop()
          throws biz.hammurapi.config.ConfigurationException
Stops worker (thread pool), if any, and connection.

Specified by:
stop in interface biz.hammurapi.config.Component
Overrides:
stop in class MessageProcessor
Throws:
biz.hammurapi.config.ConfigurationException

borrowBackEndSession

protected javax.jms.Session borrowBackEndSession()
                                          throws javax.jms.JMSException
This implementation simply creates a new session. Subclasses can override this method to implement session pooling.

Returns:
Throws:
javax.jms.JMSException

releaseBackEndSession

protected void releaseBackEndSession(javax.jms.Session session)
                              throws javax.jms.JMSException
This implementation simply closes the session. Subclasses can override this method to implement session pooling.

Throws:
javax.jms.JMSException

getChild

protected java.lang.Object getChild(java.lang.String name)
Provides access to back-end destination, reply destinations, initial context, and connection in addition to objects accessible through superclass getChild() method. Bridges to back-end initial context. For names in a form backEndInitialContext/<name> the name is looked up in initial context.

Overrides:
getChild in class MessageProcessor


Copyright © 2006 Hammurapi Group. All Rights Reserved.