apache > ws.apache
Apache Muse
 

Apache Muse - Publish WSRP Change Notifications

If you add the WSN NotificationProducer capability to your resource type, it will automatically send out WSRP change notifications every time the WSRP SetResourceProperties operation is used to modify a property. It also creates a WSN topic for each resource property so that clients can subscribe to notifications about individual properties, with the topic name being equal to the property name. In other words, for changes made via WSRP, you don't have to do anything!

If a property changed in an external component and you learn about it through some resource-specific listener API, you can still send notifications without too much trouble. You must fire the property change listeners on the WSRP document, one of which will be the listener that sends change notifications via WSN NotificationProducer. Since the property change is already complete, there is no need to fire the change approval listeners that usually perform validation on the change request. The code below can be executed from within a WSRF-based capability and it assumes that you are obtaining the property name and values from a resource-specific API:

import org.apache.muse.ws.resource.properties.*;
import org.apache.muse.ws.resource.properties.listeners.*;

...

//
// in this scenario, we are alerted to a property change
// that occurred outside of WSRP requests, and that alert
// presumably contains the name/value pair for the change
//
QName name = ...;
Element oldValue = ...;
Element newValue = ...;

ResourcePropertyCollection wsrp = getWsResource().getPropertyCollection();
Iterator i = wsrp.getChangeListeners(name);

while (i.hasNext())
{
    PropertyChangeListener listener = (PropertyChangeListener)i.next();
    listener.propertyChanged(oldValue, newValue);
}