super.initializeCompleted();
//
// access resource's WSN capability and create a new topic
//
final NotificationProducer wsn = (NotificationProducer)getResource().getCapability(WsnConstants.PRODUCER_URI);
wsn.addTopic(_TOPIC_NAME);
Thread producer = new Thread() {
public void run()
{
//
// for this example, reuse one payload for every notification
//
QName messageName = new QName(NAMESPACE_URI, "MyMessage", PREFIX);
String message = "This is a message from " + getServerName();
Element payload = XmlUtils.createElement(messageName, message);
while (true)
{
try
{
//
// read current value - property is mutable
//
int currentInterval = getMessageInterval();
getLog().info("Waiting " + currentInterval + " seconds before sending message...");
Thread.currentThread().sleep(currentInterval * 1000);
//
// use WSN capability to send message to any subscribers
//
getLog().info("Sending message to consumers...");
wsn.publish(_TOPIC_NAME, payload);
}
catch (Throwable error)
{
error.printStackTrace();