moos.ssds.jms
Class SubscriberComponent

java.lang.Object
  extended bymoos.ssds.jms.SubscriberComponent

public class SubscriberComponent
extends java.lang.Object

SubscriberComponent provides an easy to use class that handles JMS publish-subscribe messaging. The goal of this is to povide messsaging without requiring the developer to use JMS api's

Here's an example of code using a SubscriberComponent


 import ssds.portal.*;

 public class Subscriber1 {

    SubscriberComponent sc;
    SensorDataPacketListener listener = new SensorDataPacketListener();

    public Subscriber1(String topicName) {
        sc = new SubscriberComponent(topicName, listener);
    }

    public static void main(String[] args) {
        try {
            Subscriber1 sub = new Subscriber1(args[0]);

        } catch (Throwable e) {
            e.printStackTrace();
        }
    }
 }

 

Note: I tried overriding the finalize() method to close the TopicConnection when the class was no longer used. However, the garbage collector would call the finalize() method at seemingly random times. Causing the program to cease. Moving the close() call out of the finalize() method stopeed this problem.


Version:
: $Revision: 1.2 $

The Monterey Bay Aquarium Research Institute (MBARI) provides this documentation and code "as is", with no warranty, express or implied, of its quality or consistency. It is provided without support and without obligation on the part of MBARI to assist in its use, correction, modification, or enhancement. This information should not be published or distributed to third parties without specific written permission from MBARI.


Copyright 2002 MBARI.
MBARI Proprietary Information. All rights reserved.



Author:
: $Author: kgomes $

Field Summary
protected  javax.naming.Context jndiContext
          This the the naming Context that will be used to look up the JMS related servcies.
protected  javax.jms.Message message
          A dummy message
protected  javax.jms.TopicConnection topicConnection
          This is the TopicConnection to the JMS server
protected  javax.jms.TopicConnectionFactory topicConnectionFactory
          This is the JMS TopicConnectionFactory that is used to get the topic connection for this subscriber
protected  java.lang.String topicname
          The topic name that this SubscriberComponent will subscribe to
protected  javax.jms.TopicSession topicSession
          This is the TopicSession that will be used to listen and process messages coming from JMS
protected  javax.jms.TopicSubscriber topicSubscriber
          This is the TopicSubscriber obtained from the JMS server
 
Constructor Summary
SubscriberComponent(java.lang.String topicName, javax.jms.MessageListener messageListener)
          Constructor
 
Method Summary
 void close()
          Closes the topic connection.
 javax.jms.MessageListener getMessageListener()
          Accessor for the MessageListener
 java.lang.String getTopicname()
          Accessor for the topic name
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

topicname

protected java.lang.String topicname
The topic name that this SubscriberComponent will subscribe to


jndiContext

protected javax.naming.Context jndiContext
This the the naming Context that will be used to look up the JMS related servcies. It is going to use the first jndi.properties file it finds in its classpath to determine which JNDI service to utilize.


topicConnectionFactory

protected javax.jms.TopicConnectionFactory topicConnectionFactory
This is the JMS TopicConnectionFactory that is used to get the topic connection for this subscriber


topicSession

protected javax.jms.TopicSession topicSession
This is the TopicSession that will be used to listen and process messages coming from JMS


topicConnection

protected javax.jms.TopicConnection topicConnection
This is the TopicConnection to the JMS server


message

protected javax.jms.Message message
A dummy message


topicSubscriber

protected javax.jms.TopicSubscriber topicSubscriber
This is the TopicSubscriber obtained from the JMS server

Constructor Detail

SubscriberComponent

public SubscriberComponent(java.lang.String topicName,
                           javax.jms.MessageListener messageListener)
Constructor

Parameters:
topicName - The name of the topic to subscribe to. For JBoss this needs to be "topic/someTopic" whereas most other J2EE servers would use "someTopic"
messageListener - The MessageListener to be used to handle the message.
Method Detail

getMessageListener

public javax.jms.MessageListener getMessageListener()
Accessor for the MessageListener

Returns:
The class used to process the messages recieved by this SubscriberComponent

getTopicname

public java.lang.String getTopicname()
Accessor for the topic name

Returns:
The topic name that this SubscriberComponent is subscribed to.

close

public void close()
Closes the topic connection. Should be called when the class is no longer used.