org.systinet.transport.jms
Class ReductionTemplate

java.lang.Object
  extended byorg.systinet.transport.jms.ReductionTemplate
All Implemented Interfaces:
Reduction

public abstract class ReductionTemplate
extends java.lang.Object
implements Reduction

Simplified template to write custom Reduction interface implementations.

Since:
4.5
See Also:
Reduction
Component:
J2EE-JMS-Transport

Constructor Summary
ReductionTemplate()
           
 
Method Summary
abstract  boolean check()
          Returns true of the reduction can be used.
abstract  javax.jms.Message createMessage(byte[] data, javax.jms.Session session)
          Creates message using the session and fills it with data.
abstract  byte[] getMessageData(javax.jms.Message msg)
          Gets data from the message passed as an argument.
abstract  java.lang.String getStringProperty(javax.jms.Message msg, java.lang.String key)
          Gets value of the property of the message.
 void publishClientData(javax.jms.TopicSession session, javax.jms.Topic topic, byte[] data, java.util.Map jmsProperties, int deliveryMode, int priority, int timeToLive)
          Template implementation of the method publishClientData.
 byte[] receiveClientData(javax.jms.QueueSession session, javax.jms.Queue queue, long timeout, java.util.Map properties)
          Template implementation of the method receiveClientData.
abstract  javax.jms.Queue resolveQueue(java.lang.String name)
          Resolves the queue with the given name.
abstract  javax.jms.QueueConnectionFactory resolveQueueConnectionFactory(java.lang.String name)
          Resolves the queue connection factory with the given name.
abstract  javax.jms.Topic resolveTopic(java.lang.String name)
          Resolves the topic with the given name.
abstract  javax.jms.TopicConnectionFactory resolveTopicConnectionFactory(java.lang.String name)
          Resolves topic connection factory with the given name.
 void sendClientData(javax.jms.QueueSession session, javax.jms.Queue queue, javax.jms.Queue replyQueue, byte[] data, java.util.Map jmsProperties, int deliveryMode, int priority, int timeToLive)
          Template implementation of the method sendClientData.
 void sendData(javax.jms.QueueSession session, javax.jms.Queue queue, byte[] data, java.util.Map outputProperties, int deliveryMode, int priority, int timeToLive)
          Template implementation of the method @method sendData.
abstract  void setProperty(javax.jms.Message message, java.lang.String key, java.lang.Object value)
          Sets property of the message.
 void startQueueListening(JmsDataHandler handler, javax.jms.QueueSession session, javax.jms.Queue queue, java.lang.String serverSelector)
          Template implementation of the method startQueueListening.
abstract  void startResolving(java.util.Map properties)
          Typically this method should allocate resources needed to be able to resolve object in following calls of the resolve* methods.
 void startTopicListening(JmsDataHandler handler, javax.jms.TopicSession session, javax.jms.Topic topic, java.lang.String serverSelector, java.lang.String durableId)
          Template implementation of the method startTopicListening.
 void stopListening()
          Template implementation of the method stopListening.
abstract  void stopResolving()
          Called after all resolve* method calls are performed.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ReductionTemplate

public ReductionTemplate()
Method Detail

startResolving

public abstract void startResolving(java.util.Map properties)
                             throws javax.naming.NamingException
Typically this method should allocate resources needed to be able to resolve object in following calls of the resolve* methods. Typically it creates new initial context.

Specified by:
startResolving in interface Reduction
Parameters:
properties - allows passing of customization parameters to the reduction implementation. User may pass them using WebserviceLookup.lookup(...). Otherwise, the properties are read from JMS transport configuration.
Throws:
javax.naming.NamingException - when an exception occures during setup of resources

stopResolving

public abstract void stopResolving()
                            throws javax.naming.NamingException
Called after all resolve* method calls are performed. Typically it closes context and other resources created in startResolving method

Specified by:
stopResolving in interface Reduction
Throws:
javax.naming.NamingException - when an exception occures during closing resources

check

public abstract boolean check()
Returns true of the reduction can be used. Typically it checks classes in the classloader if they are suitable for this reduction

Specified by:
check in interface Reduction
Returns:
true if it succeeds, otherwise it returns false.

