[webbeans-commits] Webbeans SVN: r2303 - in ri/trunk: impl/src/main/java/org/jboss/webbeans/bean/proxy and 4 other directories.
webbeans-commits at lists.jboss.org
webbeans-commits at lists.jboss.org
Sun Apr 5 16:03:04 EDT 2009
Author: pete.muir at jboss.org
Date: 2009-04-05 16:03:03 -0400 (Sun, 05 Apr 2009)
New Revision: 2303
Added:
ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/manager/
ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/manager/Foo.java
ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/manager/ManagerTest.java
Modified:
ri/trunk/impl/src/main/java/org/jboss/webbeans/CurrentManager.java
ri/trunk/impl/src/main/java/org/jboss/webbeans/ManagerImpl.java
ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/proxy/ClientProxyMethodHandler.java
ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/proxy/ClientProxyProvider.java
ri/trunk/jboss-tck-runner/pom.xml
ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/AbstractWebBeansTest.java
ri/trunk/tests/unit-tests.xml
Log:
up memory for running tests, fix serialization for child managers, use correct manager in client proxy
Modified: ri/trunk/impl/src/main/java/org/jboss/webbeans/CurrentManager.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/CurrentManager.java 2009-04-05 13:14:58 UTC (rev 2302)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/CurrentManager.java 2009-04-05 20:03:03 UTC (rev 2303)
@@ -17,7 +17,10 @@
package org.jboss.webbeans;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
/**
* Access point for getting/setting current Managager
*
@@ -25,8 +28,11 @@
*/
public class CurrentManager
{
+
// The root manager instance
- protected static ManagerImpl managerImpl;
+ private static Integer rootManagerId;
+
+ private final static Map<Integer, ManagerImpl> managers = new ConcurrentHashMap<Integer, ManagerImpl>();
/**
* Gets the root manager
@@ -35,7 +41,7 @@
*/
public static ManagerImpl rootManager()
{
- return managerImpl;
+ return managers.get(rootManagerId);
}
/**
@@ -45,7 +51,26 @@
*/
public static void setRootManager(ManagerImpl managerImpl)
{
- CurrentManager.managerImpl = managerImpl;
+ if (managerImpl == null)
+ {
+ rootManagerId = null;
+ }
+ else
+ {
+ rootManagerId = add(managerImpl);
+ }
}
+ public static ManagerImpl get(Integer key)
+ {
+ return managers.get(key);
+ }
+
+ public static Integer add(ManagerImpl manager)
+ {
+ Integer id = manager.getId();
+ managers.put(id, manager);
+ return id;
+ }
+
}
Modified: ri/trunk/impl/src/main/java/org/jboss/webbeans/ManagerImpl.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/ManagerImpl.java 2009-04-05 13:14:58 UTC (rev 2302)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/ManagerImpl.java 2009-04-05 20:03:03 UTC (rev 2303)
@@ -34,9 +34,11 @@
import java.util.Stack;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArrayList;
+import java.util.concurrent.CopyOnWriteArraySet;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicInteger;
import javax.context.Context;
import javax.context.ContextNotActiveException;
@@ -82,9 +84,9 @@
import org.jboss.webbeans.util.Beans;
import org.jboss.webbeans.util.Proxies;
import org.jboss.webbeans.util.Reflections;
-import org.jboss.webbeans.util.collections.multi.ConcurrentSetHashMultiMap;
import org.jboss.webbeans.util.collections.multi.ConcurrentListHashMultiMap;
import org.jboss.webbeans.util.collections.multi.ConcurrentListMultiMap;
+import org.jboss.webbeans.util.collections.multi.ConcurrentSetHashMultiMap;
import org.jboss.webbeans.util.collections.multi.ConcurrentSetMultiMap;
/**
@@ -123,6 +125,7 @@
private transient final Map<Class<?>, EnterpriseBean<?>> newEnterpriseBeans;
private transient final Map<String, RIBean<?>> riBeans;
private final transient Map<Bean<?>, Bean<?>> specializedBeans;
+ private final transient AtomicInteger ids;
/*
@@ -141,7 +144,9 @@
private transient final ThreadLocal<Stack<InjectionPoint>> currentInjectionPoint;
private transient List<Bean<?>> beans;
private final transient Namespace rootNamespace;
- private final ConcurrentSetMultiMap<Type, EventObserver<?>> registeredObservers;
+ private final transient ConcurrentSetMultiMap<Type, EventObserver<?>> registeredObservers;
+ private final transient Set<ManagerImpl> childActivities;
+ private final Integer id;
/**
@@ -166,8 +171,9 @@
new ClientProxyProvider(),
new ConcurrentListHashMultiMap<Class<? extends Annotation>, Context>(),
new HashMap<Bean<?>, Bean<?>>(),
-
- defaultEnabledDeploymentTypes);
+ defaultEnabledDeploymentTypes,
+ new AtomicInteger()
+ );
}
/**
@@ -195,7 +201,9 @@
parentManager.getClientProxyProvider(),
parentManager.getContexts(),
parentManager.getSpecializedBeans(),
- parentManager.getEnabledDeploymentTypes());
+ parentManager.getEnabledDeploymentTypes(),
+ parentManager.getIds()
+ );
}
/**
@@ -213,7 +221,8 @@
ClientProxyProvider clientProxyProvider,
ConcurrentListMultiMap<Class<? extends Annotation>, Context> contexts,
Map<Bean<?>, Bean<?>> specializedBeans,
- List<Class<? extends Annotation>> enabledDeploymentTypes
+ List<Class<? extends Annotation>> enabledDeploymentTypes,
+ AtomicInteger ids
)
{
this.services = serviceRegistry;
@@ -226,10 +235,13 @@
this.registeredObservers = registeredObservers;
setEnabledDeploymentTypes(enabledDeploymentTypes);
this.rootNamespace = rootNamespace;
+ this.ids = ids;
+ this.id = ids.incrementAndGet();
this.resolver = new Resolver(this);
this.eventManager = new EventManager(this);
this.nonContextualInjector = new NonContextualInjector(this);
+ this.childActivities = new CopyOnWriteArraySet<ManagerImpl>();
this.currentInjectionPoint = new ThreadLocal<Stack<InjectionPoint>>()
{
@Override
@@ -280,6 +292,10 @@
resolver.clear();
beans.add(bean);
registerBeanNamespace(bean);
+ for (ManagerImpl childActivity : childActivities)
+ {
+ childActivity.addBean(bean);
+ }
return this;
}
@@ -557,43 +573,44 @@
throw new UnsupportedOperationException("Not yet implemented");
}
+ public <T> Manager addObserver(Observer<T> observer, Class<T> eventType, Annotation... bindings)
+ {
+ return _addObserver(observer, eventType, bindings);
+ }
+
/**
- * Registers an observer for a given event type and binding types
+ * Shortcut to register an ObserverImpl
*
- * @param observer The observer to register
- * @param eventType The event type to match
- * @param bindings The bindings to match
- * @return A reference to the manager
- *
- * @see javax.inject.manager.Manager#addObserver(javax.event.Observer,
- * java.lang.Class, java.lang.annotation.Annotation[])
+ * @param <T>
+ * @param observer
+ * @return
*/
- public <T> Manager addObserver(Observer<T> observer, Class<T> eventType, Annotation... bindings)
+ public <T> Manager addObserver(ObserverImpl<T> observer)
{
- this.eventManager.addObserver(observer, eventType, bindings);
- return this;
+ return _addObserver(observer, observer.getEventType(), observer.getBindingsAsArray());
}
- public <T> Manager addObserver(ObserverImpl<T> observer)
+ public <T> Manager addObserver(Observer<T> observer, TypeLiteral<T> eventType, Annotation... bindings)
{
- this.eventManager.addObserver(observer, observer.getEventType(), observer.getBindingsAsArray());
- return this;
+ return _addObserver(observer, eventType.getType(), bindings);
}
-
+
/**
- * Registers an observer for a given event type literal and binding types
- *
- * @param observer The observer to register
- * @param eventType The event type literal to match
- * @param bindings The bindings to match
- * @return A reference to the manager
- *
- * @see javax.inject.manager.Manager#addObserver(javax.event.Observer,
- * javax.inject.TypeLiteral, java.lang.annotation.Annotation[])
+ * Does the actual observer registration
+ *
+ * @param <T>
+ * @param observer
+ * @param eventType
+ * @param bindings
+ * @return
*/
- public <T> Manager addObserver(Observer<T> observer, TypeLiteral<T> eventType, Annotation... bindings)
+ protected <T> Manager _addObserver(Observer<T> observer, Type eventType, Annotation... bindings)
{
- eventManager.addObserver(observer, eventType.getType(), bindings);
+ this.eventManager.addObserver(observer, eventType, bindings);
+ for (ManagerImpl childActivity : childActivities)
+ {
+ childActivity._addObserver(observer, eventType, bindings);
+ }
return this;
}
@@ -704,7 +721,7 @@
{
if (creationalContext != null || (creationalContext == null && getContext(bean.getScopeType()).get(bean) != null))
{
- return (T) clientProxyProvider.getClientProxy(bean);
+ return (T) clientProxyProvider.getClientProxy(this, bean);
}
else
{
@@ -968,9 +985,12 @@
throw new UnsupportedOperationException();
}
- public Manager createActivity()
+ public ManagerImpl createActivity()
{
- return newChildManager(this);
+ ManagerImpl childActivity = newChildManager(this);
+ childActivities.add(childActivity);
+ CurrentManager.add(childActivity);
+ return childActivity;
}
public Manager setCurrent(Class<? extends Annotation> scopeType)
@@ -1015,7 +1035,7 @@
protected Object readResolve()
{
- return CurrentManager.rootManager();
+ return CurrentManager.get(id);
}
/**
@@ -1076,6 +1096,16 @@
return contexts;
}
+ protected AtomicInteger getIds()
+ {
+ return ids;
+ }
+
+ public Integer getId()
+ {
+ return id;
+ }
+
public ConcurrentSetMultiMap<Type, EventObserver<?>> getRegisteredObservers()
{
return registeredObservers;
Modified: ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/proxy/ClientProxyMethodHandler.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/proxy/ClientProxyMethodHandler.java 2009-04-05 13:14:58 UTC (rev 2302)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/proxy/ClientProxyMethodHandler.java 2009-04-05 20:03:03 UTC (rev 2303)
@@ -25,7 +25,7 @@
import javax.context.Context;
import javax.inject.manager.Bean;
-import org.jboss.webbeans.CurrentManager;
+import org.jboss.webbeans.ManagerImpl;
import org.jboss.webbeans.context.CreationalContextImpl;
import org.jboss.webbeans.log.LogProvider;
import org.jboss.webbeans.log.Logging;
@@ -48,8 +48,10 @@
// The bean
private transient Bean<?> bean;
// The bean index in the manager
- private int beanIndex;
+ private final int beanIndex;
+ private final ManagerImpl manager;
+
private static final ThreadLocal<CreationalContextImpl<?>> currentCreationalContext = new ThreadLocal<CreationalContextImpl<?>>();
/**
@@ -58,10 +60,11 @@
* @param bean The bean to proxy
* @param beanIndex The index to the bean in the manager bean list
*/
- public ClientProxyMethodHandler(Bean<?> bean, int beanIndex)
+ public ClientProxyMethodHandler(Bean<?> bean, ManagerImpl manager, int beanIndex)
{
this.bean = bean;
this.beanIndex = beanIndex;
+ this.manager = manager;
log.trace("Created method handler for bean " + bean + " indexed as " + beanIndex);
}
@@ -88,7 +91,7 @@
{
if (bean == null)
{
- bean = CurrentManager.rootManager().getBeans().get(beanIndex);
+ bean = manager.getBeans().get(beanIndex);
}
Object proxiedInstance = getProxiedInstance(bean);
Object returnValue = Reflections.lookupMethod(proxiedMethod, proxiedInstance).invoke(proxiedInstance, args);
@@ -110,7 +113,7 @@
}
try
{
- Context context = CurrentManager.rootManager().getContext(bean.getScopeType());
+ Context context = manager.getContext(bean.getScopeType());
return context.get(bean, creationalContext);
}
finally
Modified: ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/proxy/ClientProxyProvider.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/proxy/ClientProxyProvider.java 2009-04-05 13:14:58 UTC (rev 2302)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/proxy/ClientProxyProvider.java 2009-04-05 20:03:03 UTC (rev 2303)
@@ -28,7 +28,7 @@
import javax.inject.DefinitionException;
import javax.inject.manager.Bean;
-import org.jboss.webbeans.CurrentManager;
+import org.jboss.webbeans.ManagerImpl;
import org.jboss.webbeans.util.Proxies;
import org.jboss.webbeans.util.collections.ConcurrentCache;
@@ -71,12 +71,12 @@
* @throws InstantiationException When the proxy couldn't be created
* @throws IllegalAccessException When the proxy couldn't be created
*/
- private static <T> T createClientProxy(Bean<T> bean, int beanIndex) throws RuntimeException
+ private static <T> T createClientProxy(Bean<T> bean, ManagerImpl manager, int beanIndex) throws RuntimeException
{
try
{
- ClientProxyMethodHandler proxyMethodHandler = new ClientProxyMethodHandler(bean, beanIndex);
+ ClientProxyMethodHandler proxyMethodHandler = new ClientProxyMethodHandler(bean, manager, beanIndex);
Set<Type> classes = new LinkedHashSet<Type>(bean.getTypes());
classes.add(Serializable.class);
ProxyFactory proxyFactory = Proxies.getProxyFactory(classes);
@@ -110,19 +110,19 @@
* @return the client proxy for the bean
*/
// TODO: What is this create parameter? Something obsolete?
- public <T> T getClientProxy(final Bean<T> bean)
+ public <T> T getClientProxy(final ManagerImpl manager, final Bean<T> bean)
{
return pool.putIfAbsent(bean, new Callable<T>()
{
public T call() throws Exception
{
- int beanIndex = CurrentManager.rootManager().getBeans().indexOf(bean);
+ int beanIndex = manager.getBeans().indexOf(bean);
if (beanIndex < 0)
{
throw new DefinitionException(bean + " is not known to the manager");
}
- return createClientProxy(bean, beanIndex);
+ return createClientProxy(bean, manager, beanIndex);
}
});
Modified: ri/trunk/jboss-tck-runner/pom.xml
===================================================================
--- ri/trunk/jboss-tck-runner/pom.xml 2009-04-05 13:14:58 UTC (rev 2302)
+++ ri/trunk/jboss-tck-runner/pom.xml 2009-04-05 20:03:03 UTC (rev 2303)
@@ -92,6 +92,8 @@
<suiteXmlFiles>
<suiteXmlFile>${project.build.directory}/dependency/jsr299-tck-impl-suite.xml</suiteXmlFile>
</suiteXmlFiles>
+ <argLine>-Xmx128m</argLine>
+ <forkMode>once</forkMode>
</configuration>
</plugin>
<plugin>
Modified: ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/AbstractWebBeansTest.java
===================================================================
--- ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/AbstractWebBeansTest.java 2009-04-05 13:14:58 UTC (rev 2302)
+++ ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/AbstractWebBeansTest.java 2009-04-05 20:03:03 UTC (rev 2303)
@@ -1,6 +1,10 @@
package org.jboss.webbeans.test.unit;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
import java.lang.annotation.Annotation;
import java.net.URL;
import java.util.Arrays;
@@ -114,4 +118,18 @@
}
}
+ protected byte[] serialize(Object instance) throws IOException
+ {
+ ByteArrayOutputStream bytes = new ByteArrayOutputStream();
+ ObjectOutputStream out = new ObjectOutputStream(bytes);
+ out.writeObject(instance);
+ return bytes.toByteArray();
+ }
+
+ protected Object deserialize(byte[] bytes) throws IOException, ClassNotFoundException
+ {
+ ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(bytes));
+ return in.readObject();
+ }
+
}
Added: ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/manager/Foo.java
===================================================================
--- ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/manager/Foo.java (rev 0)
+++ ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/manager/Foo.java 2009-04-05 20:03:03 UTC (rev 2303)
@@ -0,0 +1,6 @@
+package org.jboss.webbeans.test.unit.manager;
+
+public class Foo
+{
+
+}
Property changes on: ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/manager/Foo.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/manager/ManagerTest.java
===================================================================
--- ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/manager/ManagerTest.java (rev 0)
+++ ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/manager/ManagerTest.java 2009-04-05 20:03:03 UTC (rev 2303)
@@ -0,0 +1,140 @@
+package org.jboss.webbeans.test.unit.manager;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Type;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.context.CreationalContext;
+import javax.context.Dependent;
+import javax.inject.Production;
+import javax.inject.manager.Bean;
+import javax.inject.manager.InjectionPoint;
+import javax.inject.manager.Manager;
+
+import org.jboss.testharness.impl.packaging.Artifact;
+import org.jboss.testharness.impl.packaging.Packaging;
+import org.jboss.webbeans.ManagerImpl;
+import org.jboss.webbeans.literal.CurrentLiteral;
+import org.jboss.webbeans.test.unit.AbstractWebBeansTest;
+import org.testng.annotations.Test;
+
+ at Artifact
+ at Packaging
+public class ManagerTest extends AbstractWebBeansTest
+{
+
+ private static final Set<Annotation> DEFAULT_BINDINGS = new HashSet<Annotation>();
+
+ static
+ {
+ DEFAULT_BINDINGS.add(new CurrentLiteral());
+ }
+
+ private static interface Dummy {}
+
+ private static class DummyBean extends Bean<Dummy>
+ {
+
+ private static final Set<Type> TYPES = new HashSet<Type>();
+
+ static
+ {
+ TYPES.add(Dummy.class);
+ TYPES.add(Object.class);
+ }
+
+ protected DummyBean(Manager manager)
+ {
+ super(manager);
+ }
+
+ @Override
+ public Set<Annotation> getBindings()
+ {
+ return DEFAULT_BINDINGS;
+ }
+
+ @Override
+ public Class<? extends Annotation> getDeploymentType()
+ {
+ return Production.class;
+ }
+
+ @Override
+ public Set<? extends InjectionPoint> getInjectionPoints()
+ {
+ return Collections.emptySet();
+ }
+
+ @Override
+ public String getName()
+ {
+ return null;
+ }
+
+ @Override
+ public Class<? extends Annotation> getScopeType()
+ {
+ return Dependent.class;
+ }
+
+ @Override
+ public Set<? extends Type> getTypes()
+ {
+ return TYPES;
+ }
+
+ @Override
+ public boolean isNullable()
+ {
+ return true;
+ }
+
+ @Override
+ public boolean isSerializable()
+ {
+ return false;
+ }
+
+ public Dummy create(CreationalContext<Dummy> creationalContext)
+ {
+ return null;
+ }
+
+ public void destroy(Dummy instance)
+ {
+
+ }
+
+ }
+
+ @Test
+ public void testRootManagerSerializability() throws Exception
+ {
+ Integer rootManagerId = manager.getId();
+ ManagerImpl deserializedRootManager = (ManagerImpl) deserialize(serialize(manager));
+ assert deserializedRootManager.getId().equals(rootManagerId);
+ assert manager.resolveByType(Foo.class).size() == 1;
+ assert deserializedRootManager.resolveByType(Foo.class).size() == 1;
+ assert manager.resolveByType(Foo.class).iterator().next().equals(deserializedRootManager.resolveByType(Foo.class).iterator().next());
+ }
+
+ @Test
+ public void testChildManagerSerializability() throws Exception
+ {
+ ManagerImpl childManager = manager.createActivity();
+ Bean<?> dummyBean = new DummyBean(childManager);
+ childManager.addBean(dummyBean);
+ Integer childManagerId = childManager.getId();
+ ManagerImpl deserializedChildManager = (ManagerImpl) deserialize(serialize(childManager));
+ assert deserializedChildManager.getId().equals(childManagerId);
+ assert childManager.resolveByType(Dummy.class).size() == 1;
+ assert deserializedChildManager.resolveByType(Dummy.class).size() == 1;
+ assert childManager.resolveByType(Dummy.class).iterator().next().equals(deserializedChildManager.resolveByType(Dummy.class).iterator().next());
+ }
+
+
+
+}
Property changes on: ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/manager/ManagerTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: ri/trunk/tests/unit-tests.xml
===================================================================
--- ri/trunk/tests/unit-tests.xml 2009-04-05 13:14:58 UTC (rev 2302)
+++ ri/trunk/tests/unit-tests.xml 2009-04-05 20:03:03 UTC (rev 2303)
@@ -64,6 +64,7 @@
<package name="org.jboss.webbeans.test.unit.implementation.proxy" />
<package name="org.jboss.webbeans.test.unit.implementation.proxy.enterprise" />
<package name="org.jboss.webbeans.test.unit.lookup" />
+ <package name="org.jboss.webbeans.test.unit.manager" />
<package name="org.jboss.webbeans.test.unit.lookup.circular" />
<package name="org.jboss.webbeans.test.unit.xml.deploy" />
<package name="org.jboss.webbeans.test.unit.xml.parser" />
More information about the weld-commits
mailing list