[jboss-cvs] jboss-cvs-commits Digest, Vol 40, Issue 622
Kabir Khan
kabir.khan at jboss.com
Tue Oct 27 06:41:59 EDT 2009
Then we can only have one reader at a time (synchronized) vs multiple
readers (read-lock), and we would need to synchronize ourselves when
iterating to read. From the javadoc:
It is imperative that the user manually synchronize on the returned
sorted set when iterating over it or any of its subSet, headSet, or
tailSet views.
SortedSet s = Collections.synchronizedSortedSet(new TreeSet());
...
synchronized(s) {
Iterator i = s.iterator(); // Must be in the synchronized block
while (i.hasNext())
foo(i.next());
}
On 27 Oct 2009, at 10:34, Ales Justin wrote:
> What about SortedSet<KCCC> set = Collections.synchronizedSortedSet
> (new TreeSet<KCCC>(COMPARATOR)); ?
>
> Kabir Khan wrote:
>> On 26 Oct 2009, at 21:34, Kabir Khan wrote:
>>>
>>> On 26 Oct 2009, at 20:46, Ales Justin wrote:
>>>
>>>> I would pull this comparator out from BMDD, not to bloat it.
>>>
>>> ok
>>>
>>>> And instead of using synch code, we could use some existing Set
>>>> to do this for us.
>>>
>>> Which are you thinking of? I can't see anything sorted in
>>> java.util.concurrent, which is why I went for locking myself
>> In other words, I am not 100% sure the following is thread-safe:
>> List controllerContextCreators = new CopyOnWriteArraySet();
>> public void addControllerContextCreator
>> (KernelControllerContextCreator creator)
>> {
>> if (creator == null)
>> return;
>> controllerContextCreators.add(creator);
>> Collections.sort(controllerContextCreators,
>> RelativeComparator.INSTANCE);
>> }
>>>
>>>>
>>>>> ------------------------------
>>>>> Message: 6
>>>>> Date: Mon, 26 Oct 2009 16:42:39 -0400
>>>>> From: jboss-cvs-commits at lists.jboss.org
>>>>> Subject: [jboss-cvs] JBossAS SVN: r95580 - in
>>>>> projects/jboss-deployers/trunk:
>>>>> deployers-vfs/src/test/java/org/jboss/test/deployers/vfs/
>>>>> deployer/bean/support
>>>>> and 2 other directories.
>>>>> To: jboss-cvs-commits at lists.jboss.org
>>>>> Message-ID:
>>>>> <200910262042.n9QKgdRE018603 at svn01.web.mwc.hst.phx2.redhat.com>
>>>>> Content-Type: text/plain; charset=UTF-8
>>>>> Author: kabir.khan at jboss.com
>>>>> Date: 2009-10-26 16:42:38 -0400 (Mon, 26 Oct 2009)
>>>>> New Revision: 95580
>>>>> Modified:
>>>>> projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/java/
>>>>> org/jboss/deployers/vfs/spi/deployer/helpers/
>>>>> KernelControllerContextCreator.java
>>>>> projects/jboss-deployers/trunk/deployers-vfs/src/main/java/org/
>>>>> jboss/deployers/vfs/deployer/kernel/BeanMetaDataDeployer.java
>>>>> projects/jboss-deployers/trunk/deployers-vfs/src/test/java/org/
>>>>> jboss/test/deployers/vfs/deployer/bean/support/
>>>>> NoopControllerContextCreator.java
>>>>> projects/jboss-deployers/trunk/deployers-vfs/src/test/java/org/
>>>>> jboss/test/deployers/vfs/deployer/bean/support/
>>>>> SpecialControllerContextCreator.java
>>>>> projects/jboss-deployers/trunk/deployers-vfs/src/test/java/org/
>>>>> jboss/test/deployers/vfs/deployer/bean/test/
>>>>> KernelControllerContextCreatorTestCase.java
>>>>> Log:
>>>>> [JBDEPLOY-219] Relative sort order of
>>>>> KernelControllerContextCreators
>>>>> Modified: projects/jboss-deployers/trunk/deployers-vfs/src/main/
>>>>> java/org/jboss/deployers/vfs/deployer/kernel/
>>>>> BeanMetaDataDeployer.java
>>>>> =
>>>>> ==================================================================
>>>>> --- projects/jboss-deployers/trunk/deployers-vfs/src/main/java/
>>>>> org/jboss/deployers/vfs/deployer/kernel/
>>>>> BeanMetaDataDeployer.java 2009-10-26 20:37:45 UTC (rev 95579)
>>>>> +++ projects/jboss-deployers/trunk/deployers-vfs/src/main/java/
>>>>> org/jboss/deployers/vfs/deployer/kernel/
>>>>> BeanMetaDataDeployer.java 2009-10-26 20:42:38 UTC (rev 95580)
>>>>> @@ -21,9 +21,12 @@
>>>>> */
>>>>> package org.jboss.deployers.vfs.deployer.kernel;
>>>>> +import java.util.ArrayList;
>>>>> import java.util.Collection;
>>>>> -import java.util.List;
>>>>> -import java.util.concurrent.CopyOnWriteArrayList;
>>>>> +import java.util.Collections;
>>>>> +import java.util.Comparator;
>>>>> +import java.util.concurrent.locks.ReadWriteLock;
>>>>> +import java.util.concurrent.locks.ReentrantReadWriteLock;
>>>>> import
>>>>> org.jboss.beans.metadata.plugins.AbstractClassLoaderMetaData;
>>>>> import org.jboss.beans.metadata.plugins.AbstractValueMetaData;
>>>>> @@ -57,8 +60,10 @@
>>>>> private Controller controller;
>>>>> /** List of controller context creators */
>>>>> - private List<KernelControllerContextCreator>
>>>>> controllerContextCreators = new
>>>>> CopyOnWriteArrayList<KernelControllerContextCreator>();
>>>>> + private ArrayList<KernelControllerContextCreator>
>>>>> controllerContextCreators = new
>>>>> ArrayList<KernelControllerContextCreator>();
>>>>> + private ReadWriteLock lock = new ReentrantReadWriteLock();
>>>>> + /** The default controller context creator */
>>>>> @@ -110,8 +115,31 @@
>>>>> */
>>>>> public void addControllerContextCreator
>>>>> (KernelControllerContextCreator creator)
>>>>> {
>>>>> - if (creator != null)
>>>>> + if (creator == null)
>>>>> + return;
>>>>> + + lock.writeLock().lock();
>>>>> + try
>>>>> + {
>>>>> controllerContextCreators.add(creator);
>>>>> + Collections.sort(controllerContextCreators, new
>>>>> Comparator<KernelControllerContextCreator>()
>>>>> + {
>>>>> +
>>>>> + public int compare(KernelControllerContextCreator
>>>>> o1, KernelControllerContextCreator o2)
>>>>> + {
>>>>> + if (o1.getRelativeOrder() < o2.getRelativeOrder())
>>>>> + return -1;
>>>>> + if (o1.getRelativeOrder() > o2.getRelativeOrder())
>>>>> + return 1;
>>>>> + + return 0;
>>>>> + }
>>>>> + });
>>>>> + }
>>>>> + finally
>>>>> + {
>>>>> + lock.writeLock().unlock();
>>>>> + }
>>>>> }
>>>>> /**
>>>>> @@ -121,8 +149,18 @@
>>>>> */
>>>>> public void removeControllerContextCreator
>>>>> (KernelControllerContextCreator creator)
>>>>> {
>>>>> - if (creator != null)
>>>>> + if (creator == null)
>>>>> + return;
>>>>> + + lock.writeLock().lock();
>>>>> + try
>>>>> + {
>>>>> controllerContextCreators.remove(creator);
>>>>> + }
>>>>> + finally
>>>>> + {
>>>>> + lock.writeLock().unlock();
>>>>> + }
>>>>> }
>>>>> @Override
>>>>> @@ -170,12 +208,20 @@
>>>>> {
>>>>> if (controllerContextCreators.size() > 0)
>>>>> {
>>>>> - for (KernelControllerContextCreator creator :
>>>>> controllerContextCreators)
>>>>> + lock.readLock().lock();
>>>>> + try
>>>>> {
>>>>> - KernelControllerContext context =
>>>>> creator.createContext(controller, unit, deployment);
>>>>> - if (context != null)
>>>>> - return context;
>>>>> + for (KernelControllerContextCreator creator :
>>>>> controllerContextCreators)
>>>>> + {
>>>>> + KernelControllerContext context =
>>>>> creator.createContext(controller, unit, deployment);
>>>>> + if (context != null)
>>>>> + return context;
>>>>> + }
>>>>> }
>>>>> + finally
>>>>> + {
>>>>> + lock.readLock().unlock();
>>>>> + }
>>>>> }
>>>>> return new AbstractKernelControllerContext(null, deployment,
>>>>> null);
>>>>> }
>>>>> Modified: projects/jboss-deployers/trunk/deployers-vfs/src/test/
>>>>> java/org/jboss/test/deployers/vfs/deployer/bean/support/
>>>>> NoopControllerContextCreator.java
>>>>> =
>>>>> ==================================================================
>>>>> --- projects/jboss-deployers/trunk/deployers-vfs/src/test/java/
>>>>> org/jboss/test/deployers/vfs/deployer/bean/support/
>>>>> NoopControllerContextCreator.java 2009-10-26 20:37:45 UTC
>>>>> (rev 95579)
>>>>> +++ projects/jboss-deployers/trunk/deployers-vfs/src/test/java/
>>>>> org/jboss/test/deployers/vfs/deployer/bean/support/
>>>>> NoopControllerContextCreator.java 2009-10-26 20:42:38 UTC
>>>>> (rev 95580)
>>>>> @@ -21,6 +21,9 @@
>>>>> */ package org.jboss.test.deployers.vfs.deployer.bean.support;
>>>>> +import java.util.ArrayList;
>>>>> +import java.util.List;
>>>>> +
>>>>> import org.jboss.beans.metadata.spi.BeanMetaData;
>>>>> import org.jboss.dependency.spi.Controller;
>>>>> import org.jboss.deployers.structure.spi.DeploymentUnit;
>>>>> @@ -34,10 +37,17 @@
>>>>> */
>>>>> public class NoopControllerContextCreator implements
>>>>> KernelControllerContextCreator
>>>>> {
>>>>> - private boolean triggered;
>>>>> + private static List<Integer> triggered = new
>>>>> ArrayList<Integer>();
>>>>> - public boolean isTriggered()
>>>>> + private int order;
>>>>> + + public NoopControllerContextCreator(int order)
>>>>> {
>>>>> + this.order = order;
>>>>> + }
>>>>> + + public static List<Integer> getTriggered()
>>>>> + {
>>>>> return triggered;
>>>>> }
>>>>> @@ -49,8 +59,12 @@
>>>>> throw new IllegalArgumentException("Null unit");
>>>>> if (beanMetaData == null)
>>>>> throw new IllegalArgumentException("Null beanMetadata");
>>>>> - triggered = true;
>>>>> + triggered.add(order);
>>>>> return null;
>>>>> }
>>>>> + public int getRelativeOrder()
>>>>> + {
>>>>> + return order;
>>>>> + }
>>>>> }
>>>>> Modified: projects/jboss-deployers/trunk/deployers-vfs/src/test/
>>>>> java/org/jboss/test/deployers/vfs/deployer/bean/support/
>>>>> SpecialControllerContextCreator.java
>>>>> =
>>>>> ==================================================================
>>>>> --- projects/jboss-deployers/trunk/deployers-vfs/src/test/java/
>>>>> org/jboss/test/deployers/vfs/deployer/bean/support/
>>>>> SpecialControllerContextCreator.java 2009-10-26 20:37:45 UTC
>>>>> (rev 95579)
>>>>> +++ projects/jboss-deployers/trunk/deployers-vfs/src/test/java/
>>>>> org/jboss/test/deployers/vfs/deployer/bean/support/
>>>>> SpecialControllerContextCreator.java 2009-10-26 20:42:38 UTC
>>>>> (rev 95580)
>>>>> @@ -38,6 +38,13 @@
>>>>> {
>>>>> public static final String TRIGGER =
>>>>> "TriggerSpecialControllerContextCreator";
>>>>> + private int order;
>>>>> + + public SpecialControllerContextCreator(int order)
>>>>> + {
>>>>> + this.order = order;
>>>>> + }
>>>>> + public KernelControllerContext createContext(Controller
>>>>> controller, DeploymentUnit unit, BeanMetaData beanMetaData)
>>>>> {
>>>>> if (unit.getAttachment(TRIGGER) != null)
>>>>> @@ -55,5 +62,10 @@
>>>>> }
>>>>> }
>>>>> +
>>>>> + public int getRelativeOrder()
>>>>> + {
>>>>> + return order;
>>>>> + }
>>>>> }
>>>>> Modified: projects/jboss-deployers/trunk/deployers-vfs/src/test/
>>>>> java/org/jboss/test/deployers/vfs/deployer/bean/test/
>>>>> KernelControllerContextCreatorTestCase.java
>>>>> =
>>>>> ==================================================================
>>>>> --- projects/jboss-deployers/trunk/deployers-vfs/src/test/java/
>>>>> org/jboss/test/deployers/vfs/deployer/bean/test/
>>>>> KernelControllerContextCreatorTestCase.java 2009-10-26
>>>>> 20:37:45 UTC (rev 95579)
>>>>> +++ projects/jboss-deployers/trunk/deployers-vfs/src/test/java/
>>>>> org/jboss/test/deployers/vfs/deployer/bean/test/
>>>>> KernelControllerContextCreatorTestCase.java 2009-10-26
>>>>> 20:42:38 UTC (rev 95580)
>>>>> @@ -24,8 +24,6 @@
>>>>> import junit.framework.Test;
>>>>> import junit.framework.TestSuite;
>>>>> -import org.jboss.beans.metadata.spi.BeanMetaData;
>>>>> -import org.jboss.beans.metadata.spi.builder.BeanMetaDataBuilder;
>>>>> import org.jboss.dependency.spi.ControllerContext;
>>>>> import org.jboss.deployers.vfs.deployer.kernel.BeanDeployer;
>>>>> import
>>>>> org.jboss.deployers.vfs.deployer.kernel.BeanMetaDataDeployer;
>>>>> @@ -83,7 +81,8 @@
>>>>> public void testNoopControllerContextCreator() throws Throwable
>>>>> {
>>>>> - NoopControllerContextCreator noop = new
>>>>> NoopControllerContextCreator();
>>>>> + NoopControllerContextCreator.getTriggered().clear();
>>>>> + NoopControllerContextCreator noop = new
>>>>> NoopControllerContextCreator(1);
>>>>> beanMetaDataDeployer.addControllerContextCreator(noop);
>>>>> try
>>>>> {
>>>>> @@ -91,7 +90,8 @@
>>>>> VFSDeployment context = createDeployment("/bean",
>>>>> "toplevel/my-beans.xml");
>>>>> assertDeploy(context);
>>>>> - assertTrue(noop.isTriggered());
>>>>> + assertEquals(1,
>>>>> NoopControllerContextCreator.getTriggered().size());
>>>>> + assertTrue(NoopControllerContextCreator.getTriggered
>>>>> ().contains(1));
>>>>> ControllerContext test =
>>>>> controller.getInstalledContext("Test");
>>>>> assertNotNull(test);
>>>>> @@ -107,19 +107,21 @@
>>>>> public void testSpecialControllerContextCreatorNotTriggered()
>>>>> throws Throwable
>>>>> {
>>>>> - NoopControllerContextCreator noop1 = new
>>>>> NoopControllerContextCreator();
>>>>> + NoopControllerContextCreator.getTriggered().clear();
>>>>> + NoopControllerContextCreator noop1 = new
>>>>> NoopControllerContextCreator(1);
>>>>> beanMetaDataDeployer.addControllerContextCreator(noop1);
>>>>> - SpecialControllerContextCreator special = new
>>>>> SpecialControllerContextCreator();
>>>>> + SpecialControllerContextCreator special = new
>>>>> SpecialControllerContextCreator(2);
>>>>> beanMetaDataDeployer.addControllerContextCreator(special);
>>>>> - NoopControllerContextCreator noop2 = new
>>>>> NoopControllerContextCreator();
>>>>> + NoopControllerContextCreator noop2 = new
>>>>> NoopControllerContextCreator(3);
>>>>> beanMetaDataDeployer.addControllerContextCreator(noop2);
>>>>> try
>>>>> {
>>>>> VFSDeployment context = createDeployment("/bean",
>>>>> "toplevel/my-beans.xml");
>>>>> assertDeploy(context);
>>>>> - assertTrue(noop1.isTriggered());
>>>>> - assertTrue(noop2.isTriggered());
>>>>> + assertEquals(2,
>>>>> NoopControllerContextCreator.getTriggered().size());
>>>>> + assertTrue(NoopControllerContextCreator.getTriggered
>>>>> ().contains(1));
>>>>> + assertTrue(NoopControllerContextCreator.getTriggered
>>>>> ().contains(3));
>>>>> ControllerContext test =
>>>>> controller.getInstalledContext("Test");
>>>>> assertNotNull(test);
>>>>> @@ -137,21 +139,23 @@
>>>>> public void testSpecialControllerContextCreatorTriggered()
>>>>> throws Throwable
>>>>> {
>>>>> + NoopControllerContextCreator.getTriggered().clear();
>>>>> addDeployer(main, new TriggerSpecialControllerContextDeployer
>>>>> ());
>>>>> - NoopControllerContextCreator noop1 = new
>>>>> NoopControllerContextCreator();
>>>>> + NoopControllerContextCreator noop1 = new
>>>>> NoopControllerContextCreator(1);
>>>>> beanMetaDataDeployer.addControllerContextCreator(noop1);
>>>>> - SpecialControllerContextCreator special = new
>>>>> SpecialControllerContextCreator();
>>>>> + SpecialControllerContextCreator special = new
>>>>> SpecialControllerContextCreator(2);
>>>>> beanMetaDataDeployer.addControllerContextCreator(special);
>>>>> - NoopControllerContextCreator noop2 = new
>>>>> NoopControllerContextCreator();
>>>>> + NoopControllerContextCreator noop2 = new
>>>>> NoopControllerContextCreator(3);
>>>>> beanMetaDataDeployer.addControllerContextCreator(noop2);
>>>>> try
>>>>> {
>>>>> VFSDeployment context = createDeployment("/bean",
>>>>> "toplevel/my-beans.xml");
>>>>> assertDeploy(context);
>>>>> - assertTrue(noop1.isTriggered());
>>>>> - assertFalse(noop2.isTriggered());
>>>>> + assertEquals(1,
>>>>> NoopControllerContextCreator.getTriggered().size());
>>>>> + assertTrue(NoopControllerContextCreator.getTriggered
>>>>> ().contains(1));
>>>>> + assertFalse(NoopControllerContextCreator.getTriggered
>>>>> ().contains(3));
>>>>> ControllerContext test =
>>>>> controller.getInstalledContext("Test");
>>>>> assertNotNull(test);
>>>>> @@ -166,4 +170,57 @@
>>>>> beanMetaDataDeployer.removeControllerContextCreator(noop2);
>>>>> }
>>>>> }
>>>>> + + public void testControllerContextOrder() throws Throwable
>>>>> + {
>>>>> + NoopControllerContextCreator.getTriggered().clear();
>>>>> + NoopControllerContextCreator noop6 = new
>>>>> NoopControllerContextCreator(6);
>>>>> + beanMetaDataDeployer.addControllerContextCreator(noop6);
>>>>> + NoopControllerContextCreator noop1 = new
>>>>> NoopControllerContextCreator(1);
>>>>> + beanMetaDataDeployer.addControllerContextCreator(noop1);
>>>>> + NoopControllerContextCreator noop3 = new
>>>>> NoopControllerContextCreator(3);
>>>>> + beanMetaDataDeployer.addControllerContextCreator(noop3);
>>>>> + NoopControllerContextCreator noop4 = new
>>>>> NoopControllerContextCreator(4);
>>>>> + beanMetaDataDeployer.addControllerContextCreator(noop4);
>>>>> + NoopControllerContextCreator noop2 = new
>>>>> NoopControllerContextCreator(2);
>>>>> + beanMetaDataDeployer.addControllerContextCreator(noop2);
>>>>> + NoopControllerContextCreator noop5 = new
>>>>> NoopControllerContextCreator(5);
>>>>> + beanMetaDataDeployer.addControllerContextCreator(noop5);
>>>>> + try
>>>>> + {
>>>>> + VFSDeployment context = createDeployment("/bean",
>>>>> "toplevel/my-beans.xml");
>>>>> + assertDeploy(context);
>>>>> + + assertEquals(6,
>>>>> NoopControllerContextCreator.getTriggered().size());
>>>>> + assertTrue(NoopControllerContextCreator.getTriggered
>>>>> ().contains(1));
>>>>> + assertTrue(NoopControllerContextCreator.getTriggered
>>>>> ().contains(2));
>>>>> + assertTrue(NoopControllerContextCreator.getTriggered
>>>>> ().contains(3));
>>>>> + assertTrue(NoopControllerContextCreator.getTriggered
>>>>> ().contains(4));
>>>>> + assertTrue(NoopControllerContextCreator.getTriggered
>>>>> ().contains(5));
>>>>> + assertTrue(NoopControllerContextCreator.getTriggered
>>>>> ().contains(6));
>>>>> + + int last = 0;
>>>>> + for (int i : NoopControllerContextCreator.getTriggered
>>>>> ())
>>>>> + {
>>>>> + assertTrue(last + 1 == i);
>>>>> + last = i;
>>>>> + }
>>>>> + + ControllerContext test =
>>>>> controller.getInstalledContext("Test");
>>>>> + assertNotNull(test);
>>>>> + assertEquals(AbstractKernelControllerContext.class,
>>>>> test.getClass());
>>>>> + assertUndeploy(context);
>>>>> + assertNull(controller.getContext("Test", null));
>>>>> + }
>>>>> + finally
>>>>> + {
>>>>> + beanMetaDataDeployer.removeControllerContextCreator
>>>>> (noop1);
>>>>> + beanMetaDataDeployer.removeControllerContextCreator
>>>>> (noop2);
>>>>> + beanMetaDataDeployer.removeControllerContextCreator
>>>>> (noop3);
>>>>> + beanMetaDataDeployer.removeControllerContextCreator
>>>>> (noop4);
>>>>> + beanMetaDataDeployer.removeControllerContextCreator
>>>>> (noop5);
>>>>> + beanMetaDataDeployer.removeControllerContextCreator
>>>>> (noop6);
>>>>> + }
>>>>> + + }
>>>>> }
>>>>> Modified: projects/jboss-deployers/trunk/deployers-vfs-spi/src/
>>>>> main/java/org/jboss/deployers/vfs/spi/deployer/helpers/
>>>>> KernelControllerContextCreator.java
>>>>> =
>>>>> ==================================================================
>>>>> --- projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/
>>>>> java/org/jboss/deployers/vfs/spi/deployer/helpers/
>>>>> KernelControllerContextCreator.java 2009-10-26 20:37:45 UTC
>>>>> (rev 95579)
>>>>> +++ projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/
>>>>> java/org/jboss/deployers/vfs/spi/deployer/helpers/
>>>>> KernelControllerContextCreator.java 2009-10-26 20:42:38 UTC
>>>>> (rev 95580)
>>>>> @@ -36,6 +36,13 @@
>>>>> public interface KernelControllerContextCreator
>>>>> {
>>>>> /**
>>>>> + * The relative order of this creator. BeanMetaDataDeployer
>>>>> will try to + * create contexts with values first.
>>>>> + * @return The relative order
>>>>> + */
>>>>> + int getRelativeOrder();
>>>>> + + /**
>>>>> * Create a controller context
>>>>> * @param controller The controller to which the beans will be
>>>>> deployed
>>>>> * @param unit The deployment unit we are deploying
>>>>> ------------------------------
>>>>> _______________________________________________
>>>>> jboss-cvs-commits mailing list
>>>>> jboss-cvs-commits at lists.jboss.org
>>>>> https://lists.jboss.org/mailman/listinfo/jboss-cvs-commits
>>>>> End of jboss-cvs-commits Digest, Vol 40, Issue 622
>>>>> **************************************************
>>>
More information about the jboss-cvs-commits
mailing list