WorkflowWork workflowWork)
throws WorkflowException, ScriptException
{
log.debug("[dispatch_core] workitem: " + workflowWork.getInfo());
WorkflowActivity workflowActivity = workflowWork.getWorkflowActivity();
WorkflowActivityEvent event = new WorkflowActivityEvent(workflowWork, WorkflowActivityEvent.WORK_DISPATCH);
WorkflowActivityListener[] listeners = workflowActivity.getWorkflowActivityListeners();
for (int i = 0; i < listeners.length; ++i)
{
listeners[i].beforeDispatched(event);
}
WorkflowCase workflowCase = workflowWork.getWorkflowCase();
WorkflowPackage workflowPackage = workflowProcess.getWorkflowPackage();
workflowWork.setDispatchTime(new java.util.Date());
caseDatabase.updateWorkflowWork(workflowProcess, operator, userTransaction, workflowWork);
//------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------
WorkflowTransition customizedTransition = dispatch_revert(workflowService,workflowProcess,operator,caseDatabase,userTransaction,workflowWork);
List filterTrans = null;
if (customizedTransition == null)
{
filterTrans =
OutTransitionFilter.filterOutTransition(workflowService,
operator,
caseDatabase,
userTransaction,
workflowWork);
}
else
{
filterTrans = new ArrayList();
filterTrans.add(customizedTransition);
}
int sizeTrans = filterTrans.size();
if (sizeTrans > 0)
{
WorkflowTransition transition = null;
//-------------------------------------------------------------
// �������ɷ������Ĺ�����ʹ����ͬ���ɷ��Ǻ�
//--------------------------------------------------------------
String pathDispBatch = null;
pathDispBatch =
caseDatabase.getCaseIdGenerator().genWorkflowPathBatch(
workflowPackage.getUUID(),
workflowProcess.getUUID(),
workflowActivity.getUUID(),
workflowCase.getUUID());
ParallelThread pThreads[] =new ParallelThread[sizeTrans];
for (int i = 0; i < sizeTrans; ++i)
{
transition = (WorkflowTransition) filterTrans.get(i);
// dispatch_control(workflowService,
// workflowProcess,
// operator,
// caseDatabase,
// userTransaction,
// workflowWork,
// transition,
// pathDispBatch);
pThreads[i]=new ParallelThread(workflowService,
workflowProcess,
operator,
caseDatabase,
userTransaction,
workflowWork,
transition,
pathDispBatch);
pThreads[i].start();
}
WorkflowException dispatch_exception = null;
for (int i = 0; i < sizeTrans; ++i)
{
try
{
pThreads[i].join();
if(pThreads[i].getException() != null)
{
dispatch_exception = pThreads[i].getException();
}
}
catch(InterruptedException ex)
{
dispatch_exception = new WorkflowException("another thread has interrupted the ParallelThread");
}
}
if(dispatch_exception != null)
{
throw dispatch_exception;
}
}
else
{
// how I can do? just log it
WorkflowContext context = workflowService.getWorkflowContext();
String message =
"---------BEGIN-------------Damn It ,Fatal Error----------------------\n"
+ "no available outgoing transition found. shXt, willow is powered by zosatapo (dertyang@hotmail.com) . \n"
+ "\t\t PackageID = "
+ workflowPackage.getUUID()
+ "\n"
+ "\t\t ProcessID = "
+ workflowProcess.getUUID()
+ "\n"
+ "\t\t ActivityID = "
+ workflowActivity.getUUID()
+ "\n"
+ "---------END-------------Damn It ,Fatal Error----------------------\n";
context.log(message);
}