diff --git a/config/alfresco/core-services-context.xml b/config/alfresco/core-services-context.xml index 8cec470376..1ba13f8baf 100644 --- a/config/alfresco/core-services-context.xml +++ b/config/alfresco/core-services-context.xml @@ -502,6 +502,9 @@ + + ${system.lockTryTimeout.MessageServiceImpl} + @@ -732,6 +735,9 @@ ${lucene.defaultAnalyserResourceBundleName} + + ${system.lockTryTimeout.DictionaryDAOImpl} + diff --git a/config/alfresco/policy-context.xml b/config/alfresco/policy-context.xml index 945186f628..33b5328639 100644 --- a/config/alfresco/policy-context.xml +++ b/config/alfresco/policy-context.xml @@ -44,6 +44,9 @@ + + ${system.lockTryTimeout.PolicyComponentImpl} + diff --git a/config/alfresco/repository.properties b/config/alfresco/repository.properties index 96d142ee10..fa76f1ee1c 100644 --- a/config/alfresco/repository.properties +++ b/config/alfresco/repository.properties @@ -1091,4 +1091,12 @@ system.cronJob.startDelayMinutes=1 # # Enable transformation retrying if the file has MIME type differ than file extension. # -content.transformer.retryOn.different.mimetype=true \ No newline at end of file +content.transformer.retryOn.different.mimetype=true + +# +# Lock timeout configuration +# +system.lockTryTimeout=100 +system.lockTryTimeout.DictionaryDAOImpl=2000 +system.lockTryTimeout.MessageServiceImpl=${system.lockTryTimeout} +system.lockTryTimeout.PolicyComponentImpl=${system.lockTryTimeout} \ No newline at end of file diff --git a/source/java/org/alfresco/repo/i18n/MessageServiceImpl.java b/source/java/org/alfresco/repo/i18n/MessageServiceImpl.java index 40c342df15..b42f3b09ba 100644 --- a/source/java/org/alfresco/repo/i18n/MessageServiceImpl.java +++ b/source/java/org/alfresco/repo/i18n/MessageServiceImpl.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2005-2013 Alfresco Software Limited. + * Copyright (C) 2005-2014 Alfresco Software Limited. * * This file is part of Alfresco * @@ -85,7 +85,10 @@ public class MessageServiceImpl implements MessageService private ContentService contentService; private NamespaceService namespaceService; private NodeService nodeService; - + + // Try lock timeout (MNT-11371) + private long tryLockTimeout; + /** * List of registered bundles */ @@ -138,7 +141,12 @@ public class MessageServiceImpl implements MessageService { this.messagesCache = messagesCache; } - + + public void setTryLockTimeout(long tryLockTimeout) + { + this.tryLockTimeout = tryLockTimeout; + } + public void setLocale(Locale locale) { I18NUtil.setLocale(locale); @@ -173,7 +181,7 @@ public class MessageServiceImpl implements MessageService { String tenantDomain = getTenantDomain(); Set tenantResourceBundleBaseNames = null; - LockHelper.tryLock(readLock, 100); + LockHelper.tryLock(readLock, tryLockTimeout, "getting resource bundle base names in 'MessageServiceImpl.registerResourceBundle()'"); try { tenantResourceBundleBaseNames = getResourceBundleBaseNames(tenantDomain); @@ -183,7 +191,7 @@ public class MessageServiceImpl implements MessageService readLock.unlock(); } - LockHelper.tryLock(writeLock, 100); + LockHelper.tryLock(writeLock, tryLockTimeout, "adding new resource bundle path and clearing loaded resource bundles in 'MessageServiceImpl.registerResourceBundle()'"); try { if (! tenantResourceBundleBaseNames.contains(resBundlePath)) @@ -273,7 +281,7 @@ public class MessageServiceImpl implements MessageService Set resourceBundleBaseNamesForAllLocales; String tenantDomain = getTenantDomain(); - LockHelper.tryLock(readLock, 100); + LockHelper.tryLock(readLock, tryLockTimeout, "getting loaded resource bundles, messages and base names in 'MessageServiceImpl.unregisterResourceBundle()'"); try { // all locales @@ -286,7 +294,7 @@ public class MessageServiceImpl implements MessageService readLock.unlock(); } - LockHelper.tryLock(writeLock, 100); + LockHelper.tryLock(writeLock, tryLockTimeout, "removing resource bundle by path in 'MessageServiceImpl.unregisterResourceBundle()'"); try { // unload resource bundles for each locale (by tenant, if applicable) @@ -388,7 +396,7 @@ public class MessageServiceImpl implements MessageService Map> tenantCachedMessages = null; Set tenantResourceBundleBaseNames = null; - LockHelper.tryLock(readLock, 100); + LockHelper.tryLock(readLock, tryLockTimeout, "getting loaded resource bundles, messages and base names in 'MessageServiceImpl.getLocaleProperties()'"); try { tenantLoadedResourceBundles = getLoadedResourceBundles(tenantDomain); @@ -407,7 +415,7 @@ public class MessageServiceImpl implements MessageService if (loadedBundles == null) { - LockHelper.tryLock(writeLock, 100); + LockHelper.tryLock(writeLock, tryLockTimeout, "adding resource bundle for locale in 'MessageServiceImpl.getLocaleProperties()'"); try { loadedBundles = new HashSet(); @@ -422,7 +430,8 @@ public class MessageServiceImpl implements MessageService if (props == null) { - LockHelper.tryLock(writeLock, 100); + LockHelper.tryLock(writeLock, tryLockTimeout, + "adding resource bundle properties into the cache (because properties are not cached) in 'MessageServiceImpl.getLocaleProperties()'"); try { props = new HashMap(); @@ -437,7 +446,8 @@ public class MessageServiceImpl implements MessageService if ((loadedBundles.size() != loadedBundleCount) || (init == true)) { - LockHelper.tryLock(writeLock, 100); + LockHelper.tryLock(writeLock, tryLockTimeout, + "searching resource bundle and adding new resource bundle for locale if the bundle is not found in 'MessageServiceImpl.getLocaleProperties()'"); try { // get registered resource bundles @@ -582,7 +592,7 @@ public class MessageServiceImpl implements MessageService public Set getRegisteredBundles() { - LockHelper.tryLock(readLock, 100); + LockHelper.tryLock(readLock, tryLockTimeout, "getting resource bundle base names in 'MessageServiceImpl.getRegisteredBundles()'"); try { return getResourceBundleBaseNames(getTenantDomain()); @@ -604,7 +614,7 @@ public class MessageServiceImpl implements MessageService // They are not there. Upgrade to the write lock. readLock.unlock(); - LockHelper.tryLock(writeLock, 100); + LockHelper.tryLock(writeLock, tryLockTimeout, "getting cached resource bundle base names by tenant domain in 'MessageServiceImpl.getRegisteredBundles()'"); try { resourceBundleBaseNames = resourceBundleBaseNamesCache.get(tenantDomain); @@ -618,7 +628,7 @@ public class MessageServiceImpl implements MessageService finally { writeLock.unlock(); - LockHelper.tryLock(readLock, 100); + LockHelper.tryLock(readLock, tryLockTimeout, "upgrading to read lock in MessageServiceImpl.getResourceBundleBaseNames()"); } if (resourceBundleBaseNames == null) @@ -655,7 +665,7 @@ public class MessageServiceImpl implements MessageService // Not present. Upgrade to write lock. readLock.unlock(); - LockHelper.tryLock(writeLock, 100); + LockHelper.tryLock(writeLock, tryLockTimeout, "getting cached resource bundle by tenant domain in 'MessageServiceImpl.getLoadedResourceBundles()'"); try { loadedResourceBundles = loadedResourceBundlesCache.get(tenantDomain); @@ -669,7 +679,7 @@ public class MessageServiceImpl implements MessageService finally { writeLock.unlock(); - LockHelper.tryLock(readLock, 100); + LockHelper.tryLock(readLock, tryLockTimeout, "upgrading to read lock in MessageServiceImpl.getLoadedResourceBundles()"); } if (loadedResourceBundles == null) @@ -714,7 +724,7 @@ public class MessageServiceImpl implements MessageService // Need to create it. Upgrade to write lock. readLock.unlock(); - LockHelper.tryLock(writeLock, 100); + LockHelper.tryLock(writeLock, tryLockTimeout, "getting messages by tenant domain from the cache in 'MessageServiceImpl.getMessages()'"); try { messages = messagesCache.get(tenantDomain); @@ -728,7 +738,7 @@ public class MessageServiceImpl implements MessageService finally { writeLock.unlock(); - LockHelper.tryLock(readLock, 100); + LockHelper.tryLock(readLock, tryLockTimeout, "upgrading to read lock in MessageServiceImpl.getMessages()"); } if (messages == null) diff --git a/source/java/org/alfresco/repo/policy/AssociationPolicyDelegate.java b/source/java/org/alfresco/repo/policy/AssociationPolicyDelegate.java index 8a82435259..7dc6d50acd 100644 --- a/source/java/org/alfresco/repo/policy/AssociationPolicyDelegate.java +++ b/source/java/org/alfresco/repo/policy/AssociationPolicyDelegate.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2005-2010 Alfresco Software Limited. + * Copyright (C) 2005-2014 Alfresco Software Limited. * * This file is part of Alfresco * @@ -52,7 +52,7 @@ public class AssociationPolicyDelegate

