apache > ws.apache
Pubscribe
 

Notification Producer

Introduction

This section provides instructions for adding notification topics for a resource. Each resource that is configured to be a notification producer (implements the WSN NotificationProducer portType) is associated with a TopicSet object. The resource publishes notifications to a topic in the topic set. Notification consumers can then subscribe to a topic and receive notifications from the resource. As the service developer of the notification producer resource, you are responsible for adding the topics you want to support to the topic set. In addition, you must initialize all topics. This is done using Pubscribe APIs.

Adding Topics

Notification topics must be added to the init() method of your service's resource class. If you used the Wsdl2Java tool, the resource class ( service_name Resource.java) is automatically generated, but will need to modified. The resource class is the stateful instance-representation of your Web service. In addition to notification topics, the resource class maintains the resource id and the ResourcePropertySet. The ResourcePropertySet is the Java representation of the Resource Properties document defined in the schema section of your WSDL file.

Note
The notification producer portType resource properties (Topic, FixedTopicSet, TopicExpressionDialects) are initialized by default and do not have to be initalized here.

This section discusses how to add topics to a resource class for each resource property. Topics emit notifications if any resource property changes in any way. Initially, you should model your resource off of the included FileSystemResource example to ensure that you write a valid resource class. When adding topics to the resource class, you can select to add topics for all resource properties or you can add topics for specific resource properties. Each style is discussed below.

Note
This section does not include instructions for initializing resource properties and adding them to the ResourcePropertySet. See the Resource Class documentation included with Apache WSRF.

Topics for All Resource Properties

The easiest way to add notification topics is to add topics for all resource properties that a WS resource exposes. In this case, the following method is added to the resource class:

try
  {
  org.apache.ws.notification.topics.util.TopicUtils.addResourcePropertyValueChangeTopics( getResourcePropertySet(), getTopicSpaceSet() );
  }

In the above example, a notification topic is added for all resource properties that have been added to ResourcePropertySet.

Topics for Specific Resource Properties

Notification topics can be added for specific resource properties. This allows you to control which topics will be available to a notification consumer. In this case, the following method can be used for each resource property for which you want to add a topic:

try
   {
   org.apache.ws.notification.topics.util.TopicUtils.addResourcePropertyValueChangeTopic( getResourcePropertySet().get( FilesystemPropertyQNames.FSCKPASSNUMBER ), getTopicSpaceSet() );
   }

In the above example a topic is created specifically for the FSCKPASSNUMBER resource property.

Resource Termination Topic

The resource termination topic is used for notifications when a resource is terminated. The use of this topic is optional. To add this topic to the resource class, use the following method:

org.apache.ws.notification.topics.util.TopicUtils.addResourceTerminationTopic( getTopicSpaceSet(), this, SPEC_NAMESPACE_SET );