org.jgroups.protocols

Class JMS

public class JMS extends Protocol implements 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)

Nested Class Summary
protected static classJMS.JMSAddress
Simple Address representing the JMS node ID or JMS topic group.
Field Summary
static StringDEFAULT_CONNECTION_FACTORY
static StringDEST_PROPERTY
static StringGROUP_NAME_PROPERTY
static StringINIT_CONNECTION_FACTORY
static StringINIT_JNDI_CONTEXT
static StringINIT_PROVIDER_URL
static StringINIT_TOPIC_NAME
static StringSRC_PROPERTY
static StringTIME_TO_LIVE
Constructor Summary
JMS()
Empty constructor.
Method Summary
voiddown(Event evt)
Called by the protocol above this.
protected StringgenerateLocalAddress()
Generate random local address.
StringgetName()
Get the name of the protocol.
protected voidhandleDownEvent(Event evt)
Handle down event, if it is not a Event.MSG type.
voidonMessage(Message jmsMessage)
Implementation of the javax.jms.MessageListener interface.
protected voidsendMessage(Message msg)
Publish message in the JMS topic.
booleansetProperties(Properties props)
Set protocol properties.
voidstart()
Start the JMS protocol.
voidstop()
Stops the work of the JMS protocol.
StringtoString()
Get the string representation of the protocol.

Field Detail

DEFAULT_CONNECTION_FACTORY

public static final String DEFAULT_CONNECTION_FACTORY

DEST_PROPERTY

public static final String DEST_PROPERTY

GROUP_NAME_PROPERTY

public static final String GROUP_NAME_PROPERTY

INIT_CONNECTION_FACTORY

public static final String INIT_CONNECTION_FACTORY

INIT_JNDI_CONTEXT

public static final String INIT_JNDI_CONTEXT

INIT_PROVIDER_URL

public static final String INIT_PROVIDER_URL

INIT_TOPIC_NAME

public static final String INIT_TOPIC_NAME

SRC_PROPERTY

public static final String SRC_PROPERTY

TIME_TO_LIVE

public static final String TIME_TO_LIVE

Constructor Detail

JMS

public JMS()
Empty constructor.

Method Detail

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 take care of it.

Parameters: evt event to process.

generateLocalAddress

protected String generateLocalAddress()
Generate random local address. This method takes host name and appends it with randomly generated integer.

Returns: randomly generated local address.

getName

public String getName()
Get the name of the protocol.

Returns: always returns the "JMS" string.

handleDownEvent

protected void handleDownEvent(Event evt)
Handle down event, if it is not a Event.MSG type.

Parameters: evt event to handle.

onMessage

public void onMessage(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.

Parameters: jmsMessage instance of javax.jms.Message.

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.

setProperties

public boolean setProperties(Properties props)
Set protocol properties. Properties are:

start

public void start()
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. IllegalArgumentException if the connection factory or topic cannot be found under specified names.

stop

public void stop()
Stops the work of the JMS protocol. This method closes JMS session and connection and deregisters itself from the message notification.

toString

public String toString()
Get the string representation of the protocol.

Returns: string representation of the protocol (not very useful though).

Copyright ? 1998-2005 Bela Ban. All Rights Reserved.