String type = event.eventType();
if (!type.equals(WfAuditEvent.PROCESS_STATE_CHANGED)) {
return;
}
WfStateAuditEvent stateEvent = (WfStateAuditEvent) event;
String mgrName = stateEvent.processMgrName();
String[] ids = mgrName.split("/");
String packageId = ids[0];
String processId = ids[1];
String processKey = stateEvent.processKey();
Collection observers;
try {
observers = observerRegistry.getObservers(packageId, processId, processKey);
} catch (SQLException sqle) {
logger.warn("error retrieving observer list", sqle);
return;
}
for (Iterator iterator=observers.iterator(); iterator.hasNext();) {
ObserverInfo observerInfo = (ObserverInfo)iterator.next();
ResourceReference resRef = new ResourceReference
(observerInfo.getSenderBase(),
packageId, processId, event.processKey());
InstanceResponseGenerator irg = new InstanceResponseGenerator
(observerRegistry, workflowService, resRef);
try {
sendStateChanged
(observerInfo.getObserverKey(), irg, stateEvent);
if (stateEvent instanceof ProcessClosedAuditEvent) {
ProcessData result
= ((ProcessClosedAuditEvent)stateEvent).result();
sendCompleted (observerInfo.getObserverKey(), irg, result);
}
} catch (IllegalStateException e) {
logger.warn ("Problem sending event to "
+ observerInfo.getObserverKey() + ": "
+ e.getMessage(), e);
try {
observerRegistry.unsubscribe(observerInfo.getObserverKey());
} catch (SQLException ee) {
logger.warn("error removing observer", ee);
return;
}
}
}
// Do some cleanup if the process is no more available.
if (stateEvent.newState().startsWith("closed")) {
try {
observerRegistry.unsubscribe(packageId, processId, processKey);
} catch (SQLException e) {
logger.warn("error unsubscribing observer", e);
return;