ACE-4250: Revert r110119 (except keep 2 out of 4 unit tests)

- note: related to ACE-4421/MNT-13836

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@114219 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Jan Vonka
2015-10-12 22:15:03 +00:00
parent fd740adefc
commit 30f8e49239
2 changed files with 274 additions and 272 deletions

View File

@@ -1,271 +1,269 @@
/* /*
* Copyright (C) 2005-2014 Alfresco Software Limited. * Copyright (C) 2005-2014 Alfresco Software Limited.
* *
* This file is part of Alfresco * This file is part of Alfresco
* *
* Alfresco is free software: you can redistribute it and/or modify * Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by * it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* Alfresco is distributed in the hope that it will be useful, * Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details. * GNU Lesser General Public License for more details.
* *
* You should have received a copy of the GNU Lesser General Public License * You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>. * along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
*/ */
package org.alfresco.repo.policy; package org.alfresco.repo.policy;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.List;
import java.util.List; import java.util.concurrent.locks.ReentrantReadWriteLock;
import java.util.concurrent.locks.ReentrantReadWriteLock;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeRef; import org.alfresco.service.namespace.QName;
import org.alfresco.service.namespace.QName; import org.alfresco.util.LockHelper;
import org.alfresco.util.LockHelper;
/**
/** * Class (Type/Aspect) oriented index of bound behaviours
* Class (Type/Aspect) oriented index of bound behaviours *
* * Note: Uses Class hierarchy to derive bindings.
* Note: Uses Class hierarchy to derive bindings. *
* * @author David Caruana
* @author David Caruana *
* */
*/ /*package*/ class ClassBehaviourIndex<B extends ClassBehaviourBinding> implements BehaviourIndex<B>
/*package*/ class ClassBehaviourIndex<B extends ClassBehaviourBinding> implements BehaviourIndex<B> {
{ // Lock
// Lock private ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
private ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
// Map of class bindings
// Map of class bindings private BehaviourMap<B> classMap = new BehaviourMap<B>();
private BehaviourMap<B> classMap = new BehaviourMap<B>();
// Map of service bindings
// Map of service bindings private BehaviourMap<ServiceBehaviourBinding> serviceMap = new BehaviourMap<ServiceBehaviourBinding>();
private BehaviourMap<ServiceBehaviourBinding> serviceMap = new BehaviourMap<ServiceBehaviourBinding>();
// List of registered observers
// List of registered observers private List<BehaviourChangeObserver<B>> observers = new ArrayList<BehaviourChangeObserver<B>>();
private List<BehaviourChangeObserver<B>> observers = new ArrayList<BehaviourChangeObserver<B>>();
// Behaviour Filter
// Behaviour Filter private BehaviourFilter filter = null;
private BehaviourFilter filter = null;
// Try lock timeout (MNT-11371)
// Try lock timeout (MNT-11371) private long tryLockTimeout;
private long tryLockTimeout;
public void setTryLockTimeout(long tryLockTimeout)
public void setTryLockTimeout(long tryLockTimeout) {
{ this.tryLockTimeout = tryLockTimeout;
this.tryLockTimeout = tryLockTimeout; }
}
/**
/** * Construct.
* Construct. */
*/ /*package*/ ClassBehaviourIndex(BehaviourFilter filter)
/*package*/ ClassBehaviourIndex(BehaviourFilter filter) {
{ // Observe class binding changes and propagate to our own observers
// Observe class binding changes and propagate to our own observers this.classMap.addChangeObserver(new BehaviourChangeObserver<B>()
this.classMap.addChangeObserver(new BehaviourChangeObserver<B>() {
{ public void addition(B binding, Behaviour behaviour)
public void addition(B binding, Behaviour behaviour) {
{ for (BehaviourChangeObserver<B> listener : observers)
for (BehaviourChangeObserver<B> listener : observers) {
{ listener.addition(binding, behaviour);
listener.addition(binding, behaviour); }
} }
}
public void removal(B binding, Behaviour behaviour)
public void removal(B binding, Behaviour behaviour) {
{ for (BehaviourChangeObserver<B> listener : observers)
for (BehaviourChangeObserver<B> listener : observers) {
{ listener.removal(binding, behaviour);
listener.removal(binding, behaviour); }
} }
} });
});
this.classMap.addChangeObserver(new BehaviourChangeObserver<B>()
this.classMap.addChangeObserver(new BehaviourChangeObserver<B>() {
{ public void addition(B binding, Behaviour behaviour)
public void addition(B binding, Behaviour behaviour) {
{ for (BehaviourChangeObserver<B> listener : observers)
for (BehaviourChangeObserver<B> listener : observers) {
{ listener.addition(binding, behaviour);
listener.addition(binding, behaviour); }
} }
}
public void removal(B binding, Behaviour behaviour)
public void removal(B binding, Behaviour behaviour) {
{ for (BehaviourChangeObserver<B> listener : observers)
for (BehaviourChangeObserver<B> listener : observers) {
{ listener.removal(binding, behaviour);
listener.removal(binding, behaviour); }
} }
} });
});
// Observe service binding changes and propagate to our own observers
// Observe service binding changes and propagate to our own observers this.serviceMap.addChangeObserver(new BehaviourChangeObserver<ServiceBehaviourBinding>()
this.serviceMap.addChangeObserver(new BehaviourChangeObserver<ServiceBehaviourBinding>() {
{ public void addition(ServiceBehaviourBinding binding, Behaviour behaviour)
public void addition(ServiceBehaviourBinding binding, Behaviour behaviour) {
{ for (BehaviourChangeObserver<B> listener : observers)
for (BehaviourChangeObserver<B> listener : observers) {
{ // Note: Don't specify class ref as service-level bindings affect all classes
// Note: Don't specify class ref as service-level bindings affect all classes listener.addition(null, behaviour);
listener.addition(null, behaviour); }
} }
}
public void removal(ServiceBehaviourBinding binding, Behaviour behaviour)
public void removal(ServiceBehaviourBinding binding, Behaviour behaviour) {
{ for (BehaviourChangeObserver<B> listener : observers)
for (BehaviourChangeObserver<B> listener : observers) {
{ listener.removal(null, behaviour);
listener.removal(null, behaviour); }
} }
} });
});
// Setup state
// Setup state this.filter = filter;
this.filter = filter; }
}
@Override
@Override public Collection<BehaviourDefinition> getAll()
public Collection<BehaviourDefinition> getAll() {
{ LockHelper.tryLock(lock.readLock(), tryLockTimeout, "getting all behavior definitions in 'ClassBehaviourIndex.getAll()'");
LockHelper.tryLock(lock.readLock(), tryLockTimeout, "getting all behavior definitions in 'ClassBehaviourIndex.getAll()'");
try
try {
{ List<BehaviourDefinition> all = new ArrayList<BehaviourDefinition>(classMap.size() + serviceMap.size());
List<BehaviourDefinition> all = new ArrayList<BehaviourDefinition>(classMap.size() + serviceMap.size()); all.addAll(classMap.getAll());
all.addAll(classMap.getAll()); all.addAll(serviceMap.getAll());
all.addAll(serviceMap.getAll()); return all;
return all; }
} finally
finally {
{ lock.readLock().unlock();
lock.readLock().unlock(); }
} }
}
@Override
@Override @SuppressWarnings("unchecked")
@SuppressWarnings("unchecked") public Collection<BehaviourDefinition> find(B binding)
public Collection<BehaviourDefinition> find(B binding) {
{ LockHelper.tryLock(lock.readLock(), tryLockTimeout, "searching behavior definitions list in 'ClassBehaviourIndex.find()'");
LockHelper.tryLock(lock.readLock(), tryLockTimeout, "searching behavior definitions list in 'ClassBehaviourIndex.find()'");
try
try {
{ List<BehaviourDefinition> behaviours = new ArrayList<BehaviourDefinition>();
List<BehaviourDefinition> behaviours = new ArrayList<BehaviourDefinition>();
// Determine if behaviour has been disabled
// Find class behaviour by scanning up the class hierarchy boolean isEnabled = true;
List<BehaviourDefinition<B>> behaviour = null; if (filter != null)
while (binding != null) {
{ NodeRef nodeRef = binding.getNodeRef();
behaviour = classMap.get(binding); QName className = binding.getClassQName();
if (behaviour != null && isEnabled(binding)) isEnabled = (nodeRef == null) ? filter.isEnabled(className) : filter.isEnabled(nodeRef, className);
{ }
behaviours.addAll(0, behaviour); // note: list base/generalised before extended/specific
} if (isEnabled)
binding = (B)binding.generaliseBinding(); {
} // Find class behaviour by scanning up the class hierarchy
List<BehaviourDefinition<B>> behaviour = null;
// Append all service-level behaviours while (binding != null)
behaviours.addAll(serviceMap.getAll()); {
behaviour = classMap.get(binding);
return behaviours; if (behaviour != null)
} {
finally behaviours.addAll(0, behaviour); // note: list base/generalised before extended/specific
{ }
lock.readLock().unlock(); binding = (B)binding.generaliseBinding();
} }
} }
// Append all service-level behaviours
@Override behaviours.addAll(serviceMap.getAll());
public void addChangeObserver(BehaviourChangeObserver<B> observer)
{ return behaviours;
observers.add(observer); }
} finally
{
lock.readLock().unlock();
@Override }
public BehaviourFilter getFilter() }
{
return filter;
} @Override
public void addChangeObserver(BehaviourChangeObserver<B> observer)
{
/** observers.add(observer);
* Binds a Class Behaviour into this index }
*
* @param behaviour the class bound behaviour
*/ @Override
public void putClassBehaviour(BehaviourDefinition<B> behaviour) public BehaviourFilter getFilter()
{ {
LockHelper.tryLock(lock.writeLock(), tryLockTimeout, "putting behavior definition in 'ClassBehaviourIndex.putClassBehavior()'"); return filter;
try }
{
classMap.put(behaviour);
} /**
finally * Binds a Class Behaviour into this index
{ *
lock.writeLock().unlock(); * @param behaviour the class bound behaviour
} */
} public void putClassBehaviour(BehaviourDefinition<B> behaviour)
{
LockHelper.tryLock(lock.writeLock(), tryLockTimeout, "putting behavior definition in 'ClassBehaviourIndex.putClassBehavior()'");
/** try
* Binds a Service Behaviour into this index {
* classMap.put(behaviour);
* @param behaviour the service bound behaviour }
*/ finally
public void putServiceBehaviour(BehaviourDefinition<ServiceBehaviourBinding> behaviour) {
{ lock.writeLock().unlock();
LockHelper.tryLock(lock.writeLock(), tryLockTimeout, "putting behavior definition in 'ClassBehaviourIndex.putServiceBehavior()'"); }
try }
{
serviceMap.put(behaviour);
} /**
finally * Binds a Service Behaviour into this index
{ *
lock.writeLock().unlock(); * @param behaviour the service bound behaviour
} */
} public void putServiceBehaviour(BehaviourDefinition<ServiceBehaviourBinding> behaviour)
{
/** LockHelper.tryLock(lock.writeLock(), tryLockTimeout, "putting behavior definition in 'ClassBehaviourIndex.putServiceBehavior()'");
* Remove class behaviour try
* {
* @param behaviour BehaviourDefinition<B> serviceMap.put(behaviour);
*/ }
public void removeClassBehaviour(BehaviourDefinition<B> behaviour) finally
{ {
LockHelper.tryLock(lock.writeLock(), tryLockTimeout, "removing behavior definition in 'ClassBehaviourIndex.removeClassBehavior()'"); lock.writeLock().unlock();
try }
{ }
classMap.remove(behaviour);
} /**
finally * Remove class behaviour
{ *
lock.writeLock().unlock(); * @param behaviour BehaviourDefinition<B>
} */
} public void removeClassBehaviour(BehaviourDefinition<B> behaviour)
{
private boolean isEnabled(B binding) LockHelper.tryLock(lock.writeLock(), tryLockTimeout, "removing behavior definition in 'ClassBehaviourIndex.removeClassBehavior()'");
{ try
// Determine if behaviour has been disabled {
boolean isEnabled = true; classMap.remove(behaviour);
if (filter != null) }
{ finally
NodeRef nodeRef = binding.getNodeRef(); {
QName className = binding.getClassQName(); lock.writeLock().unlock();
isEnabled = (nodeRef == null) ? filter.isEnabled(className) : filter.isEnabled(nodeRef, className); }
} }
return isEnabled; }
}
}

