biz.hammurapi.jms
Class MessageProcessor

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

public abstract class MessageProcessor
extends biz.hammurapi.config.ComponentBase
implements biz.hammurapi.config.Restartable

Base class for JMS message processors.

Author:
Pavel Vlasov

Field Summary
protected  int acknowledgeMode
           
protected  javax.jms.Connection connection
           
protected  javax.jms.ConnectionFactory connectionFactory
           
protected  javax.naming.Context initialContext
           
protected  boolean isTransacted
           
protected  biz.hammurapi.logging.Logger logger
           
protected  biz.hammurapi.config.RestartCommand restartCommand
           
protected  biz.hammurapi.util.Worker worker
           
 
Fields inherited from class biz.hammurapi.config.ComponentBase
owner
 
Constructor Summary
MessageProcessor()
           
 
Method Summary
protected  void _processMessage(javax.jms.Message request, javax.jms.Session session)
           
protected  javax.jms.Session borrowSession()
          This implementation simply creates a new session.
protected  java.lang.Object getChild(java.lang.String name)
          Provides access to destination, initial context, connection, and worker.
protected abstract  void processMessage(javax.jms.Message request, javax.jms.Session session)
          Processes request message
protected  void releaseSession(javax.jms.Session session)
          This implementation simply closes the session.
 void setAcknowledgeMode(java.lang.String acknowledgeModeName)
          Acknoledge mode.
 void setConnection(javax.jms.Connection connection)
          Explicitly sets connection.
 void setConnectionFactory(java.lang.String connectionFactoryName)
          JMS connection name
 void setDestination(java.lang.String destinationName)
          Request destination (queue or topic) name
 void setInitialContext(javax.naming.Context initialContext)
           
 void setListeners(int listeners)
          Number of message listening threads.
 void setLogger(biz.hammurapi.logging.Logger logger)
          Sets logger.
 void setMessageSelector(java.lang.String messageSelector)
          Message selector
 void setNoLocal(boolean noLocal)
          If true and destination is topic then messages produced by this connection are not consumed by the message processor.
 void setPassword(java.lang.String pwd)
          JMS Connection password.
 void setRestartCommand(biz.hammurapi.config.RestartCommand command)
           
 void setTransacted(boolean isTransacted)
          Transactional attribute of JMS Session.
 void setUser(java.lang.String user)
          JMS Connection user name.
 void setWorker(biz.hammurapi.util.Worker worker)
          Worker to process requests.
 void start()
           
 void stop()
          Stops worker (thread pool), if any, and connection.
 
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

logger

protected biz.hammurapi.logging.Logger logger

initialContext

protected javax.naming.Context initialContext

connection

protected javax.jms.Connection connection

isTransacted

protected boolean isTransacted

acknowledgeMode

protected int acknowledgeMode

worker

protected biz.hammurapi.util.Worker worker

connectionFactory

protected javax.jms.ConnectionFactory connectionFactory

restartCommand

protected biz.hammurapi.config.RestartCommand restartCommand
Constructor Detail

MessageProcessor

public MessageProcessor()
Method Detail

setLogger

public void setLogger(biz.hammurapi.logging.Logger logger)
Sets logger.

Parameters:
logger -

setListeners

public void setListeners(int listeners)
Number of message listening threads. Defaults to number of processes available to JVM.

Parameters:
listeners -

setInitialContext

public void setInitialContext(javax.naming.Context initialContext)

setDestination

public void setDestination(java.lang.String destinationName)
Request destination (queue or topic) name

Parameters:
destinationName -

setConnectionFactory

public void setConnectionFactory(java.lang.String connectionFactoryName)
JMS connection name

Parameters:
connectionName -

setWorker

public void setWorker(biz.hammurapi.util.Worker worker)
Worker to process requests. It is optional. If worker is not set or cannot process requests, requests are processed in the message listener thread.

Parameters:
worker -

setAcknowledgeMode

public void setAcknowledgeMode(java.lang.String acknowledgeModeName)
Acknoledge mode. Valid values: AUTO (default), CLIENT, DUPS_OK.

Parameters:
acknowledgeModeName -

setConnection

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

Parameters:
connection -

setTransacted

public void setTransacted(boolean isTransacted)
Transactional attribute of JMS Session.

Parameters:
isTransacted -

setUser

public void setUser(java.lang.String user)
JMS Connection user name. Optional.

Parameters:
user -

setPassword

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

Parameters:
pwd -

start

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

processMessage

protected abstract void processMessage(javax.jms.Message request,
                                       javax.jms.Session session)
Processes request message

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

_processMessage

protected void _processMessage(javax.jms.Message request,
                               javax.jms.Session session)

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
Throws:
biz.hammurapi.config.ConfigurationException

borrowSession

protected javax.jms.Session borrowSession()
                                   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

releaseSession

protected void releaseSession(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 destination, initial context, connection, and worker. Bridges to initial context. For names in a form initialContext/<name> the name is looked up in initial context.

Overrides:
getChild in class biz.hammurapi.config.ComponentBase

setMessageSelector

public void setMessageSelector(java.lang.String messageSelector)
Message selector

Parameters:
messageSelector -

setNoLocal

public void setNoLocal(boolean noLocal)
If true and destination is topic then messages produced by this connection are not consumed by the message processor.

Parameters:
noLocal -

setRestartCommand

public void setRestartCommand(biz.hammurapi.config.RestartCommand command)
Specified by:
setRestartCommand in interface biz.hammurapi.config.Restartable


Copyright © 2006 Hammurapi Group. All Rights Reserved.