resolveQueue

public abstract javax.jms.Queue resolveQueue(java.lang.String name)
                                      throws javax.naming.NamingException
Resolves the queue with the given name. It can lookup the queue, create the queue with the given name or anyhow resolve the request.

Specified by:
resolveQueue in interface Reduction
Parameters:
name - the queue
Returns:
the queue
Throws:
javax.naming.NamingException - if an exception occures during resolving the request.

resolveTopic

public abstract javax.jms.Topic resolveTopic(java.lang.String name)
                                      throws javax.naming.NamingException
Resolves the topic with the given name. It can lookup the topic, create the topic with the given name or anyhow resolve the request.

Specified by:
resolveTopic in interface Reduction
Parameters:
name - the topic name
Returns:
the topic
Throws:
javax.naming.NamingException - if an exception occures during resolving the request.

resolveQueueConnectionFactory

public abstract javax.jms.QueueConnectionFactory resolveQueueConnectionFactory(java.lang.String name)
                                                                        throws javax.naming.NamingException
Resolves the queue connection factory with the given name. It can lookup the factory, create the factory with the given name or anyhow resolve the request.

Specified by:
resolveQueueConnectionFactory in interface Reduction
Parameters:
name - the factory name
Returns:
the queue connection factory
Throws:
javax.naming.NamingException - if an exception occures during resolving the request.

resolveTopicConnectionFactory

public abstract javax.jms.TopicConnectionFactory resolveTopicConnectionFactory(java.lang.String name)
                                                                        throws javax.naming.NamingException
Resolves topic connection factory with the given name. It can lookup the factory, create the factory with the given name or anyhow resolve the request.

Specified by:
resolveTopicConnectionFactory in interface Reduction
Parameters:
name - the factory name
Returns:
the topic connection factory
Throws:
javax.naming.NamingException - if an exception occures during resolving the request.

setProperty

public abstract void setProperty(javax.jms.Message message,
                                 java.lang.String key,
                                 java.lang.Object value)
                          throws javax.jms.JMSException
Sets property of the message. It may perform some aditional processing like encoding the property. It's called everywhere the setting of the property is processed.

Parameters:
message - message to be the property set on
key - key value of the property
value - value of the property.
Throws:
javax.jms.JMSException - when en exception occures during setting the property

getStringProperty

public abstract java.lang.String getStringProperty(javax.jms.Message msg,
                                                   java.lang.String key)
                                            throws javax.jms.JMSException
Gets value of the property of the message. It may perform some aditional processing like decoding the property. It's called everywhere the getting of the property is processed.

Parameters:
msg - message which holds the property
key - key value of the property
Returns:
value of the property.
Throws:
javax.jms.JMSException - when en exception occures during setting the property

createMessage

public abstract javax.jms.Message createMessage(byte[] data,
                                                javax.jms.Session session)
                                         throws javax.jms.JMSException
Creates message using the session and fills it with data. It can use any type of the message to send data and it may also perform aditional processing like data encoding. It's called to create message and fill it with data everywhere such action occures.

Parameters:
data - the message holds
session - which creates the message
Returns:
the new message
Throws:
javax.jms.JMSException - when an exception occures during message creation

getMessageData

public abstract byte[] getMessageData(javax.jms.Message msg)
Gets data from the message passed as an argument. It may perform aditional processing like data decoding. It is called in order to get data from the message anywhere such action occures.

Parameters:
msg - the message which hold the data.
Returns:
data from the message

sendClientData

public void sendClientData(javax.jms.QueueSession session,
                           javax.jms.Queue queue,
                           javax.jms.Queue replyQueue,
                           byte[] data,
                           java.util.Map jmsProperties,
                           int deliveryMode,
                           int priority,
                           int timeToLive)
                    throws javax.jms.JMSException
Template implementation of the method sendClientData.

Specified by:
sendClientData in interface Reduction
Parameters:
session - the session to be used when sending the message
queue - the queue to be used when sending the message
replyQueue - the queue where this reduction should expect optional response data. May be null.
data - data to be sent. The method may perform aditional processing like encrypting or encoding the data.
jmsProperties - the JMS properties to be set ob the output message. The method may perform aditional processing on othe properies.
deliveryMode - delivery mode to be set, one of javax.jms.DeliveryMode constants
priority - priority of the message
timeToLive - time to live of the message
Throws:
javax.jms.JMSException

