* @return a string of messages decribing the success or otherwise of
* the process
*/
public String replaceWorklet(int xType, String caseid, String itemid, String trigger) {
String result, workletCaseID ;
WorkItemRecord wir = null;
boolean caseLevel = isCaseLevelException(xType);
CaseMonitor mon = (CaseMonitor) _monitoredCases.get(caseid);
_log.info("REPLACE EXECUTING WORKLET REQUEST");
result = "Locating " +
(caseLevel? "case '" + caseid : "workitem '" + itemid) +
"' in the set of currently handled cases...";
caseid = getIntegralID(caseid);
// if case is currently being handled
if (mon != null) {
result += "found." + Library.newline ;
_log.debug("Caseid received found in monitoredCases: " + caseid);
// get the HandlerRunner for the Exception
HandlerRunner hr = mon.getRunnerForType(xType, itemid) ;
if (! caseLevel) wir = hr.getItem();
// get the case ids of the running worklets for this case/workitem
Iterator witr = hr.getRunningCaseIds().iterator() ;
while (witr.hasNext()) {
workletCaseID = (String) witr.next() ;
// cancel the worklet running for the case/workitem
result += "Cancelling running worklet case with case id " + workletCaseID + "...";
_log.debug("Running worklet case id for this case/item is: " + workletCaseID);
removeCase(workletCaseID);
_log.debug("Removing worklet from handlers started: " + workletCaseID);
_handlersStarted.remove(workletCaseID) ;
result += "done." + Library.newline ;
}
// go through the selection process again
result += "Launching new replacement worklet case(s) based on revised ruleset...";
_log.debug("Launching new replacement worklet case(s) based on revised ruleset");
// refresh ruleset to pickup newly added rule
RefreshRuleSet(mon.getSpecID());
// remove monitor's runner for cancelled worklet
mon.removeHandlerRunner(hr);
if (_persisting) _dbMgr.persist(hr, DBManager.DB_DELETE);
// go through the process again, depending on the exception type
switch (xType) {
case XTYPE_CASE_PRE_CONSTRAINTS : checkConstraints(mon, true); break;
case XTYPE_CASE_POST_CONSTRAINTS : checkConstraints(mon, false); break;
case XTYPE_ITEM_PRE_CONSTRAINTS : checkConstraints(mon, wir, true); break;
case XTYPE_ITEM_POST_CONSTRAINTS : checkConstraints(mon, wir, false); break;
case XTYPE_WORKITEM_ABORT : break; // not yet implemented
case XTYPE_TIMEOUT :
if (wir != null) handleTimeoutEvent(wir, wir.getTaskID()); break ;
case XTYPE_RESOURCE_UNAVAILABLE : break; // not yet implemented
case XTYPE_CONSTRAINT_VIOLATION : break; // not yet implemented
case XTYPE_CASE_EXTERNAL_TRIGGER :
raiseExternalException("case", caseid, trigger); break;
case XTYPE_ITEM_EXTERNAL_TRIGGER :