org.javagroups.protocols
Class JMS

java.lang.Object
  |
  +--org.javagroups.stack.Protocol
        |
        +--org.javagroups.protocols.JMS
All Implemented Interfaces:
javax.jms.MessageListener

public class JMS
extends Protocol
implements javax.jms.MessageListener

Implementation of the transport protocol using the Java Message Service (JMS). This implementation depends on the JMS server that will distribute messages published to the specific topic to all topic subscribers.

Protocol parameters are:

Note, when you are using the JMS protocol, try to avoid using protocols that open server socket connections, like FD_SOCK. I belive that FD is more appropriate failure detector for JMS case.

Author:
Roman Rokytskyy (rrokytskyy@acm.org)

Inner Class Summary
protected static class JMS.JMSAddress
          Simple Address representing the JMS node ID or JMS topic group.
 
Field Summary
static java.lang.String DEFAULT_CONNECTION_FACTORY
           
static java.lang.String DEST_PROPERTY
           
static java.lang.String GROUP_NAME_PROPERTY
           
static java.lang.String INIT_CONNECTION_FACTORY
           
static java.lang.String INIT_JNDI_CONTEXT
           
static java.lang.String INIT_PROVIDER_URL
           
static java.lang.String INIT_TOPIC_NAME
           
static java.lang.String SRC_PROPERTY
           
static java.lang.String TIME_TO_LIVE
           
 
Fields inherited from class org.javagroups.stack.Protocol
down_handler, down_prot, down_queue, down_thread, observer, props, stack, up_handler, up_prot, up_queue, up_thread
 
Constructor Summary
JMS()
          Empty constructor.
 
Method Summary
 void down(Event evt)
          Called by the protocol above this.
protected  java.lang.String generateLocalAddress()
          Generate random local address.
 java.lang.String getName()
          Get the name of the protocol.
protected  void handleDownEvent(Event evt)
          Handle down event, if it is not a Event.MSG type.
 void onMessage(javax.jms.Message jmsMessage)
          Implementation of the javax.jms.MessageListener interface.
protected  void sendMessage(Message msg)
          Publish message in the JMS topic.
 boolean setProperties(java.util.Properties props)
          Set protocol properties.
protected  void startWork()
          Start the JMS protocol.
protected  void stopWork()
          Stops the work of the JMS protocol.
 java.lang.String toString()
          Get the string representation of the protocol.
 void up(Event evt)
          handle the UP event.
 
Methods inherited from class org.javagroups.stack.Protocol
getDownProtocol, getDownQueue, getProperties, getUpProtocol, getUpQueue, init, passDown, passUp, providedDownServices, providedUpServices, receiveDownEvent, receiveUpEvent, requiredDownServices, requiredUpServices, setDownProtocol, setObserver, setPropertiesInternal, setProtocolStack, setUpProtocol, startDownHandler, startUpHandler, stopInternal
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

DEFAULT_CONNECTION_FACTORY

public static final java.lang.String DEFAULT_CONNECTION_FACTORY

INIT_CONNECTION_FACTORY

public static final java.lang.String INIT_CONNECTION_FACTORY

INIT_TOPIC_NAME

public static final java.lang.String INIT_TOPIC_NAME

INIT_JNDI_CONTEXT

public static final java.lang.String INIT_JNDI_CONTEXT

INIT_PROVIDER_URL

public static final java.lang.String INIT_PROVIDER_URL

TIME_TO_LIVE

public static final java.lang.String TIME_TO_LIVE

GROUP_NAME_PROPERTY

public static final java.lang.String GROUP_NAME_PROPERTY

SRC_PROPERTY

public static final java.lang.String SRC_PROPERTY

DEST_PROPERTY

public static final java.lang.String DEST_PROPERTY
Constructor Detail

JMS

public JMS()
Empty constructor.
Method Detail

getName

public java.lang.String getName()
Get the name of the protocol.
Overrides:
getName in class Protocol
Returns:
always returns the "JMS" string.

toString

public java.lang.String toString()
Get the string representation of the protocol.
Overrides:
toString in class java.lang.Object
Returns:
string representation of the protocol (not very useful though).

setProperties

public boolean setProperties(java.util.Properties props)
Set protocol properties. Properties are:
Overrides:
setProperties in class Protocol

onMessage

public void onMessage(javax.jms.Message jmsMessage)
Implementation of the javax.jms.MessageListener interface. This method receives the JMS message, checks the destination group name. If the group name is the same as the group name of this channel, it checks the destination address. If destination address is either multicast or is the same as local address then message is unwrapped and passed up the protocol stack. Otherwise it is ignored.
Specified by:
onMessage in interface javax.jms.MessageListener
Parameters:
jmsMessage - instance of javax.jms.Message.

handleDownEvent

protected void handleDownEvent(Event evt)
Handle down event, if it is not a Event.MSG type.
Parameters:
evt - event to handle.

down

public void down(Event evt)
Called by the protocol above this. We check the event type, and if it is message, we publish it in the topic, otherwise we let the handleDownEvent(Event) take care of it.
Overrides:
down in class Protocol
Parameters:
evt - event to process.

up

public void up(Event evt)
handle the UP event. the only event checked for is Event.START which will start this protocol this method will take the START event and perform the following action 1. pass up the start event through out the stack 2. create all the sockets and initlize the listener threads 3. pass up a Event.SET_LOCAL_ADDRESS event 4. pass up a Event.START_OK event
Overrides:
up in class Protocol
Parameters:
evt - - the event being send from the stack

sendMessage

protected void sendMessage(Message msg)
Publish message in the JMS topic. We set the message source and destination addresses if they were null.
Parameters:
msg - message to publish.

startWork

protected void startWork()
                  throws javax.jms.JMSException,
                         javax.naming.NamingException,
                         java.net.UnknownHostException
Start the JMS protocol. This method instantiates the JNDI initial context and looks up the topic connection factory and topic itself. If this step is successful, it creates a connection to JMS server, opens a session and obtains publisher and subscriber instances.
Throws:
javax.jms.JMSException - if something goes wrong with JMS.
javax.naming.NamingException - if something goes wrong with JNDI.
java.lang.IllegalArgumentException - if the connection factory or topic cannot be found under specified names.

stopWork

protected void stopWork()
                 throws javax.jms.JMSException
Stops the work of the JMS protocol. This method closes JMS session and connection and deregisters itself from the message notification.
Throws:
javax.jms.JMSException - if something goes wrong with JMS.

generateLocalAddress

protected java.lang.String generateLocalAddress()
                                         throws java.net.UnknownHostException
Generate random local address. This method takes host name and appends it with randomly generated integer.
Returns:
randomly generated local address.


Copyright © 2001,2002 www.javagroups.com . All Rights Reserved.