Skip to content

Commit

Permalink
BeanMap backing Map -> ConcurrentHashMap
Browse files Browse the repository at this point in the history
CopyOnWriteArrayList setter for beans in Manager

git-svn-id: http://anonsvn.jboss.org/repos/weld/ri/trunk@226 1c488680-804c-0410-94cd-c6b725194a0e
  • Loading branch information
nickarls committed Nov 3, 2008
1 parent c32319f commit a665a3e
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 8 deletions.
13 changes: 13 additions & 0 deletions webbeans-ri/src/main/java/org/jboss/webbeans/ManagerImpl.java
Expand Up @@ -3,6 +3,7 @@
import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
Expand Down Expand Up @@ -195,6 +196,18 @@ public ResolutionManager getResolutionManager()
return resolutionManager;
}

/**
* Wraps a collection of beans into a thread safe list.
* Since this overwrites any existing list of beans in the manager,
* this should only be done on startup and other controlled situations.
*
* @param beans The collection of beans to wrap.
*/
public Manager setBeans(Collection<Bean<?>> beans) {
this.beans = new CopyOnWriteArrayList<Bean<?>>(beans);
return this;
}

public List<Bean<?>> getBeans()
{
return beans;
Expand Down
@@ -1,7 +1,7 @@
package org.jboss.webbeans.contexts;

import java.lang.annotation.Annotation;
import java.util.HashMap;
import java.util.concurrent.ConcurrentHashMap;

import javax.webbeans.manager.Bean;
import javax.webbeans.manager.Context;
Expand All @@ -22,10 +22,10 @@ public abstract class AbstractContext implements Context

protected class BeanMap extends MapWrapper<Bean<? extends Object>, Object>
{

public BeanMap()
{
super(new HashMap<Bean<? extends Object>, Object>());
super(new ConcurrentHashMap<Bean<? extends Object>, Object>());
}

@SuppressWarnings("unchecked")
Expand Down
Expand Up @@ -2,7 +2,6 @@

import java.io.Serializable;
import java.lang.reflect.Method;
import java.util.List;

import javassist.util.proxy.MethodHandler;

Expand All @@ -26,7 +25,6 @@ public ProxyMethodHandler(Bean<?> bean, int beanIndex, ManagerImpl manager)
ProxyMethodHandler.manager = manager;
}

//@Override Let's stay compatible with JDK5 :-)
public Object invoke(Object self, Method method, Method proceed, Object[] args) throws Throwable
{
if (bean == null)
Expand Down
Expand Up @@ -60,7 +60,14 @@ public void testManagerLookupInJndi()
{
assert false;
}


@Test(groups="manager")
public void testWrappingOfBeanCollection()
{
// TODO stub
assert false;
}

/*
@Test(groups="manager") @SpecAssertion(section="4.8")
Expand Down
Expand Up @@ -30,7 +30,7 @@
*
*/
@SpecVersion("PDR")
public class CommonContextTest extends AbstractTest
public class NormalContextTest extends AbstractTest
{
Context context;

Expand Down Expand Up @@ -83,4 +83,11 @@ public void testDestroy() {
((AbstractContext)context).destroy(manager);
assert context.get(tunaBean, false) == null;
}

@Test(groups="contexts")
public void testThreadSafety() {
//TODO stub
assert false;
}

}
Expand Up @@ -3,7 +3,6 @@
import static org.jboss.webbeans.test.util.Util.createSimpleWebBean;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

Expand Down

0 comments on commit a665a3e

Please sign in to comment.