Kernel level WSN support

compared with
Key
This line was removed.
This word was removed. This word was added.
This line was added.

Changes (3)

View Page History
h2. Publish notifications

You can directly publish notifications to the available kernel topics from Java clients by using the _NotificationCenter_ defined in _org.petalslink.dsb.kernel.pubsub.service.NotificationCenter_ (module deb-kernel-pubsubservice). To do that, just get the instance of the NotificationCenter and its notification sender, then call the notify operation:
You can directly publish notifications to the available kernel topics from Java clients by using the _NotificationCenter_ defined in _org.petalslink.dsb.kernel.pubsub.service.NotificationCenter_ (module deb-kernel-pubsubservice). Here is the NotificationSender interface definition:
{code}/**
*
*/
package org.petalslink.dsb.notification.commons.api;

import javax.xml.namespace.QName;

import org.petalslink.dsb.notification.commons.NotificationException;
import org.w3c.dom.Document;

import com.ebmwebsourcing.wsstar.basenotification.datatypes.api.abstraction.Notify;

/**
* Send notification on topics ie on all the consumers which are registered in
* the topic... A call to {@link #notify(Document, QName, String)} can reach N
* destination. It is up to the implementation to handle thread pools for
* efficiency for example...
*
* @author chamerling
*
*/
public interface NotificationSender {

/**
* Notify with a given payload. This will build the notification message
* with the given parameters.
*
* @param notify
* @param topic
* @param dialect
* @throws NotificationException
*/
void notify(final Document payload, final QName topic, final String dialect)
throws NotificationException;

/**
* Notify with a prefilled notification message.
*
* @param notify
* @throws NotificationException
*/
void notify(Notify notify) throws NotificationException;

}
{code}
To send the notification, just get the instance of the NotificationCenter and its notification sender, then call the notify operation:
{code:language=java}/**
*
*/
package org.petalslink.dsb.kernel.pubsub.service;

import org.objectweb.fractal.fraclet.annotation.annotations.FractalComponent;
import org.objectweb.fractal.fraclet.annotation.annotations.Interface;
import org.objectweb.fractal.fraclet.annotation.annotations.LifeCycle;
import org.objectweb.fractal.fraclet.annotation.annotations.Monolog;
import org.objectweb.fractal.fraclet.annotation.annotations.Provides;
import org.objectweb.fractal.fraclet.annotation.annotations.type.LifeCycleType;
import org.objectweb.util.monolog.api.Logger;
import org.ow2.petals.util.LoggingUtil;
import org.petalslink.dsb.notification.commons.NotificationException;
import org.petalslink.dsb.notification.commons.api.NotificationSender;

import com.ebmwebsourcing.wsstar.basenotification.datatypes.api.abstraction.Notify;
import com.ebmwebsourcing.wsstar.basenotification.datatypes.api.utils.WsnbException;
import com.ebmwebsourcing.wsstar.wsnb.services.INotificationConsumer;

/**
* This consumer service is a facade to the notification engine. It is just used
* to forward internal kernel calls to interested parties...
*
* @author chamerling
*
*/
@FractalComponent
@Provides(interfaces = { @Interface(name = "service", signature = INotificationConsumer.class) })
public class NotificationConsumerServiceImpl implements INotificationConsumer {

@Monolog(name = "logger")
private Logger logger;

private LoggingUtil log;

@LifeCycle(on = LifeCycleType.START)
protected void start() {
this.log = new LoggingUtil(this.logger);
}

@LifeCycle(on = LifeCycleType.STOP)
protected void stop() {
}

/*
* (non-Javadoc)
*
* @see
* com.ebmwebsourcing.wsstar.wsnb.services.INotificationConsumer#notify(
* com.ebmwebsourcing
* .wsstar.basenotification.datatypes.api.abstraction.Notify)
*/
public void notify(Notify notify) throws WsnbException {
if (log.isDebugEnabled()) {
log.debug("Got a notify message at the kernel level!");
}

// Let see if the notification center is available...
NotificationSender sender = NotificationCenter.get().getSender();
if (sender == null) {
log.warning("Can not find the notification sender");
return;
}

try {
sender.notify(notify);
} catch (NotificationException e) {
throw new WsnbException(e);
}
}

}
{code}
As a result, the notification will eb published to the topic (if available) and then distributed to all subscribers. Up to the notification engine will send notifications using the right transport...