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;
}