* @param index the behaviour index to query against */ @SuppressWarnings("unchecked") - /*package*/ AssociationPolicyDelegate(DictionaryService dictionary, Class

policyClass, BehaviourIndex index) + /*package*/ AssociationPolicyDelegate(DictionaryService dictionary, Class

policyClass, BehaviourIndex index, long tryLockTimeout) { // Get list of all pre-registered behaviours for the policy and // ensure they are valid. @@ -65,6 +65,7 @@ public class AssociationPolicyDelegate

// Rely on cached implementation of policy factory // Note: Could also use PolicyFactory (without caching) this.factory = new CachedPolicyFactory(policyClass, index); + this.factory.setTryLockTimeout(tryLockTimeout); this.dictionary = dictionary; } diff --git a/source/java/org/alfresco/repo/policy/CachedPolicyFactory.java b/source/java/org/alfresco/repo/policy/CachedPolicyFactory.java index 5e4429802e..17dc6d3cb3 100644 --- a/source/java/org/alfresco/repo/policy/CachedPolicyFactory.java +++ b/source/java/org/alfresco/repo/policy/CachedPolicyFactory.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2005-2010 Alfresco Software Limited. + * Copyright (C) 2005-2013 Alfresco Software Limited. * * This file is part of Alfresco * @@ -59,7 +59,16 @@ import org.apache.commons.logging.LogFactory; */ private Map> listCache = new HashMap>(); - + // Try lock timeout (MNT-11371) + private long tryLockTimeout; + + + public void setTryLockTimeout(long tryLockTimeout) + { + this.tryLockTimeout = tryLockTimeout; + } + + /** * Construct cached policy factory * @@ -93,7 +102,7 @@ import org.apache.commons.logging.LogFactory; return super.create(binding); } - LockHelper.tryLock(lock.readLock(), 100); + LockHelper.tryLock(lock.readLock(), tryLockTimeout, "getting policy from cache in 'CachedPolicyFactory.create()'"); try { P policyInterface = singleCache.get(binding); @@ -108,7 +117,7 @@ import org.apache.commons.logging.LogFactory; } // There wasn't one - LockHelper.tryLock(lock.writeLock(), 100); + LockHelper.tryLock(lock.writeLock(), tryLockTimeout, "putting new policy to cache in 'CachedPolicyFactory.create()'"); try { P policyInterface = singleCache.get(binding); @@ -140,7 +149,7 @@ import org.apache.commons.logging.LogFactory; return super.createList(binding); } - LockHelper.tryLock(lock.readLock(), 100); + LockHelper.tryLock(lock.readLock(), tryLockTimeout, "getting policy list from cache in 'CachedPolicyFactory.createList()'"); try { Collection

policyInterfaces = listCache.get(binding); @@ -155,7 +164,7 @@ import org.apache.commons.logging.LogFactory; } // There wasn't one - LockHelper.tryLock(lock.writeLock(), 100); + LockHelper.tryLock(lock.writeLock(), tryLockTimeout, "putting policy list to cache in 'CachedPolicyFactory.createList()'"); try { Collection

