[ 1732480 ] Improve callout recursive call detection
- Remove use of static variable and maintain backward compatibility.
This commit is contained in:
parent
888f0954f4
commit
557d2c431f
|
@ -41,6 +41,8 @@ public class CalloutEngine implements Callout
|
||||||
|
|
||||||
/** Logger */
|
/** Logger */
|
||||||
protected CLogger log = CLogger.getCLogger(getClass());
|
protected CLogger log = CLogger.getCLogger(getClass());
|
||||||
|
private GridTab m_mTab;
|
||||||
|
private GridField m_mField;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Start Callout.
|
* Start Callout.
|
||||||
|
@ -64,6 +66,10 @@ public class CalloutEngine implements Callout
|
||||||
{
|
{
|
||||||
if (methodName == null || methodName.length() == 0)
|
if (methodName == null || methodName.length() == 0)
|
||||||
throw new IllegalArgumentException ("No Method Name");
|
throw new IllegalArgumentException ("No Method Name");
|
||||||
|
|
||||||
|
m_mTab = mTab;
|
||||||
|
m_mField = mField;
|
||||||
|
|
||||||
//
|
//
|
||||||
String retValue = "";
|
String retValue = "";
|
||||||
StringBuffer msg = new StringBuffer(methodName).append(" - ")
|
StringBuffer msg = new StringBuffer(methodName).append(" - ")
|
||||||
|
@ -103,6 +109,11 @@ public class CalloutEngine implements Callout
|
||||||
ex.printStackTrace(System.err);
|
ex.printStackTrace(System.err);
|
||||||
retValue = ex.getLocalizedMessage();
|
retValue = ex.getLocalizedMessage();
|
||||||
}
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
m_mTab = null;
|
||||||
|
m_mField = null;
|
||||||
|
}
|
||||||
return retValue;
|
return retValue;
|
||||||
} // start
|
} // 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
|
* @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
|
} // isCalloutActive
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set Callout (in)active.
|
* 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
|
* @param active active
|
||||||
*/
|
*/
|
||||||
protected static void setCalloutActive (boolean active)
|
protected static void setCalloutActive (boolean active)
|
||||||
{
|
{
|
||||||
s_calloutActive = active;
|
;
|
||||||
} // setCalloutActive
|
} // setCalloutActive
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -238,5 +257,23 @@ public class CalloutEngine implements Callout
|
||||||
setCalloutActive(false);
|
setCalloutActive(false);
|
||||||
return "";
|
return "";
|
||||||
} // rate
|
} // rate
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @return gridTab
|
||||||
|
*/
|
||||||
|
public GridTab getGridTab()
|
||||||
|
{
|
||||||
|
return m_mTab;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @return gridField
|
||||||
|
*/
|
||||||
|
public GridField getGridField()
|
||||||
|
{
|
||||||
|
return m_mField;
|
||||||
|
}
|
||||||
|
|
||||||
} // CalloutEngine
|
} // CalloutEngine
|
||||||
|
|
|
@ -2352,6 +2352,7 @@ public class GridTab implements DataStatusListener, Evaluatee, Serializable
|
||||||
|
|
||||||
|
|
||||||
private List<String> activeCallouts = new ArrayList<String>();
|
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()];
|
String[] list = new String[activeCallouts.size()];
|
||||||
return activeCallouts.toArray(list);
|
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).
|
* Process Callout(s).
|
||||||
|
@ -2425,6 +2436,7 @@ public class GridTab implements DataStatusListener, Evaluatee, Serializable
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
activeCallouts.add(cmd);
|
activeCallouts.add(cmd);
|
||||||
|
activeCalloutInstance.add(call);
|
||||||
retValue = call.start(m_vo.ctx, method, m_vo.WindowNo, this, field, value, oldValue);
|
retValue = call.start(m_vo.ctx, method, m_vo.WindowNo, this, field, value, oldValue);
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
|
@ -2436,6 +2448,7 @@ public class GridTab implements DataStatusListener, Evaluatee, Serializable
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
activeCallouts.remove(cmd);
|
activeCallouts.remove(cmd);
|
||||||
|
activeCalloutInstance.remove(call);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!retValue.equals("")) // interrupt on first error
|
if (!retValue.equals("")) // interrupt on first error
|
||||||
|
|
Loading…
Reference in New Issue