From 557d2c431f00923274d0a36856869545ed96494a Mon Sep 17 00:00:00 2001 From: Heng Sin Low Date: Fri, 14 Dec 2007 02:39:06 +0000 Subject: [PATCH] [ 1732480 ] Improve callout recursive call detection - Remove use of static variable and maintain backward compatibility. --- .../src/org/compiere/model/CalloutEngine.java | 47 +++++++++++++++++-- base/src/org/compiere/model/GridTab.java | 13 +++++ 2 files changed, 55 insertions(+), 5 deletions(-) diff --git a/base/src/org/compiere/model/CalloutEngine.java b/base/src/org/compiere/model/CalloutEngine.java index 730e787b9a..93e624f5bc 100644 --- a/base/src/org/compiere/model/CalloutEngine.java +++ b/base/src/org/compiere/model/CalloutEngine.java @@ -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 diff --git a/base/src/org/compiere/model/GridTab.java b/base/src/org/compiere/model/GridTab.java index 50c4f72822..ccaafc04d9 100644 --- a/base/src/org/compiere/model/GridTab.java +++ b/base/src/org/compiere/model/GridTab.java @@ -2352,6 +2352,7 @@ public class GridTab implements DataStatusListener, Evaluatee, Serializable private List activeCallouts = new ArrayList(); + private List activeCalloutInstance = new ArrayList(); /** * @@ -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