policyInterfaces = listCache.get(binding); @@ -188,7 +197,7 @@ import org.apache.commons.logging.LogFactory; { if (binding == null) { - LockHelper.tryLock(lock.writeLock(), 100); + LockHelper.tryLock(lock.writeLock(), tryLockTimeout, "clearing policy cache in 'CachedPolicyFactory.clearCache()'"); try { // A specific binding has not been provided, so clear all entries @@ -226,7 +235,7 @@ import org.apache.commons.logging.LogFactory; // Remove all invalid bindings if (invalidBindings.size() > 0) { - LockHelper.tryLock(lock.writeLock(), 100); + LockHelper.tryLock(lock.writeLock(), tryLockTimeout, "removing invalid policy bindings from cache in 'CachedPolicyFactory.clearCache()'"); try { for (B invalidBinding : invalidBindings) diff --git a/source/java/org/alfresco/repo/policy/ClassBehaviourIndex.java b/source/java/org/alfresco/repo/policy/ClassBehaviourIndex.java index d2ef8f61bc..4ac7b17203 100644 --- a/source/java/org/alfresco/repo/policy/ClassBehaviourIndex.java +++ b/source/java/org/alfresco/repo/policy/ClassBehaviourIndex.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2005-2010 Alfresco Software Limited. + * Copyright (C) 2005-2014 Alfresco Software Limited. * * This file is part of Alfresco * @@ -53,7 +53,15 @@ import org.alfresco.util.LockHelper; // Behaviour Filter private BehaviourFilter filter = null; - + // Try lock timeout (MNT-11371) + private long tryLockTimeout; + + + public void setTryLockTimeout(long tryLockTimeout) + { + this.tryLockTimeout = tryLockTimeout; + } + /** * Construct. */ @@ -92,7 +100,7 @@ import org.alfresco.util.LockHelper; @Override public Collection getAll() { - LockHelper.tryLock(lock.readLock(), 100); + LockHelper.tryLock(lock.readLock(), tryLockTimeout, "getting all behavior definitions in 'ClassBehaviourIndex.getAll()'"); try { @@ -112,7 +120,7 @@ import org.alfresco.util.LockHelper; @SuppressWarnings("unchecked") public Collection find(B binding) { - LockHelper.tryLock(lock.readLock(), 100); + LockHelper.tryLock(lock.readLock(), tryLockTimeout, "searching behavior definitions list in 'ClassBehaviourIndex.find()'"); try { @@ -175,7 +183,7 @@ import org.alfresco.util.LockHelper; */ public void putClassBehaviour(BehaviourDefinition behaviour) { - LockHelper.tryLock(lock.writeLock(), 100); + LockHelper.tryLock(lock.writeLock(), tryLockTimeout, "putting behavior definition in 'ClassBehaviourIndex.putClassBehavior()'"); try { classMap.put(behaviour); @@ -194,7 +202,7 @@ import org.alfresco.util.LockHelper; */ public void putServiceBehaviour(BehaviourDefinition behaviour) { - LockHelper.tryLock(lock.writeLock(), 100); + LockHelper.tryLock(lock.writeLock(), tryLockTimeout, "putting behavior definition in 'ClassBehaviourIndex.putServiceBehavior()'"); try { serviceMap.put(behaviour); @@ -212,7 +220,7 @@ import org.alfresco.util.LockHelper; */ public void removeClassBehaviour(BehaviourDefinition behaviour) { - LockHelper.tryLock(lock.writeLock(), 100); + LockHelper.tryLock(lock.writeLock(), tryLockTimeout, "removing behavior definition in 'ClassBehaviourIndex.removeClassBehavior()'"); try { classMap.remove(behaviour); diff --git a/source/java/org/alfresco/repo/policy/ClassPolicyDelegate.java b/source/java/org/alfresco/repo/policy/ClassPolicyDelegate.java index 26dc6fadf2..e8ac646b02 100644 --- a/source/java/org/alfresco/repo/policy/ClassPolicyDelegate.java +++ b/source/java/org/alfresco/repo/policy/ClassPolicyDelegate.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2005-2010 Alfresco Software Limited. + * Copyright (C) 2005-2014 Alfresco Software Limited. * * This file is part of Alfresco * @@ -51,7 +51,7 @@ public class ClassPolicyDelegate

* @param index the behaviour index to query against */ @SuppressWarnings("unchecked") - /*package*/ ClassPolicyDelegate(DictionaryService dictionary, Class

policyClass, BehaviourIndex index) + /*package*/ ClassPolicyDelegate(DictionaryService dictionary, Class

policyClass, BehaviourIndex index, long tryLockTimeout) { // Get list of all pre-registered behaviours for the policy and // ensure they are valid. @@ -64,6 +64,7 @@ public class ClassPolicyDelegate

// Rely on cached implementation of policy factory // Note: Could also use PolicyFactory (without caching) this.factory = new CachedPolicyFactory(policyClass, index); + this.factory.setTryLockTimeout(tryLockTimeout); this.dictionary = dictionary; } diff --git a/source/java/org/alfresco/repo/policy/PolicyComponentImpl.java b/source/java/org/alfresco/repo/policy/PolicyComponentImpl.java index d77a90bb51..b5f6d5a0f7 100644 --- a/source/java/org/alfresco/repo/policy/PolicyComponentImpl.java +++ b/source/java/org/alfresco/repo/policy/PolicyComponentImpl.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2005-2010 Alfresco Software Limited. + * Copyright (C) 2005-2014 Alfresco Software Limited. * * This file is part of Alfresco * @@ -73,7 +73,15 @@ public class PolicyComponentImpl implements PolicyComponent // Wild Card Feature private static final QName FEATURE_WILDCARD = QName.createQName(NamespaceService.DEFAULT_URI, "*"); - + + // Try lock timeout (MNT-11371) + private long tryLockTimeout; + + + public void setTryLockTimeout(long tryLockTimeout) + { + this.tryLockTimeout = tryLockTimeout; + } /** * Construct @@ -129,7 +137,8 @@ public class PolicyComponentImpl implements PolicyComponent ParameterCheck.mandatory("Policy interface class", policy); PolicyDefinition definition = createPolicyDefinition(policy); registeredPolicies.put(new PolicyKey(definition.getType(), definition.getName()), definition); - ClassPolicyDelegate

delegate = new ClassPolicyDelegate

(dictionary, policy, getClassBehaviourIndex(definition.getName())); + ClassPolicyDelegate

delegate = new ClassPolicyDelegate

(dictionary, policy, getClassBehaviourIndex(definition.getName()), tryLockTimeout); + if (logger.isInfoEnabled()) logger.info("Registered class policy " + definition.getName() + " (" + definition.getPolicyInterface() + ")"); @@ -152,7 +161,7 @@ public class PolicyComponentImpl implements PolicyComponent ParameterCheck.mandatory("Policy interface class", policy); PolicyDefinition definition = createPolicyDefinition(policy); registeredPolicies.put(new PolicyKey(definition.getType(), definition.getName()), definition); - PropertyPolicyDelegate

delegate = new PropertyPolicyDelegate

(dictionary, policy, getPropertyBehaviourIndex(definition.getName())); + PropertyPolicyDelegate

delegate = new PropertyPolicyDelegate

(dictionary, policy, getPropertyBehaviourIndex(definition.getName()), tryLockTimeout); if (logger.isInfoEnabled()) logger.info("Registered property policy " + definition.getName() + " (" + definition.getPolicyInterface() + ")"); @@ -170,7 +179,7 @@ public class PolicyComponentImpl implements PolicyComponent ParameterCheck.mandatory("Policy interface class", policy); PolicyDefinition definition = createPolicyDefinition(policy); registeredPolicies.put(new PolicyKey(definition.getType(), definition.getName()), definition); - AssociationPolicyDelegate

delegate = new AssociationPolicyDelegate

(dictionary, policy, getAssociationBehaviourIndex(definition.getName())); + AssociationPolicyDelegate

delegate = new AssociationPolicyDelegate

(dictionary, policy, getAssociationBehaviourIndex(definition.getName()), tryLockTimeout); if (logger.isInfoEnabled()) logger.info("Registered association policy " + definition.getName() + " (" + definition.getPolicyInterface() + ")"); @@ -431,6 +440,7 @@ public class PolicyComponentImpl implements PolicyComponent if (index == null) { index = new ClassBehaviourIndex(behaviourFilter); + index.setTryLockTimeout(tryLockTimeout); classBehaviours.put(policy, index); } return index; @@ -449,6 +459,7 @@ public class PolicyComponentImpl implements PolicyComponent if (index == null) { index = new ClassBehaviourIndex(behaviourFilter); + index.setTryLockTimeout(tryLockTimeout); propertyBehaviours.put(policy, index); } return index; @@ -467,6 +478,7 @@ public class PolicyComponentImpl implements PolicyComponent if (index == null) { index = new ClassBehaviourIndex(behaviourFilter); + index.setTryLockTimeout(tryLockTimeout); associationBehaviours.put(policy, index); } return index; diff --git a/source/java/org/alfresco/repo/policy/PropertyPolicyDelegate.java b/source/java/org/alfresco/repo/policy/PropertyPolicyDelegate.java index 64cee2362b..419f5d8901 100644 --- a/source/java/org/alfresco/repo/policy/PropertyPolicyDelegate.java +++ b/source/java/org/alfresco/repo/policy/PropertyPolicyDelegate.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2005-2010 Alfresco Software Limited. + * Copyright (C) 2005-2014 Alfresco Software Limited. * * This file is part of Alfresco * @@ -52,7 +52,7 @@ public class PropertyPolicyDelegate

* @param index the behaviour index to query against */ @SuppressWarnings("unchecked") - /*package*/ PropertyPolicyDelegate(DictionaryService dictionary, Class

policyClass, BehaviourIndex index) + /*package*/ PropertyPolicyDelegate(DictionaryService dictionary, Class

policyClass, BehaviourIndex index, long tryLockTimeout) { // Get list of all pre-registered behaviours for the policy and // ensure they are valid. @@ -65,6 +65,7 @@ public class PropertyPolicyDelegate

// Rely on cached implementation of policy factory // Note: Could also use PolicyFactory (without caching) this.factory = new CachedPolicyFactory(policyClass, index); + this.factory.setTryLockTimeout(tryLockTimeout); this.dictionary = dictionary; }