Author: jleroux
Date: Mon Apr 11 07:03:32 2011 New Revision: 1090952 URL: http://svn.apache.org/viewvc?rev=1090952&view=rev Log: A patch from Sascha Rodekamp "Infinite loop when instantiate the delegator using distributetCacheClear" https://issues.apache.org/jira/browse/OFBIZ-3987 We found an infinite loop when instantiate the delegator. This happens when you use the distributetCacheClear . I moved the init of the dist cache clear to a separate method and call it in the factory which resolves the loop issue. Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/Delegator.java ofbiz/trunk/framework/entity/src/org/ofbiz/entity/DelegatorFactory.java ofbiz/trunk/framework/entity/src/org/ofbiz/entity/GenericDelegator.java Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/Delegator.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/Delegator.java?rev=1090952&r1=1090951&r2=1090952&view=diff ============================================================================== --- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/Delegator.java (original) +++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/Delegator.java Mon Apr 11 07:03:32 2011 @@ -796,6 +796,8 @@ public interface Delegator { public void initEntityEcaHandler(); + public void initDistributedCacheClear(); + public GenericPK makePK(Element element); /** Creates a Primary Key in the form of a GenericPK without persisting it */ Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/DelegatorFactory.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/DelegatorFactory.java?rev=1090952&r1=1090951&r2=1090952&view=diff ============================================================================== --- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/DelegatorFactory.java (original) +++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/DelegatorFactory.java Mon Apr 11 07:03:32 2011 @@ -41,6 +41,10 @@ public abstract class DelegatorFactory i // setup the Entity ECA Handler delegator.initEntityEcaHandler(); //Debug.logInfo("got delegator(" + delegatorName + ") from cache", module); + + // setup the distributed CacheClear + delegator.initDistributedCacheClear(); + return delegator; } try { Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/GenericDelegator.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/GenericDelegator.java?rev=1090952&r1=1090951&r2=1090952&view=diff ============================================================================== --- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/GenericDelegator.java (original) +++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/GenericDelegator.java Mon Apr 11 07:03:32 2011 @@ -276,38 +276,11 @@ public class GenericDelegator implements // setup the crypto class; this also after the delegator is in the cache otherwise we get infinite recursion this.crypto = new EntityCrypto(this); - - //time to do some tricks with manual class loading that resolves circular dependencies, like calling services... - ClassLoader loader = Thread.currentThread().getContextClassLoader(); - - // if useDistributedCacheClear is false do nothing since the - // distributedCacheClear member field with a null value will cause the - // dcc code to do nothing - if (getDelegatorInfo().useDistributedCacheClear) { - // initialize the distributedCacheClear mechanism - String distributedCacheClearClassName = getDelegatorInfo().distributedCacheClearClassName; - - try { - Class<?> dccClass = loader.loadClass(distributedCacheClearClassName); - this.distributedCacheClear = (DistributedCacheClear) dccClass.newInstance(); - this.distributedCacheClear.setDelegator(this, getDelegatorInfo().distributedCacheClearUserLoginId); - } catch (ClassNotFoundException e) { - Debug.logWarning(e, "DistributedCacheClear class with name " + distributedCacheClearClassName + " was not found, distributed cache clearing will be disabled", module); - } catch (InstantiationException e) { - Debug.logWarning(e, "DistributedCacheClear class with name " + distributedCacheClearClassName + " could not be instantiated, distributed cache clearing will be disabled", module); - } catch (IllegalAccessException e) { - Debug.logWarning(e, "DistributedCacheClear class with name " + distributedCacheClearClassName + " could not be accessed (illegal), distributed cache clearing will be disabled", module); - } catch (ClassCastException e) { - Debug.logWarning(e, "DistributedCacheClear class with name " + distributedCacheClearClassName + " does not implement the DistributedCacheClear interface, distributed cache clearing will be disabled", module); - } - } else { - Debug.logInfo("Distributed Cache Clear System disabled for delegator [" + delegatorFullName + "]", module); - } } - + protected void setDelegatorNames(String delegatorFullName) { this.delegatorFullName = delegatorFullName; - + int hashSymbolIndex = delegatorFullName.indexOf('#'); if (hashSymbolIndex == -1) { this.delegatorBaseName = delegatorFullName; @@ -321,10 +294,13 @@ public class GenericDelegator implements * @see org.ofbiz.entity.Delegator#initEntityEcaHandler() */ public synchronized void initEntityEcaHandler() { - if (!getDelegatorInfo().useEntityEca || this.entityEcaHandler != null) { + // Nothing to do if already assigned: the class loader has already been called, the class instantiated and casted to EntityEcaHandler + if (this.entityEcaHandler != null) { return; } + // If useEntityEca is false do nothing: the entityEcaHandler member field with a null value would cause its code to do nothing if (getDelegatorInfo().useEntityEca) { + //time to do some tricks with manual class loading that resolves circular dependencies, like calling services ClassLoader loader = Thread.currentThread().getContextClassLoader(); // initialize the entity eca handler String entityEcaHandlerClassName = getDelegatorInfo().entityEcaHandlerClassName; @@ -777,7 +753,7 @@ public class GenericDelegator implements } catch (GenericEntityException e) { // see if this was caused by an existing record before resetting the sequencer and trying again // NOTE: use the helper directly so ECA rules, etc won't be run - + GenericValue existingValue = null; try { existingValue = helper.findByPrimaryKey(value.getPrimaryKey()); @@ -2822,4 +2798,38 @@ public class GenericDelegator implements this.value = value; } } + + /* (non-Javadoc) + * @see org.ofbiz.entity.Delegator#initDistributedCacheClear() + */ + public void initDistributedCacheClear() { + // Nothing to do if already assigned: the class loader has already been called, the class instantiated and casted to DistributedCacheClear + if (this.distributedCacheClear != null) { + return; + } + + // If useDistributedCacheClear is false do nothing: the distributedCacheClear member field with a null value would cause dcc code to do nothing + if (getDelegatorInfo().useDistributedCacheClear) { + //time to do some tricks with manual class loading that resolves circular dependencies, like calling services + ClassLoader loader = Thread.currentThread().getContextClassLoader(); + // initialize the distributedCacheClear mechanism + String distributedCacheClearClassName = getDelegatorInfo().distributedCacheClearClassName; + + try { + Class<?> dccClass = loader.loadClass(distributedCacheClearClassName); + this.distributedCacheClear = UtilGenerics.cast(dccClass.newInstance()); + this.distributedCacheClear.setDelegator(this, getDelegatorInfo().distributedCacheClearUserLoginId); + } catch (ClassNotFoundException e) { + Debug.logWarning(e, "DistributedCacheClear class with name " + distributedCacheClearClassName + " was not found, distributed cache clearing will be disabled", module); + } catch (InstantiationException e) { + Debug.logWarning(e, "DistributedCacheClear class with name " + distributedCacheClearClassName + " could not be instantiated, distributed cache clearing will be disabled", module); + } catch (IllegalAccessException e) { + Debug.logWarning(e, "DistributedCacheClear class with name " + distributedCacheClearClassName + " could not be accessed (illegal), distributed cache clearing will be disabled", module); + } catch (ClassCastException e) { + Debug.logWarning(e, "DistributedCacheClear class with name " + distributedCacheClearClassName + " does not implement the DistributedCacheClear interface, distributed cache clearing will be disabled", module); + } + } else { + Debug.logVerbose("Distributed Cache Clear System disabled for delegator [" + delegatorFullName + "]", module); + } + } } |
Free forum by Nabble | Edit this page |