org.jgroups.protocols

Class JMS

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)

Nested Class Summary

protected static class
JMS.JMSAddress
Simple Address representing the JMS node ID or JMS topic group.

Field Summary

static String
DEFAULT_CONNECTION_FACTORY
static String
DEST_PROPERTY
static String
GROUP_NAME_PROPERTY
static String
INIT_CONNECTION_FACTORY
static String
INIT_JNDI_CONTEXT
static String
INIT_PROVIDER_URL
static String
INIT_TOPIC_NAME
static String
SRC_PROPERTY
static String
TIME_TO_LIVE

Fields inherited from class org.jgroups.stack.Protocol

down_handler, down_prot, down_queue, down_thread, down_thread_prio, log, observer, props, stack, up_handler, up_prot, up_queue, up_thread, up_thread_prio

Constructor Summary

JMS()
Empty constructor.

Method Summary

void
down(Event evt)
Called by the protocol above this.
protected String
generateLocalAddress()
Generate random local address.
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(Properties props)
Set protocol properties.
void
start()
Start the JMS protocol.
void
stop()
Stops the work of the JMS protocol.
String
toString()
Get the string representation of the protocol.

Methods inherited from class org.jgroups.stack.Protocol

destroy, down, getDownProtocol, getDownQueue, getName, getProperties, getUpProtocol, getUpQueue, handleSpecialDownEvent, init, passDown, passUp, providedDownServices, providedUpServices, receiveDownEvent, receiveUpEvent, requiredDownServices, requiredUpServices, setDownProtocol, setObserver, setProperties, setPropertiesInternal, setProtocolStack, setUpProtocol, start, startDownHandler, startUpHandler, stop, stopInternal, up

Field Details

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 Details

JMS

public JMS()
Empty constructor.

Method Details

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 interface Protocol
Parameters:
evt - event to process.

generateLocalAddress

protected 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.

getName

public String getName()
Get the name of the protocol.
Overrides:
getName in interface 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(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.
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:
  • topicName - (required), full JNDI name of the topic to be used for message publishing;
  • cf - (optional), full JNDI name of the topic connection factory that will create topic connection, default value is "ConnectionFactory";
  • jndiCtx - (optional), value of the javax.naming.Context.INITIAL_CONTEXT_FACTORY property; you can specify it as the JVM system property -Djava.naming.factory.initial=factory.class.Name;
  • providerURL - (optional), value of the javax.naming.Context.PROVIDER_URL property; you can specify it as the JVM system property -Djava.naming.provider.url=some_url
Overrides:
setProperties in interface Protocol

start

public void start()
            throws Exception
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.
Overrides:
start in interface Protocol

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.
Overrides:
stop in interface Protocol

toString

public String toString()
Get the string representation of the protocol.
Returns:
string representation of the protocol (not very useful though).

Copyright B) 2001,2002 www.jgroups.com . All Rights Reserved.