View File

@@ -426,6 +426,7 @@ public class PolicyComponentTransactionTest extends TestCase
* <p>then disable the super- behaviour only and show that sub behaviour is still enabled and triggered</p> * <p>then disable the super- behaviour only and show that sub behaviour is still enabled and triggered</p>
* @throws Exception * @throws Exception
*/ */
/*
public void testChildParentBehaviours2() throws Exception public void testChildParentBehaviours2() throws Exception
{ {
TestOnCreateNodePolicy baseTypeBehavior = new TestOnCreateNodePolicy(); TestOnCreateNodePolicy baseTypeBehavior = new TestOnCreateNodePolicy();
@@ -476,7 +477,8 @@ public class PolicyComponentTransactionTest extends TestCase
assertTrue("Behavior should be executed for child type.", fileTypeBehavior.isExecuted()); assertTrue("Behavior should be executed for child type.", fileTypeBehavior.isExecuted());
assertEquals(1, fileTypeBehavior.getExecutionCount()); assertEquals(1, fileTypeBehavior.getExecutionCount());
} }
*/
/** /**
* Test for MNT_13836 * Test for MNT_13836
* <p>then also disable the sub- behaviour and show that neither behaviour is triggered</p> * <p>then also disable the sub- behaviour and show that neither behaviour is triggered</p>
@@ -544,6 +546,7 @@ public class PolicyComponentTransactionTest extends TestCase
* <p>then vice-versa, ie. disabling sub- behaviour does not disable inherited super- behaviours</p> * <p>then vice-versa, ie. disabling sub- behaviour does not disable inherited super- behaviours</p>
* @throws Exception * @throws Exception
*/ */
/*
public void testChildParentBehaviours4() throws Exception public void testChildParentBehaviours4() throws Exception
{ {
TestOnCreateNodePolicy baseTypeBehavior = new TestOnCreateNodePolicy(); TestOnCreateNodePolicy baseTypeBehavior = new TestOnCreateNodePolicy();
@@ -594,6 +597,7 @@ public class PolicyComponentTransactionTest extends TestCase
assertFalse("Behavior should not be executed for child type.", fileTypeBehavior.isExecuted()); assertFalse("Behavior should not be executed for child type.", fileTypeBehavior.isExecuted());
assertEquals(0, fileTypeBehavior.getExecutionCount()); assertEquals(0, fileTypeBehavior.getExecutionCount());
} }
*/
/** /**
* @param className the class to check * @param className the class to check