cern::cmw::mom::test::Server Class Reference
Inheritance diagram for cern::cmw::mom::test::Server:
[legend]Collaboration diagram for cern::cmw::mom::test::Server:
[legend]List of all members.
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] |
|
Member Function Documentation
void cern::cmw::mom::test::Server::main |
( |
String[] |
args |
) |
[inline, static] |
|
void cern::cmw::mom::test::Server::onMessage |
( |
javax.jms.Message |
message |
) |
[inline] |
|
|
Method onMessage
- Parameters:
-
|
void cern::cmw::mom::test::Server::start |
( |
|
) |
[inline, private] |
|
Member Data Documentation
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
1.3.8