[ 1854603 ] Prepare method is being called twice

- trx management fix.
- remove non-thread safe code.
This commit is contained in:
Heng Sin Low 2008-02-14 04:49:18 +00:00
parent ac21848e01
commit 3c059e91c8
5 changed files with 57 additions and 19 deletions

View File

@ -249,7 +249,7 @@ public final class ProcessUtil {
MWorkflow wf = MWorkflow.get (ctx, AD_Workflow_ID);
MWFProcess wfProcess = null;
if (pi.isBatch())
wfProcess = wf.start(pi); // may return null
wfProcess = wf.start(pi, null); // may return null
else
wfProcess = wf.startWait(pi); // may return null
log.fine(pi.toString());

View File

@ -125,7 +125,7 @@ public class DocWorkflowManager implements DocWorkflowMgr
pi.setAD_User_ID (Env.getAD_User_ID(document.getCtx()));
pi.setAD_Client_ID(document.getAD_Client_ID());
//
if (wf.start(pi) != null)
if (wf.start(pi, document.get_TrxName()) != null)
{
log.config(wf.getName());
m_noStarted++;

View File

@ -736,8 +736,9 @@ public class MWFActivity extends X_AD_WF_Activity implements Runnable
log.info ("Node=" + getNode());
m_newValue = null;
String trxName = Trx.createTrxName("WF");
m_trx = Trx.get(trxName, true);
m_trx = Trx.get(Trx.createTrxName("WFA"), true);
//
try
{
@ -759,11 +760,6 @@ public class MWFActivity extends X_AD_WF_Activity implements Runnable
// Do Work
/**** Trx Start ****/
boolean done = performWork(m_trx);
//begin vpj-cd e-evolution 03/08/2005 PostgreSQL
// Reason: When is execute setWFState create a transaction for same table is generate a clicle Trx
// is cause that PostgreSQL wait into transaction idle
//setWFState (done ? StateEngine.STATE_Completed : StateEngine.STATE_Suspended);
//end vpj-cd e-evolution 03/08/2005 PostgreSQL
/**** Trx End ****/
// teo_sarca [ 1708835 ]
@ -776,9 +772,9 @@ public class MWFActivity extends X_AD_WF_Activity implements Runnable
m_docStatus = DocAction.STATUS_Invalid;
throw e;
}
//begin vpj-cd e-evolution 03/08/2005 PostgreSQL
//Reason: setWFState moved for the first trx be finished
setWFState (done ? StateEngine.STATE_Completed : StateEngine.STATE_Suspended);
//end vpj-cd e-evolution 03/08/2005 PostgreSQL
if (m_postImmediate != null)
postImmediate();
@ -792,6 +788,7 @@ public class MWFActivity extends X_AD_WF_Activity implements Runnable
//
if (e.getCause() != null)
log.log(Level.WARNING, "Cause", e.getCause());
String processMsg = e.getLocalizedMessage();
if (processMsg == null || processMsg.length() == 0)
processMsg = e.getMessage();

View File

@ -72,11 +72,24 @@ public class MWFProcess extends X_AD_WF_Process
* New Constructor
* @param wf workflow
* @param pi Process Info (Record_ID)
* @deprecated
* @throws Exception
*/
public MWFProcess (MWorkflow wf, ProcessInfo pi) throws Exception
{
super (wf.getCtx(), 0, wf.get_TrxName());
this(wf, pi, wf.get_TrxName());
}
/**
* New Constructor
* @param wf workflow
* @param pi Process Info (Record_ID)
* @param trxName
* @throws Exception
*/
public MWFProcess (MWorkflow wf, ProcessInfo pi, String trxName) throws Exception
{
super (wf.getCtx(), 0, trxName);
if (!TimeUtil.isValid(wf.getValidFrom(), wf.getValidTo()))
throw new IllegalStateException("Workflow not valid");
m_wf = wf;
@ -251,6 +264,10 @@ public class MWFProcess extends X_AD_WF_Process
+ (trxName == null ? "" : "[" + trxName + "]"));
if (m_state.isClosed())
return;
if (lastPO != null && lastPO.get_ID() == this.getRecord_ID())
m_po = lastPO;
//
MWFActivity[] activities = getActivities (true, true, trxName); // requery active
String closedState = null;
@ -306,7 +323,7 @@ public class MWFProcess extends X_AD_WF_Process
setWFState(closedState);
getPO();
if (m_po != null)
m_po.unlock(trxName);
m_po.unlock(null);
}
else if (suspended)
setWFState(WFSTATE_Suspended);
@ -487,7 +504,7 @@ public class MWFProcess extends X_AD_WF_Process
activity.run();
}
catch (Exception e)
catch (Throwable e)
{
log.log(Level.SEVERE, "AD_WF_Node_ID=" + AD_WF_Node_ID, e);
setTextMsg(e.toString());

View File

@ -119,6 +119,8 @@ public class MWorkflow extends X_AD_Workflow
}
// Look for Entry
MWorkflow[] retValue = (MWorkflow[])s_cacheDocValue.get(key);
//hengsin: this is not threadsafe
/*
//set trxName to all workflow instance
if ( retValue != null && retValue.length > 0 )
{
@ -126,7 +128,7 @@ public class MWorkflow extends X_AD_Workflow
{
retValue[i].set_TrxName(trxName);
}
}
}*/
return retValue;
} // getDocValue
@ -643,28 +645,50 @@ public class MWorkflow extends X_AD_Workflow
return success;
} // afterSave
/**************************************************************************
* Start Workflow.
* @param pi Process Info (Record_ID)
* @deprecated
* @return process
*/
public MWFProcess start (ProcessInfo pi)
{
return start(pi, null);
}
/**************************************************************************
* Start Workflow.
* @param pi Process Info (Record_ID)
* @return process
*/
public MWFProcess start (ProcessInfo pi)
public MWFProcess start (ProcessInfo pi, String trxName)
{
MWFProcess retValue = null;
Trx localTrx = null;
if (trxName == null)
localTrx = Trx.get(Trx.createTrxName("WFP"), true);
try
{
retValue = new MWFProcess (this, pi);
retValue = new MWFProcess (this, pi, trxName != null ? trxName : localTrx.getTrxName());
retValue.save();
retValue.startWork();
pi.setSummary(Msg.getMsg(getCtx(), "Processing"));
retValue.startWork();
if (localTrx != null)
localTrx.commit(true);
}
catch (Exception e)
{
if (localTrx != null)
localTrx.rollback();
log.log(Level.SEVERE, e.getLocalizedMessage(), e);
pi.setSummary(e.getMessage(), true);
retValue = null;
}
finally
{
if (localTrx != null)
localTrx.close();
}
return retValue;
} // MWFProcess
@ -678,7 +702,7 @@ public class MWorkflow extends X_AD_Workflow
final int SLEEP = 500; // 1/2 sec
final int MAXLOOPS = 30; // 15 sec
//
MWFProcess process = start(pi);
MWFProcess process = start(pi, null);
if (process == null)
return null;
Thread.yield();