[ 1732480 ] Improve callout recursive call detection

- Remove use of static variable and maintain backward compatibility.
This commit is contained in:
Heng Sin Low 2007-12-14 02:39:06 +00:00
parent 888f0954f4
commit 557d2c431f
2 changed files with 55 additions and 5 deletions

View File

@ -41,6 +41,8 @@ public class CalloutEngine implements Callout
/** Logger */
protected CLogger log = CLogger.getCLogger(getClass());
private GridTab m_mTab;
private GridField m_mField;
/**
* Start Callout.
@ -64,6 +66,10 @@ public class CalloutEngine implements Callout
{
if (methodName == null || methodName.length() == 0)
throw new IllegalArgumentException ("No Method Name");
m_mTab = mTab;
m_mField = mField;
//
String retValue = "";
StringBuffer msg = new StringBuffer(methodName).append(" - ")
@ -103,6 +109,11 @@ public class CalloutEngine implements Callout
ex.printStackTrace(System.err);
retValue = ex.getLocalizedMessage();
}
finally
{
m_mTab = null;
m_mField = null;
}
return retValue;
} // start
@ -165,24 +176,32 @@ public class CalloutEngine implements Callout
/*************************************************************************/
private static boolean s_calloutActive = false;
//private static boolean s_calloutActive = false;
/**
* Is Callout Active.
* Is the current callout being called in the middle of
* another callout doing her works.
* Callout can use GridTab.getActiveCalloutInstance() method
* to find out callout for which field is running.
* @return true if active
*/
protected static boolean isCalloutActive()
protected boolean isCalloutActive()
{
return s_calloutActive;
//greater than 1 instead of 0 to discount this callout instance
return m_mTab != null ? m_mTab.getActiveCallouts().length > 1 : false;
} // isCalloutActive
/**
* Set Callout (in)active.
* Deprecated as the implementation is not thread safe and
* fragile - break other callout if developer forget to call
* setCalloutActive(false) after calling setCalloutActive(true).
* @deprecated
* @param active active
*/
protected static void setCalloutActive (boolean active)
{
s_calloutActive = active;
;
} // setCalloutActive
/**
@ -238,5 +257,23 @@ public class CalloutEngine implements Callout
setCalloutActive(false);
return "";
} // rate
/**
*
* @return gridTab
*/
public GridTab getGridTab()
{
return m_mTab;
}
/**
*
* @return gridField
*/
public GridField getGridField()
{
return m_mField;
}
} // CalloutEngine

View File

@ -2352,6 +2352,7 @@ public class GridTab implements DataStatusListener, Evaluatee, Serializable
private List<String> activeCallouts = new ArrayList<String>();
private List<Callout> activeCalloutInstance = new ArrayList<Callout>();
/**
*
@ -2362,6 +2363,16 @@ public class GridTab implements DataStatusListener, Evaluatee, Serializable
String[] list = new String[activeCallouts.size()];
return activeCallouts.toArray(list);
}
/**
*
* @return list of active call out instance for this tab
*/
public Callout[] getActiveCalloutInstance()
{
Callout[] list = new Callout[activeCalloutInstance.size()];
return activeCalloutInstance.toArray(list);
}
/**************************************************************************
* Process Callout(s).
@ -2425,6 +2436,7 @@ public class GridTab implements DataStatusListener, Evaluatee, Serializable
try
{
activeCallouts.add(cmd);
activeCalloutInstance.add(call);
retValue = call.start(m_vo.ctx, method, m_vo.WindowNo, this, field, value, oldValue);
}
catch (Exception e)
@ -2436,6 +2448,7 @@ public class GridTab implements DataStatusListener, Evaluatee, Serializable
finally
{
activeCallouts.remove(cmd);
activeCalloutInstance.remove(call);
}
if (!retValue.equals("")) // interrupt on first error