receiveClientData

public byte[] receiveClientData(javax.jms.QueueSession session,
                                javax.jms.Queue queue,
                                long timeout,
                                java.util.Map properties)
                         throws javax.jms.JMSException
Template implementation of the method receiveClientData.

Specified by:
receiveClientData in interface Reduction
Parameters:
session - the session to be used when receiving the message
queue - the queue to be used when receiving the message
timeout - time, after timeout occures
properties - the structure to be filled with received properties and it initialy contains some properties like server selector value used to receive message
Returns:
the data. The method may perform aditional processing like decrypting or decoding the data.
Throws:
javax.jms.JMSException

publishClientData

public void publishClientData(javax.jms.TopicSession session,
                              javax.jms.Topic topic,
                              byte[] data,
                              java.util.Map jmsProperties,
                              int deliveryMode,
                              int priority,
                              int timeToLive)
                       throws javax.jms.JMSException
Template implementation of the method publishClientData.

Specified by:
publishClientData in interface Reduction
Parameters:
session - the session to be used when publishing the message
topic - the topic to be used when publishing the message
data - data to be sent. The method may perform aditional processing like encrypting or encoding the data.
jmsProperties - the JMS properties to be set ob the output message. The method may perform aditional processing on othe properies.
deliveryMode - delivery mode to be set, one of javax.jms.DeliveryMode constants
priority - priority of the message
timeToLive - time to live of the message
Throws:
javax.jms.JMSException

startQueueListening

public void startQueueListening(JmsDataHandler handler,
                                javax.jms.QueueSession session,
                                javax.jms.Queue queue,
                                java.lang.String serverSelector)
                         throws javax.jms.JMSException
Template implementation of the method startQueueListening.

Specified by:
startQueueListening in interface Reduction
Parameters:
handler - the handler to be used to process received data
session - the session which receives the data
queue - the queue which receives the data
serverSelector - id which identifies messages sent to the server. If not null, the listening must be performed with the selector string : String selector = JmsConstants.MSG_TYPE + "='" + JmsConstants.TYPE_REQUEST + "'" + ( ( serverSelector == null ) ? "" : ( " AND " + JmsConstants.SERVER_SELECTOR + "='" + serverSelector + "'" ) );
Throws:
javax.jms.JMSException

startTopicListening

public void startTopicListening(JmsDataHandler handler,
                                javax.jms.TopicSession session,
                                javax.jms.Topic topic,
                                java.lang.String serverSelector,
                                java.lang.String durableId)
                         throws javax.jms.JMSException
Template implementation of the method startTopicListening.

Specified by:
startTopicListening in interface Reduction
Parameters:
handler - the handler to be used to process received data
session - the session which receives the data
topic - the topic which receives the data
serverSelector - id which identifies messages sent to the server. If not null, the listening must be performed with the selector string : String selector = JmsConstants.MSG_TYPE + "='" + JmsConstants.TYPE_REQUEST + "'" + ( ( serverSelector == null ) ? "" : ( " AND " + JmsConstants.SERVER_SELECTOR + "='" + serverSelector + "'" ) );
durableId - the client identifier of the durable subscription. If null, the subscriber will not be durable.
Throws:
javax.jms.JMSException

stopListening

public void stopListening()
Template implementation of the method stopListening.

Specified by:
stopListening in interface Reduction

sendData

public void sendData(javax.jms.QueueSession session,
                     javax.jms.Queue queue,
                     byte[] data,
                     java.util.Map outputProperties,
                     int deliveryMode,
                     int priority,
                     int timeToLive)
              throws javax.jms.JMSException
Template implementation of the method @method sendData.

Specified by:
sendData in interface Reduction
Parameters:
session - the session, which sends data
queue - the queue, which sends data
data - the data to be sent
outputProperties - JMS properties which have to be set on the output JMS message.
deliveryMode - delivery mode to be set, one of javax.jms.DeliveryMode constants
priority - priority of the message
timeToLive - time to live of the message
Throws:
javax.jms.JMSException