use of org.wso2.carbon.bpel.b4p.coordination.dao.TaskProtocolHandler in project carbon-business-process by wso2.
the class TerminationTask method run.
@Override
public void run() {
PrivilegedCarbonContext.startTenantFlow();
PrivilegedCarbonContext privilegedCarbonContext = PrivilegedCarbonContext.getThreadLocalCarbonContext();
privilegedCarbonContext.setTenantId(tenantID, true);
try {
List<TaskProtocolHandler> taskProtocolHandlers = null;
try {
taskProtocolHandlers = getHTProtocolHandlerURLWithTasks(instanceID);
} catch (Exception e) {
log.error("Error occurred while retrieving coordination data", e);
}
String currentProtocolHandler = "";
ExitProtocolMessage currentExitMessage = null;
for (TaskProtocolHandler taskProtocolHandler : taskProtocolHandlers) {
// Task Protocol Handler and Task ID should be not null
if (taskProtocolHandler.getProtocolHandlerURL() != null && taskProtocolHandler.getTaskID() != null) {
if (!currentProtocolHandler.equals(taskProtocolHandler.getProtocolHandlerURL())) {
// found a new protocol handler URL, so invoking old exit message.
if (currentExitMessage != null) {
// To ignore initial condition, we do null check here.
invokeProtocolHandler(currentExitMessage);
}
currentExitMessage = new ExitProtocolMessage(taskProtocolHandler.getProtocolHandlerURL());
currentProtocolHandler = taskProtocolHandler.getProtocolHandlerURL();
}
currentExitMessage.getTaskIDs().add(taskProtocolHandler.getTaskID());
if (log.isDebugEnabled()) {
log.debug("building exit protocol message for task id:" + taskProtocolHandler.getTaskID());
}
}
}
if (currentExitMessage != null) {
// Here we do last invocation.
invokeProtocolHandler(currentExitMessage);
}
// Cleaning coordination data.
boolean deleted = false;
try {
deleted = deleteCoordinationData(instanceID);
} catch (Exception e) {
log.error("Error occurred while cleaning coordination data for process instance id " + instanceID, e);
}
if (deleted && log.isDebugEnabled()) {
log.debug("Coordination data are removed from database for process instance id " + instanceID);
}
} finally {
PrivilegedCarbonContext.endTenantFlow();
}
}
Aggregations