Package org.jgroups.protocols
Class JMS
java.lang.Object
org.jgroups.stack.Protocol
org.jgroups.protocols.JMS
- All Implemented Interfaces:
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:
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 thejavax.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 thejavax.naming.Context.PROVIDER_URL
property; you can specify it as the JVM system property-Djava.naming.provider.url=some_url
ttl
- (required), time to live in milliseconds. Default value is 0, that means that messages will never expire and will be accumulated by a JMS server.
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
Nested ClassesModifier and TypeClassDescriptionstatic class
SimpleAddress
representing the JMS node ID or JMS topic group. -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionCalled by the protocol above this.protected String
Generate random local address.getName()
Get the name of the protocol.protected Object
handleDownEvent
(Event evt) Handle down event, if it is not a Event.MSG type.void
onMessage
(javax.jms.Message jmsMessage) Implementation of thejavax.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.toString()
Get the string representation of the protocol.Methods inherited from class org.jgroups.stack.Protocol
destroy, downThreadEnabled, dumpStats, enableStats, getDownProtocol, getProperties, getProtocolStack, getThreadFactory, getTransport, getUpProtocol, init, printStats, providedDownServices, providedUpServices, requiredDownServices, requiredUpServices, resetStats, setDownProtocol, setPropertiesInternal, setProtocolStack, setUpProtocol, statsEnabled, up, upThreadEnabled
-
Field Details
-
DEFAULT_CONNECTION_FACTORY
- See Also:
-
INIT_CONNECTION_FACTORY
- See Also:
-
INIT_TOPIC_NAME
- See Also:
-
INIT_JNDI_CONTEXT
- See Also:
-
INIT_PROVIDER_URL
- See Also:
-
TIME_TO_LIVE
- See Also:
-
GROUP_NAME_PROPERTY
- See Also:
-
SRC_PROPERTY
- See Also:
-
DEST_PROPERTY
- See Also:
-
-
Constructor Details
-
JMS
public JMS()Empty constructor.
-
-
Method Details
-
getName
Get the name of the protocol. -
toString
Get the string representation of the protocol. -
setProperties
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 thejavax.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 thejavax.naming.Context.PROVIDER_URL
property; you can specify it as the JVM system property-Djava.naming.provider.url=some_url
- Overrides:
setProperties
in classProtocol
-
onMessage
public void onMessage(javax.jms.Message jmsMessage) Implementation of thejavax.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 interfacejavax.jms.MessageListener
- Parameters:
jmsMessage
- instance ofjavax.jms.Message
.
-
handleDownEvent
Handle down event, if it is not a Event.MSG type.- Parameters:
evt
- event to handle.
-
down
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 thehandleDownEvent(Event)
take care of it. -
sendMessage
Publish message in the JMS topic. We set the message source and destination addresses if they werenull
.- Parameters:
msg
- message to publish.
-
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.- Overrides:
start
in classProtocol
- Throws:
javax.jms.JMSException
- if something goes wrong with JMS.NamingException
- if something goes wrong with JNDI.IllegalArgumentException
- if the connection factory or topic cannot be found under specified names.Exception
- Thrown if protocol cannot be started successfully. This will cause the ProtocolStack to fail, soChannel.connect(String)
will throw an exception
-
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. -
generateLocalAddress
Generate random local address. This method takes host name and appends it with randomly generated integer.- Returns:
- randomly generated local address.
- Throws:
UnknownHostException
-