To provide a worklist monitor which will be informed about changes to the worklist, you can implement the interface org.eclipse.stardust.engine.core.spi.monitoring.IWorklistMonitor. This interface is used to execute custom code when item are added to or removed from a workflow participant's worklist. Typically this SPI is used to implement push notification to users like UI alerts or mails or other systems.
package org.eclipse.stardust.engine.core.spi.monitoring;
import org.eclipse.stardust.engine.api.model.IParticipant;
import org.eclipse.stardust.engine.core.runtime.beans.IActivityInstance;
public interface IWorklistMonitor
{
void addedToWorklist(IParticipant participant, IActivityInstance activityInstance);
void removedFromWorklist(IParticipant participant, IActivityInstance activityInstance);
}
The participant parameter defines the participant to whose worklist the activity instance has been added and from whose worklist the activity instance has been removed respectively. activityInstance specifies the activity instance which is affected.
Note
Use this interface with caution! We do not recommend to use this functionality to
constantly synchronize the worklists into another system.
Create your own implementations for this interface. For details on how to configure custom Service Provider Interface implementations refer to chapter Configuring SPI Implementations per Tenant.
To publish an implementor to the engine, a file named by the interface's
factory has to be created in the /META-INF/services folder of the jar
as follows:
org.eclipse.stardust.engine.core.spi.monitoring.IWorklistMonitor.
The file contents needs to be the fully qualified name of your implementation class,
e.g. org.eclipse.stardust.example.WorklistMonitorImpl.META-INF/services folder of the jar that will contain your implementation class
package org.eclipse.stardust.example;
import org.eclipse.stardust.engine.api.model.IParticipant;
import org.eclipse.stardust.engine.core.runtime.beans.IActivityInstance;
import org.eclipse.stardust.engine.core.spi.monitoring.IWorklistMonitor;
public class WorklistInterceptor implements IWorklistMonitor {
@Override
public void addedToWorklist(IParticipant arg0, IActivityInstance arg1) {
System.out.println("ADDED TO WORKLIST: " + arg0.getId() + " Activity OID: " + arg1.getOID());
}
@Override
public void removedFromWorklist(IParticipant arg0, IActivityInstance arg1) {
System.out.println("REMOVED FROM WORKLIST: " + arg0.getId() + " Activity OID: "+ arg1.getOID());
}
}
The methods in this class are called (on Session.flush())
in the following cases:
addedToWorklist(): removedFromWorklist():Note, that the notifications are not transaction save. You will be informed even if later in transaction a rollback happens and the change is not committed to the database.