WebCenter Sites's event framework enables developers to write custom business logic to execute upon certain specific events in WebCenter Sites. The custom business logic needs to be implemented in the form of Java classes in the classpath that implements a pre-defined interface. This tutorial takes you through the process of creating listeners.
This chapter takes you through the process of creating event listeners and contains the following sections:
Two types of events are currently supported by WebCenter Sites: Asset events and Publishing events.
Asset events are the events that happen when assets are added, modified or deleted, either by a user or programmatically. Upon these events, the event framework looks up and executes the set of configured events.
Publishing events are events that the RealTime publishing framework generates at each step of the publishing process. This feature is intended to facilitate system monitoring (such as SNMP) and other housekeeping processes.
This section contains the following topics:
Asset listeners need to extend AssetEventListener
in order to be notified of asset changes. A convenient base class AbstractAssetEventListener
comes with WebCenter Sites. Extending from this class makes it easy to recognize the specific type of action that led to the event (add/modify/delete).
The following sample code implements a custom asset listener. All it does is print the asset IDs; however, it is easy to see how one could plug in custom business logic.
package com.mycompany public final class CustomAssetEventListener extends AbstractAssetEventListener { public void assetAdded(AssetId id) { System.out.println("Asset " + id + " added"); } public void assetUpdated(AssetId id) { System.out.println("Asset " + id + " added"); } public void assetDeleted(AssetId id) { System.out.println("Asset " + id + " added"); } }
Asset event listeners are invoked after the asset operation has taken place, but before committing the data.
Note:
WebCenter Sites ships with a standard listener that is used for search indexing. Do not alter or delete it.
Asset event listeners are registered in the AssetListener_reg
database table. Here is the structure of the table:
Table 47-1 AssetListener_reg Database Table
ID (integer) | Unique Identifier for the Row |
---|---|
|
Fully qualified class name that implements |
|
' ' |
This section contains the following topics:
Publishing listeners need to implement PublishingEventListener
. A PublishingEvent
passed into the listener indicates the specific event that caused the invocation.
The following example shows a custom implementation that prints the pubsession
ID to the console
package com.mycompany; public class CustomPublishingEventListener implements PublishingEventListener { public void onEvent( PublishingEvent event ) throws EventException { System.out.println( "Publishing event fired for pubsession: " + event.getPubSessionId()); System.out.println( "Publishing task : " + event.getTaskName()); System.out.println( "Status of the task : " + event.getStatus()); System.out.println( "Message associated with the task : " + event.getMessage() ); } }
Publishing consists of multiple tasks (data gathering, packaging, transport, and so on), and each of them generates events. The PublishingEvent
class represents an event in the publishing task. An implementation can query the task and its status from the event as shown above.
Each task generates events when the following states are reached:
STARTED
DONE
CANCELLED
SUBTASK_FINISHED
FAILED
Publish event listeners are registered in the FW_PublishingEventRegistry
database table. Here is the structure of the table:
Table 47-2 FW_PublishingEventRegistry Database Table
ID (integer) | Unique Identifier for the Row |
---|---|
|
Fully qualified class name that implements |
|
' ' |