apache > ws.apache
Apache Muse
 

Apache Muse - Publish Any Notification Message

If you add the WSN NotificationProducer capability to your resource type, you can use it to publish messages that will be sorted and sent to subscribers without you having to understand how subscription data is managed or who is listening for notifications at any given time. All you have to do is give the message payload to the NotificationProducer capability and it will wrap it in the WSN message format, figure out who should receive the message, and put it on the wire.

Note
Publishing WSRP change notifications is a special case explained in a separate how-to.

The code below illustrates how to send an arbitrary XML payload to current subscribers from within your capability classes:

import org.apache.muse.ws.notification.*;
import org.apache.muse.util.xml.*;

...

NotificationProducer wsn = (NotificationProducer)getResource().getCapability(WsnConstants.PRODUCER_URI);

//
// you can add topics programmatically or via RMD document
//
QName topicName = new QName("http://example.com/server-product", "ServerUpdates");
wsn.addTopic(topicName);

//
// you can later publish messages to the topic
//
QName messageName = new QName("http://example.com/server-product", "UpdateMessage");
String updateMessage = "Something important happened!";
Element payload = XmlUtils.createElement(messageName, updateMessage);

wsn.publish(topicName, payload);

Programmers who are using WSDM to describe manageability interfaces will want to use the WSDM Event Format (WEF) to format the payloads they publish:

import org.apache.muse.ws.dm.muws.events.*;

...

WefFactory factory = new SimpleWefFactory();
ManagementEvent event = factory.createEvent();

Situation situation = factory.createSituation();
situation.setCategoryType(WefConstants.AVAILABLILITY_SITUATION_QNAME);
situation.setPriority(Situation.HIGH_PRIORITY);
situation.setMessage("Something important has happened!");
event.setSituation(situation);

wsn.publish(topicName, event);