65 Understanding Asset and Publish Events in WebCenter Sites

WebCenter Sites supports Asset events and Publishing events in the current release.

Topics:

Asset Events

Asset events take place when assets are added, modified or deleted by a contributor or programmatically. Upon these events, the event framework looks up and executes the set of configured events.

This topic describes how to write and register an asset event listener.

Writing an Asset Event Listener

Asset listeners have to extend AssetEventListener 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).

Implement a custom asset listener using the sample code. This code prints the asset IDs; however, you can also 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 + " updated");
    }
    public void assetDeleted(AssetId id)
    {
        System.out.println("Asset " + id + " deleted");
    }
}

Blocking asset event listeners are invoked after the asset operation has taken place, but before committing the data. Non-blocking asset event listeners are invoked asynchronously.

Registering an Asset Event Listener

This section describes how to register an asset event listener.

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.

Table 65-1 AssetListener_reg Database Table

ID (integer) Unique Identifier for the Row

listener(String)

Fully qualified class name that implements AssetEventListener. For example: com.mycompany.CustomAssetEventListener

blocking(Y or N)

'Y' indicates that the listener is blocking (runs synchronously with the thread that generated the event).

'N' indicates that the listener is non-blocking (runs in a separate thread).

Publishing 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.

Topics:

Writing a Publishing Event Listener

Publishing listeners have to implement PublishingEventListener. A PublishingEvent passed into the listener indicates the specific event that caused the invocation.

Use the following example to implement a custom even listener 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

Registering a Publishing Event Listener

  • Register Publish event listeners in the FW_PublishingEventRegistry database table.

    Table 65-2 FW_PublishingEventRegistry Database Table

    ID (integer) Unique Identifier for the Row

    listener(String)

    Fully qualified class name that implements PublishingEventListener. For example: com.mycompany.CustomPublishingEventListener

    blocking(Y or N)

    'Y' indicates that the listener is blocking (runs synchronously with the thread that generated the event).

    'N' indicates that the listener is non-blocking (runs in a separate thread).