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

static 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

static 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

References p, s, start(), and status.

Referenced by main().


Member Function Documentation

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

Method main

Parameters:
args 

References Server().

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

Member Data Documentation

Referenced by start().

Referenced by start().

Referenced by onMessage(), Server(), and start().

Referenced by onMessage(), and start().

Referenced by Server(), and start().

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

Referenced by onMessage(), Server(), and start().

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

Referenced by start().


The documentation for this class was generated from the following file:

Generated by  doxygen 1.6.2