Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

cern::cmw::mom::test::Server Class Reference

Inheritance diagram for cern::cmw::mom::test::Server:

Inheritance graph
[legend]
Collaboration diagram for cern::cmw::mom::test::Server:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 Server ()
void onMessage (javax.jms.Message message)

Static Public Member Functions

void main (String[] args)

Private Member Functions

void start ()

Private Attributes

Publisher p = null
Subscriber s = null
long openSubscriptionToken = 0
long closeSubscriptionToken = 0
boolean publicationEnabled = false
String status = null

Static Private Attributes

final String TOPIC = "CMW.ALARM_SYSTEM.ALARM_CATEGORY_TREE.CERN.INSTANT"

Detailed Description

This example shows how to setup a server publishing on a topic and listening to CONSUMER_NOTIFICATION events. It enables the actual msg publishing as it gets a CONSUMER_OPEN_NOTIFICATION msg and stops publishing when receives a CONSUMER_CLOSE_NOTIFICATION msg. It also sends an initialization msg to the new subscriber. This is the code that initializes the Subscriber :

<blockquote>

 // Build the selector on the notification messages, only interested in notifications related to the topic TOPIC
 String selector = new String( NotificationHelper.TOPIC_PROPERTY+" = '"+TOPIC+"'");
 try {
   // Subscribe to CONSUMER_OPEN_NOTIFICATION and CONSUMER_CLOSE_NOTIFICATION events with the defined selector
   openSubscriptionToken = s.subscribe(NotificationHelper.CarrierTopics[NotificationHelper.CONSUMER_OPEN_NOTIFICATION],
                                       this,
                                       selector);
   closeSubscriptionToken = s.subscribe(NotificationHelper.CarrierTopics[NotificationHelper.CONSUMER_CLOSE_NOTIFICATION],
                                        this,
                                        selector);
 } catch (javax.jms.JMSException je) {
   System.out.println("JMSException raised while subscribing to notifications");
   je.printStackTrace();
 } catch (javax.naming.NamingException ne) {
   System.out.println("NamingException raised while subscribing to notifications");
   ne.printStackTrace();
 }

 

</blockquote>

And this is how notifications are handled :

<blockquote>

 public void onMessage(javax.jms.Message message) {
   System.out.println("Got a notification");
   try {
     // Convert the Message into a Notification
     Notification n = NotificationHelper.messageToNotification(message);
     int type = n.getType();
     switch (type) {
       case NotificationHelper.CONSUMER_OPEN_NOTIFICATION:
       {
         // A subscription has been opened
         System.out.println("CONSUMER_OPEN_NOTIFICATION");
         ConsumerOpenNotification on = (ConsumerOpenNotification)n;
         // Get the subscription topic name
         String topicName = on.getTopicName();
         // Get the subscription identification
         String subscriptionId = on.getSubscriptionId();
         // Prepare a message to initialize the new subscription with the current 'satus'
         javax.jms.TextMessage m = p.createTextMessage();
         m.setText(status);
         m.setStringProperty(NotificationHelper.SUBSCRIPTION_ID_PROPERTY, subscriptionId);
         try {
           p.publish(topicName,m);
         } catch (javax.naming.NamingException ne) {
           System.out.println("NamingException raised while publishing an initialization msg");
           ne.printStackTrace();
         }
         // Enable msg publication, someone is listening
         publicationEnabled = true;
         break;
       }
       case NotificationHelper.CONSUMER_CLOSE_NOTIFICATION:
       {
         System.out.println("CONSUMER_CLOSE_NOTIFICATION");
         // Disable msg publication, subscription has been closed
         publicationEnabled = false;
         break;
       }
     }
   } catch(javax.jms.JMSException e) {
     System.out.println("JMSException raised while handling a notification");
     e.printStackTrace();
   }
 }
 

</blockquote>


Constructor & Destructor Documentation

cern::cmw::mom::test::Server::Server  )  [inline]
 

Constructor Server


Member Function Documentation

void cern::cmw::mom::test::Server::main String[]  args  )  [inline, static]
 

Method main

Parameters:
args 

void cern::cmw::mom::test::Server::onMessage javax.jms.Message  message  )  [inline]
 

Method onMessage

Parameters:
message 

void cern::cmw::mom::test::Server::start  )  [inline, private]
 

Method start


Member Data Documentation

long cern::cmw::mom::test::Server::closeSubscriptionToken = 0 [private]
 

long cern::cmw::mom::test::Server::openSubscriptionToken = 0 [private]
 

Publisher cern::cmw::mom::test::Server::p = null [private]
 

boolean cern::cmw::mom::test::Server::publicationEnabled = false [private]
 

Subscriber cern::cmw::mom::test::Server::s = null [private]
 

String cern::cmw::mom::test::Server::status = null [private]
 

final String cern::cmw::mom::test::Server::TOPIC = "CMW.ALARM_SYSTEM.ALARM_CATEGORY_TREE.CERN.INSTANT" [static, private]
 


The documentation for this class was generated from the following file:
Generated on Thu Apr 30 03:08:07 2009 for ACS Java API by doxygen 1.3.8