[webbeans-commits] Webbeans SVN: r403 - in ri/trunk/webbeans-ri/src: test/java/org/jboss/webbeans/test/mock and 1 other directory.
by webbeans-commits@lists.jboss.org
Author: pete.muir(a)jboss.org
Date: 2008-12-04 12:58:45 -0500 (Thu, 04 Dec 2008)
New Revision: 403
Modified:
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bootstrap/spi/EjbDescriptor.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bootstrap/spi/WebBeanDiscovery.java
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/mock/MockWebBeanDiscovery.java
Log:
Update SPI to support JNDI name per business interface
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bootstrap/spi/EjbDescriptor.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bootstrap/spi/EjbDescriptor.java 2008-12-04 14:15:21 UTC (rev 402)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bootstrap/spi/EjbDescriptor.java 2008-12-04 17:58:45 UTC (rev 403)
@@ -29,6 +29,24 @@
*/
public interface EjbDescriptor<T>
{
+
+ public interface BusinessInterfaceDescriptor
+ {
+
+ /**
+ * Gets the business interface class
+ */
+ public Class<?> getInterface();
+
+ /**
+ * Gets the JNDI name under which the EJB is registered
+ *
+ * @return The JNDI name
+ */
+ public String getJndiName();
+
+ }
+
/**
* Gets the EJB type
*
@@ -37,18 +55,18 @@
public Class<T> getType();
/**
- * Gets the JNDI name under which the EJB is registered
+ * Gets the local business interfaces of the EJB
*
- * @return The JNDI name
+ * @return An iterator over the local business interfaces
*/
- public String getJndiName();
-
+ public Iterator<BusinessInterfaceDescriptor> getLocalBusinessInterfaces();
+
/**
- * Gets the local interfaces of the EJB
+ * Gets the remote business interfaces of the EJB
*
- * @return An iterator to the local interfaces
+ * @return An iterator over the remote business interfaces
*/
- public Iterator<Class<?>> getLocalInterfaces();
+ public Iterator<BusinessInterfaceDescriptor> getRemoteBusinessInterfaces();
/**
* Get the remove methods of the EJB
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bootstrap/spi/WebBeanDiscovery.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bootstrap/spi/WebBeanDiscovery.java 2008-12-04 14:15:21 UTC (rev 402)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bootstrap/spi/WebBeanDiscovery.java 2008-12-04 17:58:45 UTC (rev 403)
@@ -48,6 +48,6 @@
*
* @return The bean class to descriptor map
*/
- public Map<Class<?>, EjbDescriptor<?>> discoverEjbs();
+ public Map<String, EjbDescriptor<?>> discoverEjbs();
}
Modified: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/mock/MockWebBeanDiscovery.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/mock/MockWebBeanDiscovery.java 2008-12-04 14:15:21 UTC (rev 402)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/mock/MockWebBeanDiscovery.java 2008-12-04 17:58:45 UTC (rev 403)
@@ -31,7 +31,7 @@
return webBeanClasses;
}
- public Map<Class<?>, EjbDescriptor<?>> discoverEjbs()
+ public Map<String, EjbDescriptor<?>> discoverEjbs()
{
// TODO Auto-generated method stub
return null;
16 years
[webbeans-commits] Webbeans SVN: r402 - in ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans: bean and 2 other directories.
by webbeans-commits@lists.jboss.org
Author: pete.muir(a)jboss.org
Date: 2008-12-04 09:15:21 -0500 (Thu, 04 Dec 2008)
New Revision: 402
Modified:
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/ManagerImpl.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/EnterpriseBean.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/SimpleBean.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bootstrap/Bootstrap.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/servlet/ServletLifecycle.java
Log:
Oops
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/ManagerImpl.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/ManagerImpl.java 2008-12-04 13:50:24 UTC (rev 401)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/ManagerImpl.java 2008-12-04 14:15:21 UTC (rev 402)
@@ -72,6 +72,14 @@
*/
public class ManagerImpl implements Manager
{
+
+ private static ManagerImpl instance = new ManagerImpl();
+
+ public static ManagerImpl instance()
+ {
+ return instance;
+ }
+
private List<Class<? extends Annotation>> enabledDeploymentTypes;
private MetaDataCache metaDataCache;
private EventManager eventManager;
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/EnterpriseBean.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/EnterpriseBean.java 2008-12-04 13:50:24 UTC (rev 401)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/EnterpriseBean.java 2008-12-04 14:15:21 UTC (rev 402)
@@ -305,6 +305,7 @@
Class<?> superclass = getAnnotatedItem().getType().getSuperclass();
if (superclass != null)
{
+ // TODO look up this bean and do this via init
return new EnterpriseBean(superclass, getManager());
}
else
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/SimpleBean.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/SimpleBean.java 2008-12-04 13:50:24 UTC (rev 401)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/SimpleBean.java 2008-12-04 14:15:21 UTC (rev 402)
@@ -328,6 +328,7 @@
Class<?> superclass = getAnnotatedItem().getType().getSuperclass();
if (superclass != null)
{
+ // TODO look up this bean and do this via init
return new SimpleBean(superclass, getManager());
}
else
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bootstrap/Bootstrap.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bootstrap/Bootstrap.java 2008-12-04 13:50:24 UTC (rev 401)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bootstrap/Bootstrap.java 2008-12-04 14:15:21 UTC (rev 402)
@@ -18,9 +18,9 @@
package org.jboss.webbeans.bootstrap;
import static org.jboss.webbeans.util.BeanFactory.createEnterpriseBean;
+import static org.jboss.webbeans.util.BeanFactory.createEventBean;
import static org.jboss.webbeans.util.BeanFactory.createProducerMethodBean;
import static org.jboss.webbeans.util.BeanFactory.createSimpleBean;
-import static org.jboss.webbeans.util.BeanFactory.createEventBean;
import java.util.Arrays;
import java.util.HashSet;
@@ -56,11 +56,11 @@
/**
* Constructor
*
- * Starts up with a fresh manager
+ * Starts up with the singleton Manager
*/
public Bootstrap()
{
- this(new ManagerImpl());
+ this(ManagerImpl.instance());
}
/**
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/servlet/ServletLifecycle.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/servlet/ServletLifecycle.java 2008-12-04 13:50:24 UTC (rev 401)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/servlet/ServletLifecycle.java 2008-12-04 14:15:21 UTC (rev 402)
@@ -31,7 +31,6 @@
import org.jboss.webbeans.contexts.SessionContext;
import org.jboss.webbeans.log.LogProvider;
import org.jboss.webbeans.log.Logging;
-import org.jboss.webbeans.util.JNDI;
import org.jboss.webbeans.util.Reflections;
/**
@@ -94,7 +93,7 @@
* @param request The request
*/
public static void beginRequest(HttpServletRequest request) {
- ManagerImpl manager = (ManagerImpl) JNDI.lookup(MANAGER_JNDI_KEY);
+ ManagerImpl manager = ManagerImpl.instance();
SessionContext sessionContext = (SessionContext) manager.getContext(SessionScoped.class);
sessionContext.setSession(request.getSession(true));
}
@@ -122,7 +121,6 @@
*
* @return The discoverer
*/
- // TODO move some of this bootstrap for reuse outside Servlet
private static WebBeanDiscovery getWebBeanDiscovery()
{
WebBeanDiscovery webBeanDiscovery = null;
16 years
[webbeans-commits] Webbeans SVN: r401 - ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/el.
by webbeans-commits@lists.jboss.org
Author: pete.muir(a)jboss.org
Date: 2008-12-04 08:50:24 -0500 (Thu, 04 Dec 2008)
New Revision: 401
Modified:
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/el/WebBeansELResolver.java
Log:
Simple ELResolver impl
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/el/WebBeansELResolver.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/el/WebBeansELResolver.java 2008-12-04 13:22:32 UTC (rev 400)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/el/WebBeansELResolver.java 2008-12-04 13:50:24 UTC (rev 401)
@@ -23,6 +23,8 @@
import javax.el.ELContext;
import javax.el.ELResolver;
+import org.jboss.webbeans.ManagerImpl;
+
public class WebBeansELResolver extends ELResolver
{
@@ -32,7 +34,6 @@
@Override
public Class<?> getCommonPropertyType(ELContext context, Object base)
{
- // TODO Auto-generated method stub
return null;
}
@@ -42,7 +43,6 @@
@Override
public Iterator<FeatureDescriptor> getFeatureDescriptors(ELContext context, Object base)
{
- // TODO Auto-generated method stub
return null;
}
@@ -52,7 +52,6 @@
@Override
public Class<?> getType(ELContext context, Object base, Object property)
{
- // TODO Auto-generated method stub
return null;
}
@@ -62,8 +61,14 @@
@Override
public Object getValue(ELContext context, Object base, Object property)
{
- // TODO Auto-generated method stub
- return null;
+ if (base == null && property != null)
+ {
+ return ManagerImpl.instance().getInstanceByName(property.toString());
+ }
+ else
+ {
+ return null;
+ }
}
/**
@@ -72,7 +77,6 @@
@Override
public boolean isReadOnly(ELContext context, Object base, Object property)
{
- // TODO Auto-generated method stub
return false;
}
@@ -82,7 +86,6 @@
@Override
public void setValue(ELContext context, Object base, Object property, Object value)
{
- // TODO Auto-generated method stub
}
}
16 years
[webbeans-commits] Webbeans SVN: r400 - in ri/trunk/webbeans-ri/src: test/java/org/jboss/webbeans/test and 1 other directory.
by webbeans-commits@lists.jboss.org
Author: pete.muir(a)jboss.org
Date: 2008-12-04 08:22:32 -0500 (Thu, 04 Dec 2008)
New Revision: 400
Modified:
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/MetaDataCache.java
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/AbstractTest.java
Log:
Auto register stereotypes
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/MetaDataCache.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/MetaDataCache.java 2008-12-04 13:19:02 UTC (rev 399)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/MetaDataCache.java 2008-12-04 13:22:32 UTC (rev 400)
@@ -38,23 +38,18 @@
private ConcurrentCache<Class<?>, EjbMetaData<?>> ejbMetaDataMap = new ConcurrentCache<Class<?>, EjbMetaData<?>>();
- public <T extends Annotation> void addStereotype(final Class<T> stereotype)
+ public <T extends Annotation> StereotypeModel<T> getStereotype(final Class<T> stereotype)
{
- stereotypes.putIfAbsent(stereotype, new Callable<StereotypeModel<?>>()
+ return stereotypes.putIfAbsent(stereotype, new Callable<StereotypeModel<T>>()
{
- public StereotypeModel<?> call() throws Exception
+ public StereotypeModel<T> call() throws Exception
{
return new StereotypeModel<T>(stereotype);
}
});
}
- public StereotypeModel<?> getStereotype(Class<? extends Annotation> annotationType)
- {
- return stereotypes.getValue(annotationType);
- }
-
public <T extends Annotation> ScopeModel<T> getScopeModel(final Class<T> scopeType)
{
return scopes.putIfAbsent(scopeType, new Callable<ScopeModel<T>>()
@@ -64,7 +59,7 @@
{
return new ScopeModel<T>(scopeType);
}
-
+
});
}
@@ -77,7 +72,7 @@
{
return new BindingTypeModel<T>(bindingType);
}
-
+
});
}
@@ -90,7 +85,7 @@
{
return new EjbMetaData<T>(clazz);
}
-
+
});
}
Modified: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/AbstractTest.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/AbstractTest.java 2008-12-04 13:19:02 UTC (rev 399)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/AbstractTest.java 2008-12-04 13:22:32 UTC (rev 400)
@@ -1,19 +1,11 @@
package org.jboss.webbeans.test;
-import javax.webbeans.Decorator;
-import javax.webbeans.Interceptor;
import javax.webbeans.Production;
import javax.webbeans.Standard;
import org.jboss.webbeans.bootstrap.Bootstrap;
-import org.jboss.webbeans.test.annotations.AnimalStereotype;
import org.jboss.webbeans.test.annotations.AnotherDeploymentType;
-import org.jboss.webbeans.test.annotations.FishStereotype;
import org.jboss.webbeans.test.annotations.HornedAnimalDeploymentType;
-import org.jboss.webbeans.test.annotations.HornedMammalStereotype;
-import org.jboss.webbeans.test.annotations.MammalStereotype;
-import org.jboss.webbeans.test.annotations.RequestScopedAnimalStereotype;
-import org.jboss.webbeans.test.annotations.RiverFishStereotype;
import org.jboss.webbeans.test.mock.MockBootstrap;
import org.jboss.webbeans.test.mock.MockManagerImpl;
import org.testng.annotations.BeforeMethod;
@@ -35,7 +27,6 @@
protected void init()
{
- addStereotypes();
addEnabledDeploymentTypes();
}
@@ -43,17 +34,5 @@
{
manager.setEnabledDeploymentTypes(Standard.class, Production.class, AnotherDeploymentType.class, HornedAnimalDeploymentType.class);
}
-
- protected void addStereotypes()
- {
- manager.getMetaDataCache().addStereotype(Decorator.class);
- manager.getMetaDataCache().addStereotype(Interceptor.class);
- manager.getMetaDataCache().addStereotype(AnimalStereotype.class);
- manager.getMetaDataCache().addStereotype(HornedMammalStereotype.class);
- manager.getMetaDataCache().addStereotype(MammalStereotype.class);
- manager.getMetaDataCache().addStereotype(FishStereotype.class);
- manager.getMetaDataCache().addStereotype(RiverFishStereotype.class);
- manager.getMetaDataCache().addStereotype(RequestScopedAnimalStereotype.class);
- }
}
16 years
[webbeans-commits] Webbeans SVN: r399 - in ri/trunk/webbeans-ri/src: main/java/org/jboss/webbeans/contexts and 2 other directories.
by webbeans-commits@lists.jboss.org
Author: pete.muir(a)jboss.org
Date: 2008-12-04 08:19:02 -0500 (Thu, 04 Dec 2008)
New Revision: 399
Modified:
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/MetaDataCache.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/contexts/ContextMap.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/util/ConcurrentCache.java
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/AbstractTest.java
Log:
concurrency support for metadata
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/MetaDataCache.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/MetaDataCache.java 2008-12-04 13:00:28 UTC (rev 398)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/MetaDataCache.java 2008-12-04 13:19:02 UTC (rev 399)
@@ -18,176 +18,82 @@
package org.jboss.webbeans;
import java.lang.annotation.Annotation;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.Callable;
import org.jboss.webbeans.ejb.EjbMetaData;
-import org.jboss.webbeans.model.AnnotationModel;
import org.jboss.webbeans.model.BindingTypeModel;
import org.jboss.webbeans.model.ScopeModel;
import org.jboss.webbeans.model.StereotypeModel;
+import org.jboss.webbeans.util.ConcurrentCache;
import org.jboss.webbeans.util.Strings;
-import com.google.common.collect.ForwardingMap;
-
public class MetaDataCache
{
- private abstract class AnnotationModelMap<T extends AnnotationModel<?>> extends ForwardingMap<Class<? extends Annotation>, T>
- {
+ private ConcurrentCache<Class<? extends Annotation>, StereotypeModel<?>> stereotypes = new ConcurrentCache<Class<? extends Annotation>, StereotypeModel<?>>();
- Map<Class<? extends Annotation>, T> delegate;
+ private ConcurrentCache<Class<? extends Annotation>, ScopeModel<?>> scopes = new ConcurrentCache<Class<? extends Annotation>, ScopeModel<?>>();
- public AnnotationModelMap()
- {
- delegate = new ConcurrentHashMap<Class<? extends Annotation>, T>();
- }
+ private ConcurrentCache<Class<? extends Annotation>, BindingTypeModel<?>> bindingTypes = new ConcurrentCache<Class<? extends Annotation>, BindingTypeModel<?>>();
- public <S extends Annotation> T putIfAbsent(Class<S> key)
- {
- if (!containsKey(key))
- {
- T model = createAnnotationModel(key);
- super.put(key, model);
- return model;
- }
- return (T) super.get(key);
- }
+ private ConcurrentCache<Class<?>, EjbMetaData<?>> ejbMetaDataMap = new ConcurrentCache<Class<?>, EjbMetaData<?>>();
- protected abstract <S extends Annotation> T createAnnotationModel(Class<S> type);
-
- @Override
- protected Map<Class<? extends Annotation>, T> delegate()
+ public <T extends Annotation> void addStereotype(final Class<T> stereotype)
+ {
+ stereotypes.putIfAbsent(stereotype, new Callable<StereotypeModel<?>>()
{
- return delegate;
- }
- @Override
- public String toString()
- {
- return Strings.mapToString("AnnotationModelMap (annotation -> ?): ", delegate);
- }
-
+ public StereotypeModel<?> call() throws Exception
+ {
+ return new StereotypeModel<T>(stereotype);
+ }
+ });
}
- @SuppressWarnings("unchecked")
- private class ScopeModelMap extends AnnotationModelMap<ScopeModel<?>>
+ public StereotypeModel<?> getStereotype(Class<? extends Annotation> annotationType)
{
-
- @Override
- public <S extends Annotation> ScopeModel<S> putIfAbsent(Class<S> key)
- {
- return (ScopeModel<S>) super.putIfAbsent(key);
- }
-
- @Override
- protected <S extends Annotation> ScopeModel<?> createAnnotationModel(Class<S> type)
- {
- return new ScopeModel<S>(type);
- }
-
- @Override
- public String toString()
- {
- return Strings.mapToString("ScopeModelMap (annotation -> ScopeModel): ", delegate);
- }
-
+ return stereotypes.getValue(annotationType);
}
- @SuppressWarnings("unchecked")
- private class BindingTypeModelMap extends AnnotationModelMap<BindingTypeModel<?>>
+ public <T extends Annotation> ScopeModel<T> getScopeModel(final Class<T> scopeType)
{
-
- @Override
- public <S extends Annotation> BindingTypeModel<S> putIfAbsent(Class<S> key)
+ return scopes.putIfAbsent(scopeType, new Callable<ScopeModel<T>>()
{
- return (BindingTypeModel<S>) super.putIfAbsent(key);
- }
- @Override
- protected <S extends Annotation> BindingTypeModel<?> createAnnotationModel(Class<S> type)
- {
- return new BindingTypeModel<S>(type);
- }
-
- @Override
- public String toString()
- {
- return Strings.mapToString("BindingTypeModelMap (annotation -> BindingTypeModel): ", delegate);
- }
+ public ScopeModel<T> call() throws Exception
+ {
+ return new ScopeModel<T>(scopeType);
+ }
+
+ });
}
- private class EjbMetaDataMap extends ForwardingMap<Class<?>, EjbMetaData<?>>
+ public <T extends Annotation> BindingTypeModel<T> getBindingTypeModel(final Class<T> bindingType)
{
-
- private Map<Class<?>, EjbMetaData<?>> delegate;
-
- public EjbMetaDataMap()
+ return bindingTypes.putIfAbsent(bindingType, new Callable<BindingTypeModel<T>>()
{
- delegate = new HashMap<Class<?>, EjbMetaData<?>>();
- }
- @Override
- protected Map<Class<?>, EjbMetaData<?>> delegate()
- {
- return delegate;
- }
-
- @SuppressWarnings("unchecked")
- public <T> EjbMetaData<T> putIfAbsent(Class<T> key)
- {
- if (!containsKey(key))
+ public BindingTypeModel<T> call() throws Exception
{
- EjbMetaData<T> ejbMetaData = new EjbMetaData<T>(key);
- super.put(key, ejbMetaData);
- return ejbMetaData;
+ return new BindingTypeModel<T>(bindingType);
}
- return (EjbMetaData<T>) super.get(key);
- }
-
- @Override
- public String toString()
- {
- return Strings.mapToString("EJBMetadataMap (class -> EJBMetaData): ", delegate);
- }
-
+
+ });
}
- private Map<Class<? extends Annotation>, StereotypeModel<?>> stereotypes = new HashMap<Class<? extends Annotation>, StereotypeModel<?>>();
-
- private ScopeModelMap scopes = new ScopeModelMap();
-
- private BindingTypeModelMap bindingTypes = new BindingTypeModelMap();
-
- private EjbMetaDataMap ejbMetaDataMap = new EjbMetaDataMap();
-
- public void addStereotype(StereotypeModel<?> stereotype)
+ public <T> EjbMetaData<T> getEjbMetaData(final Class<T> clazz)
{
- stereotypes.put(stereotype.getType(), stereotype);
- }
+ return ejbMetaDataMap.putIfAbsent(clazz, new Callable<EjbMetaData<T>>()
+ {
- public StereotypeModel<?> getStereotype(Class<? extends Annotation> annotationType)
- {
- return stereotypes.get(annotationType);
+ public EjbMetaData<T> call() throws Exception
+ {
+ return new EjbMetaData<T>(clazz);
+ }
+
+ });
}
- public <T extends Annotation> ScopeModel<T> getScopeModel(Class<T> scopeType)
- {
- return scopes.putIfAbsent(scopeType);
- }
-
- public <T extends Annotation> BindingTypeModel<T> getBindingTypeModel(Class<T> bindingType)
- {
- return bindingTypes.putIfAbsent(bindingType);
- }
-
- public <T> EjbMetaData<T> getEjbMetaData(Class<T> clazz)
- {
- return ejbMetaDataMap.putIfAbsent(clazz);
- }
-
@Override
public String toString()
{
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/contexts/ContextMap.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/contexts/ContextMap.java 2008-12-04 13:00:28 UTC (rev 398)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/contexts/ContextMap.java 2008-12-04 13:19:02 UTC (rev 399)
@@ -53,7 +53,7 @@
{
try
{
- return (AbstractContext) get(scopeType).get().iterator().next();
+ return (AbstractContext) getFuture(scopeType).get().iterator().next();
}
catch (InterruptedException e)
{
@@ -84,7 +84,7 @@
{
try
{
- return get(scopeType).get();
+ return getFuture(scopeType).get();
}
catch (InterruptedException e)
{
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/util/ConcurrentCache.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/util/ConcurrentCache.java 2008-12-04 13:00:28 UTC (rev 398)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/util/ConcurrentCache.java 2008-12-04 13:19:02 UTC (rev 399)
@@ -21,11 +21,42 @@
}
@SuppressWarnings("unchecked")
- public <T extends V> Future<T> get(K key)
+ public <T extends V> Future<T> getFuture(K key)
{
return (Future<T>) super.get(key);
}
+ public <T extends V> T getValue(K key)
+ {
+ Future<T> value = (Future<T>) map.get(key);
+ boolean interrupted = false;
+ try
+ {
+ while (true)
+ {
+ try
+ {
+ return value.get();
+ }
+ catch (InterruptedException e)
+ {
+ interrupted = true;
+ }
+ catch (ExecutionException e)
+ {
+ rethrow(e);
+ };
+ }
+ }
+ finally
+ {
+ if (interrupted)
+ {
+ Thread.currentThread().interrupt();
+ }
+ }
+ }
+
public <E> E putIfAbsent(K key, Callable<E> callable)
{
Future<E> value = (Future<E>) map.get(key);
Modified: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/AbstractTest.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/AbstractTest.java 2008-12-04 13:00:28 UTC (rev 398)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/AbstractTest.java 2008-12-04 13:19:02 UTC (rev 399)
@@ -6,7 +6,6 @@
import javax.webbeans.Standard;
import org.jboss.webbeans.bootstrap.Bootstrap;
-import org.jboss.webbeans.model.StereotypeModel;
import org.jboss.webbeans.test.annotations.AnimalStereotype;
import org.jboss.webbeans.test.annotations.AnotherDeploymentType;
import org.jboss.webbeans.test.annotations.FishStereotype;
@@ -47,14 +46,14 @@
protected void addStereotypes()
{
- manager.getMetaDataCache().addStereotype(new StereotypeModel<Decorator>(Decorator.class));
- manager.getMetaDataCache().addStereotype(new StereotypeModel<Interceptor>(Interceptor.class));
- manager.getMetaDataCache().addStereotype(new StereotypeModel<AnimalStereotype>(AnimalStereotype.class));
- manager.getMetaDataCache().addStereotype(new StereotypeModel<HornedMammalStereotype>(HornedMammalStereotype.class));
- manager.getMetaDataCache().addStereotype(new StereotypeModel<MammalStereotype>(MammalStereotype.class));
- manager.getMetaDataCache().addStereotype(new StereotypeModel<FishStereotype>(FishStereotype.class));
- manager.getMetaDataCache().addStereotype(new StereotypeModel<RiverFishStereotype>(RiverFishStereotype.class));
- manager.getMetaDataCache().addStereotype(new StereotypeModel<RequestScopedAnimalStereotype>(RequestScopedAnimalStereotype.class));
+ manager.getMetaDataCache().addStereotype(Decorator.class);
+ manager.getMetaDataCache().addStereotype(Interceptor.class);
+ manager.getMetaDataCache().addStereotype(AnimalStereotype.class);
+ manager.getMetaDataCache().addStereotype(HornedMammalStereotype.class);
+ manager.getMetaDataCache().addStereotype(MammalStereotype.class);
+ manager.getMetaDataCache().addStereotype(FishStereotype.class);
+ manager.getMetaDataCache().addStereotype(RiverFishStereotype.class);
+ manager.getMetaDataCache().addStereotype(RequestScopedAnimalStereotype.class);
}
}
16 years
[webbeans-commits] Webbeans SVN: r398 - in ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans: bean/proxy and 2 other directories.
by webbeans-commits@lists.jboss.org
Author: pete.muir(a)jboss.org
Date: 2008-12-04 08:00:28 -0500 (Thu, 04 Dec 2008)
New Revision: 398
Added:
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/util/ConcurrentCache.java
Modified:
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/ManagerImpl.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/Resolver.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/proxy/ProxyPool.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/contexts/ContextMap.java
Log:
Hide implementation of concurrent cache
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/ManagerImpl.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/ManagerImpl.java 2008-12-03 22:49:55 UTC (rev 397)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/ManagerImpl.java 2008-12-04 13:00:28 UTC (rev 398)
@@ -422,7 +422,7 @@
*/
public Context getContext(Class<? extends Annotation> scopeType)
{
- List<Context> contexts = contextMap.get(scopeType);
+ List<Context> contexts = contextMap.getContext(scopeType);
if (contexts.isEmpty())
{
throw new ContextNotActiveException("No active contexts for " + scopeType.getName());
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/Resolver.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/Resolver.java 2008-12-03 22:49:55 UTC (rev 397)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/Resolver.java 2008-12-04 13:00:28 UTC (rev 398)
@@ -20,18 +20,12 @@
import java.lang.annotation.Annotation;
import java.util.Collection;
import java.util.Collections;
-import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
-import java.util.Map;
import java.util.Set;
import java.util.SortedSet;
import java.util.TreeSet;
import java.util.concurrent.Callable;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.ExecutionException;
-import java.util.concurrent.Future;
-import java.util.concurrent.FutureTask;
import javax.webbeans.NullableDependencyException;
import javax.webbeans.manager.Bean;
@@ -42,11 +36,10 @@
import org.jboss.webbeans.introspector.AnnotatedItem;
import org.jboss.webbeans.introspector.ForwardingAnnotatedItem;
import org.jboss.webbeans.model.BindingTypeModel;
+import org.jboss.webbeans.util.ConcurrentCache;
import org.jboss.webbeans.util.ListComparator;
import org.jboss.webbeans.util.Strings;
-import com.google.common.collect.ForwardingMap;
-
/**
* Implementation of Web Beans type safe and name based bean resolution
*
@@ -94,43 +87,10 @@
}
- /**
- * Type safe map for caching annotation metadata
- */
- @SuppressWarnings("unchecked")
- private class ConcurrentAnnotatedItemMap extends ForwardingMap<AnnotatedItem<?, ?>, Future>
- {
-
- private Map<AnnotatedItem<?, ?>, Future> delegate;
-
- public ConcurrentAnnotatedItemMap()
- {
- delegate = new ConcurrentHashMap<AnnotatedItem<?, ?>, Future>();
- }
-
- public <T> Future<Set<Bean<T>>> get(AnnotatedItem<T, ?> key)
- {
- return (Future<Set<Bean<T>>>) super.get(key);
- }
-
- @Override
- protected Map<AnnotatedItem<?, ?>, Future> delegate()
- {
- return delegate;
- }
-
- @Override
- public String toString()
- {
- return Strings.mapToString("AnnotatedItemMap (annotated item -> bean set): ", delegate);
- }
-
- }
-
- private ConcurrentAnnotatedItemMap resolvedInjectionPoints;
+ private ConcurrentCache<ResolvableAnnotatedItem<?, ?>, Set<Bean<?>>> resolvedInjectionPoints;
private Set<AnnotatedItem<?, ?>> injectionPoints;
- private Map<String, Future<Set<Bean<?>>>> resolvedNames;
+ private ConcurrentCache<String, Set<Bean<?>>> resolvedNames;
private ManagerImpl manager;
@@ -138,7 +98,8 @@
{
this.manager = manager;
this.injectionPoints = new HashSet<AnnotatedItem<?, ?>>();
- this.resolvedInjectionPoints = new ConcurrentAnnotatedItemMap();
+ this.resolvedInjectionPoints = new ConcurrentCache<ResolvableAnnotatedItem<?,?>, Set<Bean<?>>>();
+ this.resolvedNames = new ConcurrentCache<String, Set<Bean<?>>>();
}
/**
@@ -150,38 +111,14 @@
injectionPoints.addAll(elements);
}
- private void registerName(final String name)
+ private <T, S> Set<Bean<T>> registerInjectionPoint(final ResolvableAnnotatedItem<T, S> element)
{
- FutureTask<Set<Bean<?>>> task = new FutureTask<Set<Bean<?>>>(new Callable<Set<Bean<?>>>()
+ Callable<Set<Bean<T>>> callable = new Callable<Set<Bean<T>>>()
{
- public Set<Bean<?>> call() throws Exception
+ public Set<Bean<T>> call() throws Exception
{
- Set<Bean<?>> beans = new HashSet<Bean<?>>();
- for (Bean<?> bean : manager.getBeans())
- {
- if ((bean.getName() == null && name == null) || (bean.getName() != null && bean.getName().equals(name)))
- {
- beans.add(bean);
- }
- }
- return retainHighestPrecedenceBeans(beans, manager.getEnabledDeploymentTypes());
- }
-
- });
- resolvedNames.put(name, task);
-
- task.run();
- }
-
- private <T, S> void registerInjectionPoint(final AnnotatedItem<T, S> element)
- {
- FutureTask<Set<Bean<?>>> task = new FutureTask<Set<Bean<?>>>(new Callable<Set<Bean<?>>>()
- {
-
- public Set<Bean<?>> call() throws Exception
- {
- Set<Bean<?>> beans = retainHighestPrecedenceBeans(getMatchingBeans(element, manager.getBeans(), manager.getMetaDataCache()), manager.getEnabledDeploymentTypes());
+ Set<Bean<T>> beans = retainHighestPrecedenceBeans(getMatchingBeans(element, manager.getBeans(), manager.getMetaDataCache()), manager.getEnabledDeploymentTypes());
if (element.getType().isPrimitive())
{
for (Bean<?> bean : beans)
@@ -195,20 +132,8 @@
return beans;
}
- });
-
- resolvedInjectionPoints.put(new ResolvableAnnotatedItem<T, S>()
- {
-
- @Override
- public AnnotatedItem<T, S> delegate()
- {
- return element;
- }
-
- }, task);
-
- task.run();
+ };
+ return resolvedInjectionPoints.putIfAbsent(element, callable);
}
/**
@@ -217,8 +142,8 @@
*/
public void clear()
{
- resolvedInjectionPoints = new ConcurrentAnnotatedItemMap();
- resolvedNames = new HashMap<String, Future<Set<Bean<?>>>>();
+ this.resolvedInjectionPoints = new ConcurrentCache<ResolvableAnnotatedItem<?,?>, Set<Bean<?>>>();
+ resolvedNames = new ConcurrentCache<String, Set<Bean<?>>>();
}
/**
@@ -227,9 +152,17 @@
*/
public void resolveInjectionPoints()
{
- for (AnnotatedItem<?, ?> injectable : injectionPoints)
+ for (final AnnotatedItem injectable : injectionPoints)
{
- registerInjectionPoint(injectable);
+ registerInjectionPoint(new ResolvableAnnotatedItem<Object, Object>()
+ {
+
+ @Override
+ public AnnotatedItem<Object, Object> delegate()
+ {
+ return injectable;
+ }
+ });
}
}
@@ -241,7 +174,7 @@
{
Set<Bean<T>> beans = new HashSet<Bean<T>>();
- AnnotatedItem<T, S> element = new ResolvableAnnotatedItem<T, S>()
+ final ResolvableAnnotatedItem<T, S> element = new ResolvableAnnotatedItem<T, S>()
{
@Override
@@ -259,48 +192,7 @@
}
else
{
- if (!resolvedInjectionPoints.containsKey(element))
- {
- registerInjectionPoint(element);
- }
-
- boolean interupted = false;
- try
- {
- while (true)
- {
- try
- {
- return Collections.unmodifiableSet(resolvedInjectionPoints.get(element).get());
- }
- catch (ExecutionException e)
- {
- if (e.getCause() instanceof RuntimeException)
- {
- throw (RuntimeException) e.getCause();
- }
- else if (e.getCause() instanceof Error)
- {
- throw (Error) e.getCause();
- }
- else
- {
- throw new IllegalStateException(e.getCause());
- }
- }
- catch (InterruptedException e)
- {
- interupted = true;
- }
- }
- }
- finally
- {
- if (interupted)
- {
- Thread.currentThread().interrupt();
- }
- }
+ beans = registerInjectionPoint(element);
}
return Collections.unmodifiableSet(beans);
}
@@ -308,53 +200,28 @@
/**
* Get the possible beans for the given name
*/
- public Set<Bean<?>> get(String name)
+ public Set<Bean<?>> get(final String name)
{
- if (!resolvedNames.containsKey(name))
+ return resolvedNames.putIfAbsent(name, new Callable<Set<Bean<?>>>()
{
- registerName(name);
- }
- boolean interupted = false;
- try
- {
- while (true)
+ public Set<Bean<?>> call() throws Exception
{
- try
+ Set<Bean<?>> beans = new HashSet<Bean<?>>();
+ for (Bean<?> bean : manager.getBeans())
{
- return Collections.unmodifiableSet(resolvedNames.get(name).get());
- }
- catch (ExecutionException e)
- {
- if (e.getCause() instanceof RuntimeException)
+ if ((bean.getName() == null && name == null) || (bean.getName() != null && bean.getName().equals(name)))
{
- throw (RuntimeException) e.getCause();
+ beans.add(bean);
}
- else if (e.getCause() instanceof Error)
- {
- throw (Error) e.getCause();
- }
- else
- {
- throw new IllegalStateException(e.getCause());
- }
}
- catch (InterruptedException e)
- {
- interupted = true;
- }
+ return retainHighestPrecedenceBeans((Set) beans, manager.getEnabledDeploymentTypes());
}
- }
- finally
- {
- if (interupted)
- {
- Thread.currentThread().interrupt();
- }
- }
+
+ });
}
- private static Set<Bean<?>> retainHighestPrecedenceBeans(Set<Bean<?>> beans, List<Class<? extends Annotation>> enabledDeploymentTypes)
+ private static <T> Set<Bean<T>> retainHighestPrecedenceBeans(Set<Bean<T>> beans, List<Class<? extends Annotation>> enabledDeploymentTypes)
{
if (beans.size() > 0)
{
@@ -364,12 +231,12 @@
possibleDeploymentTypes.add(bean.getDeploymentType());
}
possibleDeploymentTypes.retainAll(enabledDeploymentTypes);
- Set<Bean<?>> trimmed = new HashSet<Bean<?>>();
+ Set<Bean<T>> trimmed = new HashSet<Bean<T>>();
if (possibleDeploymentTypes.size() > 0)
{
Class<? extends Annotation> highestPrecedencePossibleDeploymentType = possibleDeploymentTypes.last();
- for (Bean<?> bean : beans)
+ for (Bean<T> bean : beans)
{
if (bean.getDeploymentType().equals(highestPrecedencePossibleDeploymentType))
{
@@ -385,14 +252,14 @@
}
}
- private static Set<Bean<?>> getMatchingBeans(AnnotatedItem<?, ?> element, List<Bean<?>> beans, MetaDataCache metaDataCache)
+ private static <T> Set<Bean<T>> getMatchingBeans(AnnotatedItem<T, ?> element, List<Bean<?>> beans, MetaDataCache metaDataCache)
{
- Set<Bean<?>> resolvedBeans = new HashSet<Bean<?>>();
+ Set<Bean<T>> resolvedBeans = new HashSet<Bean<T>>();
for (Bean<?> bean : beans)
{
if (element.isAssignableFrom(bean.getTypes()) && containsAllBindingBindingTypes(element, bean.getBindingTypes(), metaDataCache))
{
- resolvedBeans.add(bean);
+ resolvedBeans.add((Bean<T>) bean);
}
}
return resolvedBeans;
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/proxy/ProxyPool.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/proxy/ProxyPool.java 2008-12-03 22:49:55 UTC (rev 397)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/proxy/ProxyPool.java 2008-12-04 13:00:28 UTC (rev 398)
@@ -20,13 +20,8 @@
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
-import java.util.Map;
import java.util.Set;
import java.util.concurrent.Callable;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.ExecutionException;
-import java.util.concurrent.Future;
-import java.util.concurrent.FutureTask;
import javassist.util.proxy.ProxyFactory;
import javassist.util.proxy.ProxyObject;
@@ -35,10 +30,8 @@
import javax.webbeans.manager.Bean;
import org.jboss.webbeans.ManagerImpl;
-import org.jboss.webbeans.util.Strings;
+import org.jboss.webbeans.util.ConcurrentCache;
-import com.google.common.collect.ForwardingMap;
-
/**
* A proxy pool for holding scope adaptors (client proxies)
*
@@ -53,43 +46,14 @@
*
* @author Nicklas Karlsson
*/
- private class Pool extends ForwardingMap<Bean<?>, Future<Object>>
- {
- Map<Bean<?>, Future<Object>> delegate;
-
- public Pool()
- {
- delegate = new ConcurrentHashMap<Bean<?>, Future<Object>>();
- }
-
- @SuppressWarnings("unchecked")
- public <T> Future<T> get(Bean<T> key)
- {
- return (Future<T>) super.get(key);
- }
-
- @Override
- protected Map<Bean<?>, Future<Object>> delegate()
- {
- return delegate;
- }
-
- @Override
- public String toString()
- {
- return Strings.mapToString("ProxyPool (bean -> proxy): ", delegate);
- }
-
- }
-
private ManagerImpl manager;
- private Pool pool;
+ private ConcurrentCache<Bean<? extends Object>, Object> pool;
public ProxyPool(ManagerImpl manager)
{
this.manager = manager;
- this.pool = new Pool();
+ this.pool = new ConcurrentCache<Bean<? extends Object>, Object>();
}
/**
@@ -182,66 +146,22 @@
* @param bean
* @return
*/
- public Object getClientProxy(final Bean<?> bean)
+ public <T> T getClientProxy(final Bean<T> bean)
{
- Future<?> clientProxy = pool.get(bean);
- if (clientProxy == null)
+ return pool.putIfAbsent(bean, new Callable<T>()
{
- FutureTask<Object> task = new FutureTask<Object>(new Callable<Object>()
+
+ public T call() throws Exception
{
-
- public Object call() throws Exception
+ int beanIndex = manager.getBeans().indexOf(bean);
+ if (beanIndex < 0)
{
- int beanIndex = manager.getBeans().indexOf(bean);
- if (beanIndex < 0)
- {
- throw new DefinitionException(bean + " is not known to the manager");
- }
- return createClientProxy(bean, beanIndex, manager);
+ throw new DefinitionException(bean + " is not known to the manager");
}
-
- });
- clientProxy = task;
- pool.put(bean, task);
- task.run();
- }
- boolean interrupted = false;
- try
- {
- while (true)
- {
- try
- {
- return clientProxy.get();
- }
- catch (InterruptedException e)
- {
- interrupted = true;
- }
- catch (ExecutionException e)
- {
- if (e.getCause() instanceof RuntimeException)
- {
- throw (RuntimeException) e.getCause();
- }
- else if (e.getCause() instanceof Error)
- {
- throw (Error) e.getCause();
- }
- else
- {
- throw new IllegalStateException(e.getCause());
- }
- };
+ return createClientProxy(bean, beanIndex, manager);
}
- }
- finally
- {
- if (interrupted)
- {
- Thread.currentThread().interrupt();
- }
- }
+
+ });
}
@Override
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/contexts/ContextMap.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/contexts/ContextMap.java 2008-12-03 22:49:55 UTC (rev 397)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/contexts/ContextMap.java 2008-12-04 13:00:28 UTC (rev 398)
@@ -18,18 +18,16 @@
package org.jboss.webbeans.contexts;
import java.lang.annotation.Annotation;
-import java.util.ArrayList;
import java.util.List;
-import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.Callable;
import java.util.concurrent.CopyOnWriteArrayList;
+import java.util.concurrent.ExecutionException;
import javax.webbeans.manager.Context;
+import org.jboss.webbeans.util.ConcurrentCache;
import org.jboss.webbeans.util.Strings;
-import com.google.common.collect.ForwardingMap;
-
/**
* A map from a scope to a list of contexts
*
@@ -37,42 +35,80 @@
* @author Pete Muir
*
*/
-public class ContextMap extends ForwardingMap<Class<? extends Annotation>, List<Context>>
+public class ContextMap extends ConcurrentCache<Class<? extends Annotation>, List<Context>>
{
- private Map<Class<? extends Annotation>, List<Context>> delegate;
- public ContextMap()
- {
- delegate = new ConcurrentHashMap<Class<? extends Annotation>, List<Context>>();
- }
-
/**
* Gets the dependent context
*
* @param scopeType The scope type to get
* @return The dependent context
*/
- public DependentContext getBuiltInContext(Class<? extends Annotation> scopeType)
+ public AbstractContext getBuiltInContext(Class<? extends Annotation> scopeType)
{
- // TODO Why can we request any scopetype and the cast it to dependent?
- return (DependentContext) get(scopeType).iterator().next();
+ boolean interrupted = false;
+ try
+ {
+ while (true)
+ {
+ try
+ {
+ return (AbstractContext) get(scopeType).get().iterator().next();
+ }
+ catch (InterruptedException e)
+ {
+ interrupted = true;
+ }
+ catch (ExecutionException e)
+ {
+ rethrow(e);
+ }
+ }
+ }
+ finally
+ {
+ if (interrupted)
+ {
+ Thread.currentThread().interrupt();
+ }
+ }
}
-
- /**
- * Returns the delegate of the forwarding map
- *
- * @return the delegate
- */
- @Override
- protected Map<Class<? extends Annotation>, List<Context>> delegate()
+
+ public List<Context> getContext(Class<? extends Annotation> scopeType)
{
- return delegate;
+ boolean interrupted = false;
+ // TODO Why can we request any scopetype and the cast it to dependent?
+ try
+ {
+ while (true)
+ {
+ try
+ {
+ return get(scopeType).get();
+ }
+ catch (InterruptedException e)
+ {
+ interrupted = true;
+ }
+ catch (ExecutionException e)
+ {
+ rethrow(e);
+ }
+ }
+ }
+ finally
+ {
+ if (interrupted)
+ {
+ Thread.currentThread().interrupt();
+ }
+ }
}
@Override
public String toString()
{
- return Strings.mapToString("ContextMap (scope type -> context list): ", delegate);
+ return Strings.mapToString("ContextMap (scope type -> context list): ", delegate());
}
/**
@@ -84,31 +120,16 @@
*/
public void add(Context context)
{
- List<Context> contexts = super.get(context.getScopeType());
- if (contexts == null)
+ List<Context> contexts = putIfAbsent(context.getScopeType(), new Callable<List<Context>>()
{
- synchronized (delegate)
+
+ public List<Context> call() throws Exception
{
- contexts = new CopyOnWriteArrayList<Context>();
- put(context.getScopeType(), contexts);
+ return new CopyOnWriteArrayList<Context>();
}
- contexts = super.get(context.getScopeType());
- }
+
+ });
contexts.add(context);
}
- /**
- * Gets a context list for a scope type
- *
- * @param scopeType The scope type
- * @return A list of contexts. An empty list is returned if there are no registered scopes of this type
- */
- public List<Context> get(Class<? extends Annotation> scopeType)
- {
- List<Context> contexts = super.get(scopeType);
- return contexts != null ? contexts : new ArrayList<Context>();
- }
-
-
-
}
\ No newline at end of file
Added: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/util/ConcurrentCache.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/util/ConcurrentCache.java (rev 0)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/util/ConcurrentCache.java 2008-12-04 13:00:28 UTC (rev 398)
@@ -0,0 +1,95 @@
+package org.jboss.webbeans.util;
+
+import java.util.Map;
+import java.util.concurrent.Callable;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.Future;
+import java.util.concurrent.FutureTask;
+
+import com.google.common.collect.ForwardingMap;
+
+public class ConcurrentCache<K, V> extends ForwardingMap<K, Future<V>>
+{
+
+ private ConcurrentMap<K, Future<V>> map;
+
+ public ConcurrentCache()
+ {
+ map = new ConcurrentHashMap<K, Future<V>>();
+ }
+
+ @SuppressWarnings("unchecked")
+ public <T extends V> Future<T> get(K key)
+ {
+ return (Future<T>) super.get(key);
+ }
+
+ public <E> E putIfAbsent(K key, Callable<E> callable)
+ {
+ Future<E> value = (Future<E>) map.get(key);
+ if (value == null)
+ {
+ FutureTask<E> task = new FutureTask<E>(callable);
+ value = task;
+ map.put(key, (Future<V>) task);
+ task.run();
+ }
+ boolean interrupted = false;
+ try
+ {
+ while (true)
+ {
+ try
+ {
+ return value.get();
+ }
+ catch (InterruptedException e)
+ {
+ interrupted = true;
+ }
+ catch (ExecutionException e)
+ {
+ rethrow(e);
+ };
+ }
+ }
+ finally
+ {
+ if (interrupted)
+ {
+ Thread.currentThread().interrupt();
+ }
+ }
+ }
+
+ @Override
+ protected Map<K, Future<V>> delegate()
+ {
+ return map;
+ }
+
+ @Override
+ public String toString()
+ {
+ return Strings.mapToString("ProxyPool (bean -> proxy): ", map);
+ }
+
+ protected void rethrow(ExecutionException e)
+ {
+ if (e.getCause() instanceof RuntimeException)
+ {
+ throw (RuntimeException) e.getCause();
+ }
+ else if (e.getCause() instanceof Error)
+ {
+ throw (Error) e.getCause();
+ }
+ else
+ {
+ throw new IllegalStateException(e.getCause());
+ }
+ }
+
+}
\ No newline at end of file
Property changes on: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/util/ConcurrentCache.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
16 years
[webbeans-commits] Webbeans SVN: r397 - in ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans: bean and 4 other directories.
by webbeans-commits@lists.jboss.org
Author: nickarls
Date: 2008-12-03 17:49:55 -0500 (Wed, 03 Dec 2008)
New Revision: 397
Modified:
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/ManagerImpl.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/MetaDataCache.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/Resolver.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/AbstractBean.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/AbstractClassBean.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/MergedStereotypes.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/ejb/EjbMetaData.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/jlr/AbstractAnnotatedItem.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/jlr/AbstractAnnotatedMember.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/jlr/AbstractAnnotatedType.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/jlr/AnnotatedAnnotationImpl.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/jlr/AnnotatedClassImpl.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/jlr/AnnotatedConstructorImpl.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/jlr/AnnotatedFieldImpl.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/jlr/AnnotatedItemImpl.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/jlr/AnnotatedMethodImpl.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/jlr/AnnotatedParameterImpl.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/BindingTypeModel.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/StereotypeModel.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/util/Strings.java
Log:
toString caching + simplifications. Output needs tuning, though
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/ManagerImpl.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/ManagerImpl.java 2008-12-03 19:26:10 UTC (rev 396)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/ManagerImpl.java 2008-12-03 22:49:55 UTC (rev 397)
@@ -59,6 +59,7 @@
import org.jboss.webbeans.introspector.AnnotatedMethod;
import org.jboss.webbeans.introspector.jlr.AnnotatedClassImpl;
import org.jboss.webbeans.util.Reflections;
+import org.jboss.webbeans.util.Strings;
/**
* Implementation of the Web Beans Manager.
@@ -656,39 +657,15 @@
public String toString()
{
StringBuffer buffer = new StringBuffer();
-
- buffer.append("Enabled deployment types: " + enabledDeploymentTypes.size() + "\n");
- int i = 0;
- for (Class<? extends Annotation> deploymentType : enabledDeploymentTypes)
- {
- buffer.append(++i + " - " + deploymentType.getName() + "\n");
- }
+ buffer.append(Strings.collectionToString("Enabled deployment types: ", getEnabledDeploymentTypes()));
buffer.append(eventManager.toString() + "\n");
buffer.append(metaDataCache.toString() + "\n");
buffer.append(resolver.toString() + "\n");
buffer.append(contextMap.toString() + "\n");
buffer.append(proxyPool.toString() + "\n");
- buffer.append("Registered beans: " + beans.size() + "\n");
- i = 0;
- for (Bean<?> bean : beans)
- {
- buffer.append(++i + " - " + bean.toString() + "\n");
- }
-
- buffer.append("Registered decorators: " + decorators.size() + "\n");
- i = 0;
- for (Decorator decorator : decorators)
- {
- buffer.append(++i + " - " + decorator.toString() + "\n");
- }
-
- buffer.append("Registered interceptors: " + interceptors.size() + "\n");
- i = 0;
- for (Interceptor interceptor : interceptors)
- {
- buffer.append(++i + " - " + interceptor.toString() + "\n");
- }
-
+ buffer.append(Strings.collectionToString("Registered beans: ", getBeans()));
+ buffer.append(Strings.collectionToString("Registered decorators: ", decorators));
+ buffer.append(Strings.collectionToString("Registered interceptors: ", interceptors));
return buffer.toString();
}
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/MetaDataCache.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/MetaDataCache.java 2008-12-03 19:26:10 UTC (rev 396)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/MetaDataCache.java 2008-12-03 22:49:55 UTC (rev 397)
@@ -198,12 +198,7 @@
buffer.append(bindingTypes.toString() + "\n");
buffer.append(ejbMetaDataMap.toString() + "\n");
buffer.append(scopes.toString() + "\n");
- buffer.append("Stereotypes: " + stereotypes.size() + "\n");
- int i = 0;
- for (Entry<Class<? extends Annotation>, StereotypeModel<?>> entry : stereotypes.entrySet())
- {
- buffer.append(++i + " - " + entry.getKey().getName() + ": " + entry.getValue().toString() + "\n");
- }
+ buffer.append(Strings.mapToString("Stereotypes: ", stereotypes));
buffer.append("====================\n");
return buffer.toString();
}
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/Resolver.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/Resolver.java 2008-12-03 19:26:10 UTC (rev 396)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/Resolver.java 2008-12-03 22:49:55 UTC (rev 397)
@@ -27,7 +27,6 @@
import java.util.Set;
import java.util.SortedSet;
import java.util.TreeSet;
-import java.util.Map.Entry;
import java.util.concurrent.Callable;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ExecutionException;
@@ -95,7 +94,6 @@
}
-
/**
* Type safe map for caching annotation metadata
*/
@@ -116,16 +114,16 @@
}
@Override
- protected Map<AnnotatedItem<?, ?>, Future > delegate()
+ protected Map<AnnotatedItem<?, ?>, Future> delegate()
{
return delegate;
}
-
+
@Override
public String toString()
{
return Strings.mapToString("AnnotatedItemMap (annotated item -> bean set): ", delegate);
- }
+ }
}
@@ -151,7 +149,7 @@
{
injectionPoints.addAll(elements);
}
-
+
private void registerName(final String name)
{
FutureTask<Set<Bean<?>>> task = new FutureTask<Set<Bean<?>>>(new Callable<Set<Bean<?>>>()
@@ -169,13 +167,13 @@
}
return retainHighestPrecedenceBeans(beans, manager.getEnabledDeploymentTypes());
}
-
+
});
resolvedNames.put(name, task);
-
+
task.run();
}
-
+
private <T, S> void registerInjectionPoint(final AnnotatedItem<T, S> element)
{
FutureTask<Set<Bean<?>>> task = new FutureTask<Set<Bean<?>>>(new Callable<Set<Bean<?>>>()
@@ -196,9 +194,9 @@
}
return beans;
}
-
+
});
-
+
resolvedInjectionPoints.put(new ResolvableAnnotatedItem<T, S>()
{
@@ -209,7 +207,7 @@
}
}, task);
-
+
task.run();
}
@@ -265,7 +263,7 @@
{
registerInjectionPoint(element);
}
-
+
boolean interupted = false;
try
{
@@ -316,7 +314,7 @@
{
registerName(name);
}
-
+
boolean interupted = false;
try
{
@@ -446,18 +444,8 @@
StringBuffer buffer = new StringBuffer();
buffer.append("Resolver\n");
buffer.append(resolvedInjectionPoints.toString() + "\n");
- buffer.append("Injection points: " + injectionPoints.size() + "\n");
- int i = 0;
- for (AnnotatedItem<?, ?> injectionPoint : injectionPoints)
- {
- buffer.append(++i + " - " + injectionPoint.toString() + "\n");
- }
- buffer.append("Resolved names: " + resolvedNames.size() + "\n");
- i = 0;
- for (Entry<String, Future<Set<Bean<?>>>> entry : resolvedNames.entrySet())
- {
- buffer.append(++i + " - " + entry + ": " + entry.getValue().toString() + "\n");
- }
+ buffer.append(Strings.collectionToString("Injection points: ", injectionPoints));
+ buffer.append(Strings.mapToString("Resolved names: ", resolvedNames));
return buffer.toString();
}
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/AbstractBean.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/AbstractBean.java 2008-12-03 19:26:10 UTC (rev 396)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/AbstractBean.java 2008-12-03 22:49:55 UTC (rev 397)
@@ -48,6 +48,7 @@
import org.jboss.webbeans.log.LogProvider;
import org.jboss.webbeans.log.Logging;
import org.jboss.webbeans.util.Reflections;
+import org.jboss.webbeans.util.Strings;
/**
* An abstract bean representation common for all beans
@@ -66,9 +67,9 @@
/**
* Helper class for getting deployment type
*
- * Loops through the enabled deployment types (backwards) and returns the first one
- * present in the possible deployments type, resulting in the deployment type of
- * highest priority
+ * Loops through the enabled deployment types (backwards) and returns the
+ * first one present in the possible deployments type, resulting in the
+ * deployment type of highest priority
*
* @param enabledDeploymentTypes The currently enabled deployment types
* @param possibleDeploymentTypes The possible deployment types
@@ -198,7 +199,7 @@
Set<Annotation> xmlDeploymentTypes = null;
if (xmlDeploymentTypes.size() > 1)
{
- throw new DefinitionException ("At most one deployment type may be specified (" + xmlDeploymentTypes + " are specified)");
+ throw new DefinitionException("At most one deployment type may be specified (" + xmlDeploymentTypes + " are specified)");
}
if (xmlDeploymentTypes.size() == 1)
@@ -366,7 +367,7 @@
}
else if (getMergedStereotypes().getPossibleScopeTypes().size() > 1)
{
- throw new DefinitionException ("All stereotypes must specify the same scope OR a scope must be specified on the bean");
+ throw new DefinitionException("All stereotypes must specify the same scope OR a scope must be specified on the bean");
}
this.scopeType = Dependent.class;
log.trace("Using default @Dependent scope");
@@ -384,7 +385,7 @@
{
if (deploymentType == null)
{
- throw new DefinitionException ("type: " + getType() + " must specify a deployment type");
+ throw new DefinitionException("type: " + getType() + " must specify a deployment type");
}
else if (deploymentType.equals(Standard.class) && !STANDARD_WEB_BEAN_CLASSES.contains(getAnnotatedItem().getType()))
{
@@ -650,25 +651,10 @@
buffer.append("Primitive : " + primitive + "\n");
buffer.append("Declared bean type: " + (declaredBeanType == null ? "null" : declaredBeanType.toString()) + "\n");
buffer.append("Remove method: " + (removeMethod == null ? "null" : removeMethod.toString()) + "\n");
- buffer.append("Binding types: " + bindingTypes.size() + "\n");
- int i = 0;
- for (Annotation bindingType : bindingTypes)
- {
- buffer.append(++i + " - " + bindingType.toString() + "\n");
- }
- buffer.append("API types: " + apiTypes.size() + "\n");
- i = 0;
- for (Class<?> apiType : apiTypes)
- {
- buffer.append(++i + " - " + apiType.getName() + "\n");
- }
+ buffer.append(Strings.collectionToString("Binding types: ", getBindingTypes()));
+ buffer.append(Strings.collectionToString("API types: ", getTypes()));
+ buffer.append(Strings.collectionToString("Injection points: ", getInjectionPoints()));
buffer.append(mergedStereotypes.toString() + "\n");
- buffer.append("Injection points: " + injectionPoints.size() + "\n");
- i = 0;
- for (AnnotatedItem<?, ?> injectionPoint : injectionPoints)
- {
- buffer.append(++i + " - " + injectionPoint.toString() + "\n");
- }
return buffer.toString();
}
}
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/AbstractClassBean.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/AbstractClassBean.java 2008-12-03 19:26:10 UTC (rev 396)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/AbstractClassBean.java 2008-12-03 22:49:55 UTC (rev 397)
@@ -278,18 +278,9 @@
buffer.append("AbstractClassBean:\n");
buffer.append(super.toString() + "\n");
buffer.append("Annotated item: " + annotatedItem.toString() + "\n");
- buffer.append("Initializer methods: " + initializerMethods.size() + "\n");
- int i = 0;
- for (AnnotatedMethod<?> initializerMethod : initializerMethods)
- {
- buffer.append(++i + " - " + initializerMethod.toString() + "\n");
- }
- i = 0;
- buffer.append("Injectable fields " + injectableFields.size() + "\n");
- for (AnnotatedField<?> injectableField : injectableFields)
- {
- buffer.append(++i + " - " + injectableField.toString() + "\n");
- }
+ buffer.append(Strings.collectionToString("Initializer methods: ", getInitializerMethods()));
+ buffer.append(Strings.collectionToString("Injectable fields: ", getInjectableFields()));
+ buffer.append(Strings.collectionToString("Producer methods: ", getProducerMethods()));
return buffer.toString();
}
}
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/MergedStereotypes.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/MergedStereotypes.java 2008-12-03 19:26:10 UTC (rev 396)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/MergedStereotypes.java 2008-12-03 22:49:55 UTC (rev 397)
@@ -25,6 +25,7 @@
import org.jboss.webbeans.ManagerImpl;
import org.jboss.webbeans.introspector.jlr.AbstractAnnotatedItem.AnnotationMap;
import org.jboss.webbeans.model.StereotypeModel;
+import org.jboss.webbeans.util.Strings;
/**
* Meta model for the merged stereotype for a bean
@@ -163,30 +164,10 @@
StringBuffer buffer = new StringBuffer();
buffer.append("Merged stereotypes:\n");
buffer.append("Bean name defaulted: " + beanNameDefaulted + "\n");
- buffer.append("Possible deployment types: " + possibleDeploymentTypes.size() + "\n");
- int i = 0;
- for (Entry<Class<? extends Annotation>, Annotation> entry : possibleDeploymentTypes.entrySet())
- {
- buffer.append(++i + " - " + entry.getKey().getName() + ": " + entry.getValue().toString() + "\n");
- }
- buffer.append("Possible scope types: " + possibleScopeTypes.size() + "\n");
- i = 0;
- for (Annotation scopeType : possibleScopeTypes)
- {
- buffer.append(++i + " - " + scopeType.toString());
- }
- buffer.append("Required types: " + requiredTypes.size() + "\n");
- i = 0;
- for (Class<?> requiredType : requiredTypes)
- {
- buffer.append(++i + " - " + requiredType.getName() + "\n");
- }
- buffer.append("Supported scopes: " + supportedScopes.size() + "\n");
- i = 0;
- for (Class<?> supportedScope : supportedScopes)
- {
- buffer.append(++i + " - " + supportedScope.getName() + "\n");
- }
+ buffer.append("Possible deployment types: " + getPossibleDeploymentTypes().toString());
+ buffer.append(Strings.collectionToString("Possible scope types: ", getPossibleScopeTypes()));
+ buffer.append(Strings.collectionToString("Required types: ", getRequiredTypes()));
+ buffer.append(Strings.collectionToString("Supported scopes: ", getSupportedScopes()));
return buffer.toString();
}
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/ejb/EjbMetaData.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/ejb/EjbMetaData.java 2008-12-03 19:26:10 UTC (rev 396)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/ejb/EjbMetaData.java 2008-12-03 22:49:55 UTC (rev 397)
@@ -36,6 +36,7 @@
import org.jboss.webbeans.introspector.AnnotatedClass;
import org.jboss.webbeans.introspector.AnnotatedMethod;
import org.jboss.webbeans.introspector.jlr.AnnotatedClassImpl;
+import org.jboss.webbeans.util.Strings;
/**
* EJB metadata
@@ -265,24 +266,9 @@
buffer.append("EJB link JNDI name " + ejbLinkJndiName + "\n");
buffer.append("Default JNDI name: " + defaultJndiName + "\n");
buffer.append("Type: " + type.toString() + "\n");
- buffer.append("Desctructor methods: " + destructorMethods.size() + "\n");
- int i = 0;
- for (AnnotatedMethod<?> method : destructorMethods)
- {
- buffer.append(++i + " - " + method.toString() + "\n");
- }
- i = 0;
- buffer.append("Remove methods: " + removeMethods.size() + "\n");
- for (AnnotatedMethod<?> method : removeMethods)
- {
- buffer.append(++i + " - " + method.toString() + "\n");
- }
- i = 0;
- buffer.append("No-args remove methods: " + noArgsRemoveMethods.size() + "\n");
- for (AnnotatedMethod<?> method : noArgsRemoveMethods)
- {
- buffer.append(++i + " - " + method.toString() + "\n");
- }
+ buffer.append(Strings.collectionToString("Desctructor methods: ", getDestructorMethods()));
+ buffer.append(Strings.collectionToString("Remove methods: ", getRemoveMethods()));
+ buffer.append(Strings.collectionToString("No-args remove methods: ", getNoArgsRemoveMethods()));
return buffer.toString();
}
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/jlr/AbstractAnnotatedItem.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/jlr/AbstractAnnotatedItem.java 2008-12-03 19:26:10 UTC (rev 396)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/jlr/AbstractAnnotatedItem.java 2008-12-03 22:49:55 UTC (rev 397)
@@ -161,10 +161,14 @@
private static final Annotation[] DEFAULT_BINDING_ARRAY = { new CurrentAnnotationLiteral() };
// The set of default binding types
private static final Set<Annotation> DEFAULT_BINDING = new HashSet<Annotation>(Arrays.asList(DEFAULT_BINDING_ARRAY));
-
+
// The set of meta-annotations to map
+ @SuppressWarnings("unchecked")
private static final Set<Class<? extends Annotation>> MAPPED_METAANNOTATIONS = new HashSet<Class<? extends Annotation>>(Arrays.asList(BindingType.class, DeploymentType.class, Stereotype.class, ScopeType.class));
-
+
+ // Cached string representation
+ private String toString;
+
/**
* Static helper method for building annotation map from an annotated element
*
@@ -191,7 +195,7 @@
}
return annotationMap;
}
-
+
/**
* Static helper method for getting the current parameter values from a list
* of annotated parameters.
@@ -294,7 +298,7 @@
*/
public Annotation[] getMetaAnnotationsAsArray(Class<? extends Annotation> metaAnnotationType)
{
- return getMetaAnnotations(metaAnnotationType).toArray(new Annotation[0]);
+ return getMetaAnnotations(metaAnnotationType).toArray(new Annotation[0]);
}
/**
@@ -416,19 +420,17 @@
@Override
public String toString()
{
+ if (toString != null)
+ {
+ return toString;
+ }
StringBuffer buffer = new StringBuffer();
- // buffer.append("AbstractAnnotatedItem:\n");
- // buffer.append("Annotations: " + getAnnotations().size() + "\n");
- // int i = 0;
- // for (Annotation annotation : getAnnotations())
- // {
- // buffer.append(++i + " - " + annotation.toString() + "\n");
- // }
- // buffer.append(annotationMap == null ? "" : (annotationMap.toString() +
- // "\n"));
- // buffer.append(metaAnnotationMap == null ? "" :
- // (metaAnnotationMap.toString()) + "\n");
- return buffer.toString();
+ buffer.append("AbstractAnnotatedItem:\n");
+ buffer.append(Strings.collectionToString("Annotations: ", getAnnotations()));
+ buffer.append(annotationMap == null ? "" : (annotationMap.toString() + "\n"));
+ buffer.append(metaAnnotationMap == null ? "" : (metaAnnotationMap.toString()) + "\n");
+ toString = buffer.toString();
+ return toString;
}
/**
@@ -505,7 +507,7 @@
return true;
}
}
-
+
protected abstract S getDelegate();
}
\ No newline at end of file
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/jlr/AbstractAnnotatedMember.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/jlr/AbstractAnnotatedMember.java 2008-12-03 19:26:10 UTC (rev 396)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/jlr/AbstractAnnotatedMember.java 2008-12-03 22:49:55 UTC (rev 397)
@@ -91,6 +91,9 @@
// The name of the member
private final String name;
+ // Cached string representation
+ private String toString;
+
/**
* Constructor
*
@@ -156,13 +159,18 @@
*/
public String toString()
{
+ if (toString != null)
+ {
+ return toString;
+ }
StringBuffer buffer = new StringBuffer();
- // buffer.append("AbstractAnnotatedMember:\n");
- // buffer.append(super.toString() + "\n");
- // buffer.append("Final: " + isFinal() + "\n");
- // buffer.append("Static: " + isStatic() + "\n");
- // buffer.append("Name: " + getName() + "\n");
- return buffer.toString();
+ buffer.append("AbstractAnnotatedMember:\n");
+ buffer.append(super.toString() + "\n");
+ buffer.append("Final: " + isFinal() + "\n");
+ buffer.append("Static: " + isStatic() + "\n");
+ buffer.append("Name: " + getName() + "\n");
+ toString = buffer.toString();
+ return toString;
}
}
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/jlr/AbstractAnnotatedType.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/jlr/AbstractAnnotatedType.java 2008-12-03 19:26:10 UTC (rev 396)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/jlr/AbstractAnnotatedType.java 2008-12-03 22:49:55 UTC (rev 397)
@@ -23,7 +23,7 @@
/**
* Represents an abstract annotated type
*
- * This class is immutable, and therefore threadsage
+ * This class is immutable, and therefore threadsafe
*
* @author Pete Muir
*
@@ -33,7 +33,11 @@
{
// The superclass abstraction of the type
private final AnnotatedClass<Object> superclass;
+ // The name of the type
private final String name;
+
+ // Cached string representation
+ private String toString;
/**
* Constructor
@@ -96,7 +100,6 @@
*
* @return The superclass abstraction
*/
- @SuppressWarnings("unchecked")
public AnnotatedClass<Object> getSuperclass()
{
return superclass;
@@ -109,14 +112,19 @@
*/
public String toString()
{
+ if (toString != null)
+ {
+ return toString;
+ }
StringBuffer buffer = new StringBuffer();
-// buffer.append("AbstractAnnotatedType:\n");
-// buffer.append(super.toString() + "\n");
-// buffer.append("Superclass: " + (superclass == null ? "" : superclass.toString()) + "\n");
-// buffer.append("Name: " + getName() + "\n");
-// buffer.append("Final: " + isFinal() + "\n");
-// buffer.append("Static: " + isStatic() + "\n");
- return buffer.toString();
+ buffer.append("AbstractAnnotatedType:\n");
+ buffer.append(super.toString() + "\n");
+ buffer.append("Superclass: " + (superclass == null ? "" : superclass.toString()) + "\n");
+ buffer.append("Name: " + getName() + "\n");
+ buffer.append("Final: " + isFinal() + "\n");
+ buffer.append("Static: " + isStatic() + "\n");
+ toString = buffer.toString();
+ return toString;
}
}
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/jlr/AnnotatedAnnotationImpl.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/jlr/AnnotatedAnnotationImpl.java 2008-12-03 19:26:10 UTC (rev 396)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/jlr/AnnotatedAnnotationImpl.java 2008-12-03 22:49:55 UTC (rev 397)
@@ -94,6 +94,9 @@
// The set of abstracted members
private final Set<AnnotatedMethod<?>> members;
+ // Cached string representation
+ private String toString;
+
/**
* Constructor
*
@@ -177,20 +180,18 @@
*/
public String toString()
{
+ if (toString != null)
+ {
+ return toString;
+ }
StringBuffer buffer = new StringBuffer();
- // buffer.append("AnnotatedConstructorImpl:\n");
- // buffer.append(super.toString() + "\n");
- // buffer.append("Class: " + clazz.toString() + "\n");
- //
- // buffer.append("Members: " + getMembers().size() + "\n");
- // int i = 0;
- // for (AnnotatedMethod<?> member : getMembers())
- // {
- // buffer.append(++i + " - " + member.toString());
- // }
- // buffer.append(annotatedMembers == null ? "" :
- // (annotatedMembers.toString() + "\n"));
- return buffer.toString();
+ buffer.append("AnnotatedConstructorImpl:\n");
+ buffer.append(super.toString() + "\n");
+ buffer.append("Class: " + clazz.toString() + "\n");
+ buffer.append(Strings.collectionToString("Members: ", getMembers()));
+ buffer.append(annotatedMembers == null ? "" : (annotatedMembers.toString() + "\n"));
+ toString = buffer.toString();
+ return toString;
}
protected Class<T> getDelegate()
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/jlr/AnnotatedClassImpl.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/jlr/AnnotatedClassImpl.java 2008-12-03 19:26:10 UTC (rev 396)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/jlr/AnnotatedClassImpl.java 2008-12-03 22:49:55 UTC (rev 397)
@@ -42,7 +42,7 @@
/**
* Represents an annotated class
*
- * This class is immutable, and thus threadsafe
+ * This class is immutable, and therefore threadsafe
*
* @author Pete Muir
*
@@ -204,14 +204,7 @@
@Override
public String toString()
{
- StringBuffer buffer = new StringBuffer();
- buffer.append("Annotation type -> constructor by arguments mappings: " + super.size() + "\n");
- int i = 0;
- for (Entry<List<Class<?>>, AnnotatedConstructor<T>> entry : delegate.entrySet())
- {
- buffer.append(++i + " - " + entry.getKey().toString() + ": " + entry.getValue().toString() + "\n");
- }
- return buffer.toString();
+ return Strings.mapToString("Annotation type -> constructor by arguments mappings: ", delegate);
}
}
@@ -239,6 +232,9 @@
// The map from class list to abstracted constructor
private final ConstructorsByArgumentMap constructorsByArgumentMap;
+ // Cached string representation
+ private String toString;
+
/**
* Constructor
*
@@ -249,6 +245,7 @@
* @param type The type of the class
* @param annotations The array of annotations on the class
*/
+ @SuppressWarnings("unchecked")
public AnnotatedClassImpl(Class<T> rawType, Type type, Annotation[] annotations)
{
super(buildAnnotationMap(annotations), rawType);
@@ -261,7 +258,7 @@
{
actualTypeArguments = new Type[0];
}
-
+
this.fields = new HashSet<AnnotatedField<Object>>();
this.annotatedFields = new AnnotatedFieldMap();
this.metaAnnotatedFields = new AnnotatedFieldMap();
@@ -273,7 +270,7 @@
{
field.setAccessible(true);
}
- AnnotatedField<Object> annotatedField = new AnnotatedFieldImpl<Object>(field, this);
+ AnnotatedField<Object> annotatedField = new AnnotatedFieldImpl<Object>(field, this);
this.fields.add(annotatedField);
for (Annotation annotation : annotatedField.getAnnotations())
{
@@ -283,10 +280,10 @@
this.metaAnnotatedFields.put(metaAnnotation.annotationType(), annotatedField);
}
}
-
+
}
}
-
+
this.constructors = new HashSet<AnnotatedConstructor<T>>();
this.constructorsByArgumentMap = new ConstructorsByArgumentMap();
this.annotatedConstructors = new AnnotatedConstructorMap();
@@ -299,7 +296,7 @@
}
this.constructors.add(annotatedConstructor);
this.constructorsByArgumentMap.put(Arrays.asList(constructor.getParameterTypes()), annotatedConstructor);
-
+
for (Annotation annotation : annotatedConstructor.getAnnotations())
{
if (!annotatedConstructors.containsKey(annotation.annotationType()))
@@ -309,7 +306,7 @@
annotatedConstructors.get(annotation.annotationType()).add(annotatedConstructor);
}
}
-
+
this.methods = new HashSet<AnnotatedMethod<Object>>();
this.annotatedMethods = new AnnotatedMethodMap();
for (Class<?> c = clazz; c != Object.class && c != null; c = c.getSuperclass())
@@ -320,7 +317,7 @@
{
method.setAccessible(true);
}
-
+
AnnotatedMethod<Object> annotatedMethod = new AnnotatedMethodImpl<Object>(method, this);
this.methods.add(annotatedMethod);
for (Annotation annotation : annotatedMethod.getAnnotations())
@@ -496,46 +493,25 @@
*/
public String toString()
{
+ if (toString != null)
+ {
+ return toString;
+ }
StringBuffer buffer = new StringBuffer();
- // buffer.append("AnnotatedConstructorImpl:\n");
- // buffer.append(super.toString() + "\n");
- // buffer.append("Actual type arguments: " + actualTypeArguments.length +
- // "\n");
- // int i = 0;
- // for (Type actualTypeArgument : actualTypeArguments)
- // {
- // buffer.append(++i + " - " + actualTypeArgument.toString());
- // }
- // buffer.append("Class: " + clazz.toString() + "\n");
- // buffer.append("Fields: " + getFields().size() + "\n");
- // i = 0;
- // for (AnnotatedField<Object> field : getFields())
- // {
- // buffer.append(++i + " - " + field.toString());
- // }
- // buffer.append("Methods: " + methods.size() + "\n");
- // i = 0;
- // for (AnnotatedMethod<Object> method : methods)
- // {
- // buffer.append(++i + " - " + method.toString());
- // }
- // buffer.append("Constructors: " + methods.size() + "\n");
- // i = 0;
- // for (AnnotatedConstructor<T> constructor : getConstructors())
- // {
- // buffer.append(++i + " - " + constructor.toString());
- // }
- // buffer.append(annotatedConstructors == null ? "" :
- // (annotatedConstructors.toString() + "\n"));
- // buffer.append(annotatedFields == null ? "" :
- // (annotatedFields.toString() + "\n"));
- // buffer.append(annotatedMethods == null ? "" :
- // (annotatedMethods.toString() + "\n"));
- // buffer.append(constructorsByArgumentMap == null ? "" :
- // (constructorsByArgumentMap.toString() + "\n"));
- // buffer.append(metaAnnotatedFields == null ? "" :
- // (metaAnnotatedFields.toString() + "\n"));
- return buffer.toString();
+ buffer.append("AnnotatedConstructorImpl:\n");
+ buffer.append(super.toString() + "\n");
+ buffer.append(Strings.collectionToString("Actual type arguments: ", Arrays.asList(getActualTypeArguments())));
+ buffer.append("Class: " + clazz.toString() + "\n");
+ buffer.append(Strings.collectionToString("Fields: ", getFields()));
+ buffer.append(Strings.collectionToString("Methods: ", methods));
+ buffer.append(Strings.collectionToString("Constructors: ", getConstructors()));
+ buffer.append(annotatedConstructors == null ? "" : (annotatedConstructors.toString() + "\n"));
+ buffer.append(annotatedFields == null ? "" : (annotatedFields.toString() + "\n"));
+ buffer.append(annotatedMethods == null ? "" : (annotatedMethods.toString() + "\n"));
+ buffer.append(constructorsByArgumentMap == null ? "" : (constructorsByArgumentMap.toString() + "\n"));
+ buffer.append(metaAnnotatedFields == null ? "" : (metaAnnotatedFields.toString() + "\n"));
+ toString = buffer.toString();
+ return toString;
}
}
\ No newline at end of file
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/jlr/AnnotatedConstructorImpl.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/jlr/AnnotatedConstructorImpl.java 2008-12-03 19:26:10 UTC (rev 396)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/jlr/AnnotatedConstructorImpl.java 2008-12-03 22:49:55 UTC (rev 397)
@@ -22,6 +22,7 @@
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Type;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Collections;
import java.util.List;
@@ -31,10 +32,13 @@
import org.jboss.webbeans.introspector.AnnotatedConstructor;
import org.jboss.webbeans.introspector.AnnotatedParameter;
import org.jboss.webbeans.introspector.AnnotatedType;
+import org.jboss.webbeans.util.Strings;
/**
* Represents an annotated constructor
*
+ * This class is immutable, and therefore threadsafe
+ *
* @author Pete Muir
*
* @param <T>
@@ -54,6 +58,9 @@
// The declaring class abstraction
private final AnnotatedType<T> declaringClass;
+ // Cached string representation
+ private String toString;
+
/**
* Constructor
*
@@ -62,12 +69,13 @@
* @param constructor The constructor method
* @param declaringClass The declaring class
*/
+ @SuppressWarnings("unchecked")
public AnnotatedConstructorImpl(Constructor<T> constructor, AnnotatedType<T> declaringClass)
{
super(buildAnnotationMap(constructor), constructor);
this.constructor = constructor;
this.declaringClass = declaringClass;
-
+
this.parameters = new ArrayList<AnnotatedParameter<Object>>();
annotatedParameters = new AnnotatedParameterMap();
for (int i = 0; i < constructor.getParameterTypes().length; i++)
@@ -77,7 +85,7 @@
Class<? extends Object> clazz = constructor.getParameterTypes()[i];
AnnotatedParameter<Object> parameter = new AnnotatedParameterImpl<Object>(constructor.getParameterAnnotations()[i], (Class<Object>) clazz);
parameters.add(parameter);
-
+
for (Annotation annotation : parameter.getAnnotations())
{
annotatedParameters.put(annotation.annotationType(), parameter);
@@ -88,7 +96,7 @@
Class<? extends Object> clazz = constructor.getParameterTypes()[i];
AnnotatedParameter<Object> parameter = new AnnotatedParameterImpl<Object>(new Annotation[0], (Class<Object>) clazz);
parameters.add(parameter);
-
+
for (Annotation annotation : parameter.getAnnotations())
{
annotatedParameters.put(annotation.annotationType(), parameter);
@@ -264,28 +272,22 @@
*/
public String toString()
{
+ if (toString != null)
+ {
+ return toString;
+ }
StringBuffer buffer = new StringBuffer();
- // buffer.append("AnnotatedConstructorImpl:\n");
- // buffer.append(super.toString() + "\n");
- // buffer.append("Actual type arguments: " + actualTypeArguments.length +
- // "\n");
- // int i = 0;
- // for (Type actualTypeArgument : actualTypeArguments)
- // {
- // buffer.append(++i + " - " + actualTypeArgument.toString());
- // }
- // buffer.append("Declaring class:\n");
- // buffer.append(declaringClass.toString() + "\n");
- // buffer.append("Constructor:\n");
- // buffer.append(constructor.toString() + "\n");
- // buffer.append("Parameters: " + getParameters().size() + "\n");
- // i = 0;
- // for (AnnotatedParameter<?> parameter : getParameters())
- // {
- // buffer.append(++i + " - " + parameter.toString());
- // }
- // buffer.append(annotatedParameters.toString() + "\n");
- return buffer.toString();
+ buffer.append("AnnotatedConstructorImpl:\n");
+ buffer.append(super.toString() + "\n");
+ buffer.append(Strings.collectionToString("Actual type arguments: ", Arrays.asList(getActualTypeArguments())));
+ buffer.append("Declaring class:\n");
+ buffer.append(declaringClass.getName() + "[ " + declaringClass.getType() + "]" + "\n");
+ buffer.append("Constructor:\n");
+ buffer.append(constructor.toString() + "\n");
+ buffer.append(Strings.collectionToString("Parameters: ", getParameters()));
+ buffer.append(annotatedParameters.toString() + "\n");
+ toString = buffer.toString();
+ return toString;
}
}
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/jlr/AnnotatedFieldImpl.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/jlr/AnnotatedFieldImpl.java 2008-12-03 19:26:10 UTC (rev 396)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/jlr/AnnotatedFieldImpl.java 2008-12-03 22:49:55 UTC (rev 397)
@@ -20,16 +20,18 @@
import java.lang.reflect.Field;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
+import java.util.Arrays;
import org.jboss.webbeans.ManagerImpl;
import org.jboss.webbeans.introspector.AnnotatedField;
import org.jboss.webbeans.introspector.AnnotatedType;
import org.jboss.webbeans.util.Reflections;
+import org.jboss.webbeans.util.Strings;
/**
* Represents an annotated field
*
- * This class is immutable, and thus threadsafe
+ * This class is immutable, and therefore threadsafe
*
* @author Pete Muir
*
@@ -44,6 +46,9 @@
// The abstraction of the declaring class
private final AnnotatedType<?> declaringClass;
+ // Cached string representation
+ private String toString;
+
/**
* Constructor
*
@@ -113,7 +118,8 @@
* @param instance The instance to inject into
* @param manager The Web Beans manager
*
- * @see org.jboss.webbeans.introspector.AnnotatedField#inject(Object, ManagerImpl)
+ * @see org.jboss.webbeans.introspector.AnnotatedField#inject(Object,
+ * ManagerImpl)
*/
public void inject(Object instance, ManagerImpl manager)
{
@@ -151,19 +157,19 @@
*/
public String toString()
{
+ if (toString != null)
+ {
+ return toString;
+ }
StringBuffer buffer = new StringBuffer();
-// buffer.append("AnnotatedFieldImpl:\n");
-// buffer.append(super.toString() + "\n");
-// buffer.append("Actual type arguments: " + actualTypeArguments.length + "\n");
-// int i = 0;
-// for (Type actualTypeArgument : actualTypeArguments)
-// {
-// buffer.append(++i + " - " + actualTypeArgument.toString());
-// }
-// buffer.append("Declaring class:\n");
-// buffer.append(declaringClass.toString() + "\n");
-// buffer.append("Field: " + field + "\n");
- return buffer.toString();
+ buffer.append("AnnotatedFieldImpl:\n");
+ buffer.append(super.toString() + "\n");
+ buffer.append(Strings.collectionToString("Actual type arguments: ", Arrays.asList(getActualTypeArguments())));
+ buffer.append("Declaring class:\n");
+ buffer.append(declaringClass.getName() + "[ " + declaringClass.getType() + "]" + "\n");
+ buffer.append("Field: " + field + "\n");
+ toString = buffer.toString();
+ return toString;
}
}
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/jlr/AnnotatedItemImpl.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/jlr/AnnotatedItemImpl.java 2008-12-03 19:26:10 UTC (rev 396)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/jlr/AnnotatedItemImpl.java 2008-12-03 22:49:55 UTC (rev 397)
@@ -19,11 +19,14 @@
import java.lang.annotation.Annotation;
import java.lang.reflect.Type;
+import java.util.Arrays;
+import org.jboss.webbeans.util.Strings;
+
/**
* Represents an annotated item
*
- * This class is immutable, and thus threadsafe
+ * This class is immutable, and therefore threadsafe
*
* @author Pete Muir
*
@@ -39,6 +42,9 @@
// The actual annotations
private final Annotation[] actualAnnotations;
+ // Cached string representation
+ private String toString;
+
/**
* Constructor
*
@@ -143,22 +149,17 @@
*/
public String toString()
{
+ if (toString != null)
+ {
+ return toString;
+ }
StringBuffer buffer = new StringBuffer();
-// buffer.append("AnnotatedItemImpl:\n");
-// buffer.append(super.toString() + "\n");
-// buffer.append("Actual type arguments: " + actualTypeArguments.length + "\n");
-// int i = 0;
-// for (Type actualTypeArgument : actualTypeArguments)
-// {
-// buffer.append(++i + " - " + actualTypeArgument.toString());
-// }
-// buffer.append("Actual annotations: " + actualAnnotations.length + "\n");
-// i = 0;
-// for (Annotation actualAnnotation : actualAnnotations)
-// {
-// buffer.append(++i + " - " + actualAnnotation.toString());
-// }
- return buffer.toString();
+ buffer.append("AnnotatedItemImpl:\n");
+ buffer.append(super.toString() + "\n");
+ buffer.append(Strings.collectionToString("Actual type arguments: ", Arrays.asList(getActualTypeArguments())));
+ buffer.append(Strings.collectionToString("Actual annotations: ", Arrays.asList(getActualAnnotations())));
+ toString = buffer.toString();
+ return toString;
}
}
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/jlr/AnnotatedMethodImpl.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/jlr/AnnotatedMethodImpl.java 2008-12-03 19:26:10 UTC (rev 396)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/jlr/AnnotatedMethodImpl.java 2008-12-03 22:49:55 UTC (rev 397)
@@ -22,6 +22,7 @@
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Collections;
import java.util.List;
@@ -30,11 +31,12 @@
import org.jboss.webbeans.introspector.AnnotatedParameter;
import org.jboss.webbeans.introspector.AnnotatedType;
import org.jboss.webbeans.util.Reflections;
+import org.jboss.webbeans.util.Strings;
/**
* Represents an annotated method
*
- * This class is immutable and thus threadsafe
+ * This class is immutable and therefore threadsafe
*
* @author Pete Muir
*
@@ -59,6 +61,9 @@
// The abstracted declaring class
private final AnnotatedType<?> declaringClass;
+ // Cached string representation
+ private String toString;
+
/**
* Constructor
*
@@ -68,6 +73,7 @@
* @param method The underlying method
* @param declaringClass The declaring class abstraction
*/
+ @SuppressWarnings("unchecked")
public AnnotatedMethodImpl(Method method, AnnotatedType<?> declaringClass)
{
super(buildAnnotationMap(method), method);
@@ -81,7 +87,7 @@
{
this.actualTypeArguments = new Type[0];
}
-
+
this.parameters = new ArrayList<AnnotatedParameter<Object>>();
this.annotatedParameters = new AnnotatedParameterMap();
for (int i = 0; i < method.getParameterTypes().length; i++)
@@ -107,7 +113,7 @@
}
}
}
-
+
String propertyName = Reflections.getPropertyName(getDelegate());
if (propertyName == null)
{
@@ -281,30 +287,23 @@
*/
public String toString()
{
+ if (toString != null)
+ {
+ return toString;
+ }
StringBuffer buffer = new StringBuffer();
- // buffer.append("AnnotatedMethodImpl:\n");
- // buffer.append(super.toString() + "\n");
- // buffer.append("Actual type arguments: " + actualTypeArguments.length +
- // "\n");
- // int i = 0;
- // for (Type actualTypeArgument : actualTypeArguments)
- // {
- // buffer.append(++i + " - " + actualTypeArgument.toString());
- // }
- // buffer.append(annotatedParameters == null ? "" :
- // (annotatedParameters.toString() + "\n"));
- // buffer.append("Declaring class:\n");
- // buffer.append(declaringClass.toString());
- // buffer.append("Method:\n");
- // buffer.append(method.toString());
- // buffer.append("Property name: " + propertyName + "\n");
- // i = 0;
- // buffer.append("Parameters: " + getParameters().size() + "\n");
- // for (AnnotatedParameter<?> parameter : parameters)
- // {
- // buffer.append(++i + " - " + parameter.toString() + "\n");
- // }
- return buffer.toString();
+ buffer.append("AnnotatedMethodImpl:\n");
+ buffer.append(super.toString() + "\n");
+ buffer.append(Strings.collectionToString("Actual type arguments: ", Arrays.asList(getActualTypeArguments())));
+ buffer.append(annotatedParameters == null ? "" : (annotatedParameters.toString() + "\n"));
+ buffer.append("Declaring class:\n");
+ buffer.append(declaringClass.getName() + "[ " + declaringClass.getType() + "]" + "\n");
+ buffer.append("Method:\n");
+ buffer.append(method.toString());
+ buffer.append("Property name: " + propertyName + "\n");
+ buffer.append(Strings.collectionToString("Parameters: ", getParameters()));
+ toString = buffer.toString();
+ return toString;
}
}
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/jlr/AnnotatedParameterImpl.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/jlr/AnnotatedParameterImpl.java 2008-12-03 19:26:10 UTC (rev 396)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/jlr/AnnotatedParameterImpl.java 2008-12-03 22:49:55 UTC (rev 397)
@@ -19,16 +19,18 @@
import java.lang.annotation.Annotation;
import java.lang.reflect.Type;
+import java.util.Arrays;
import javax.webbeans.BindingType;
import org.jboss.webbeans.ManagerImpl;
import org.jboss.webbeans.introspector.AnnotatedParameter;
+import org.jboss.webbeans.util.Strings;
/**
* Represents a parameter
*
- * This class is immutable and thus threadsafe
+ * This class is immutable and therefore threadsafe
*
* @author Pete Muir
*
@@ -45,6 +47,9 @@
// The static state
private final boolean _static = false;
+ // Cached string representation
+ private String toString;
+
/**
* Constructor
*
@@ -149,19 +154,19 @@
*/
public String toString()
{
+ if (toString != null)
+ {
+ return toString;
+ }
StringBuffer buffer = new StringBuffer();
-// buffer.append("AnnotatedParameterImpl:\n");
-// buffer.append(super.toString() + "\n");
-// buffer.append("Type: " + type.toString() + "\n");
-// buffer.append("Final: " + _final + "\n");
-// buffer.append("Static: " + _static + "\n");
-// buffer.append("Actual type arguments: " + actualTypeArguments.length + "\n");
-// int i = 0;
-// for (Type actualTypeArgument : actualTypeArguments)
-// {
-// buffer.append(++i + " - " + actualTypeArgument.toString() + "\n");
-// }
- return buffer.toString();
+ buffer.append("AnnotatedParameterImpl:\n");
+ buffer.append(super.toString() + "\n");
+ buffer.append("Type: " + type.toString() + "\n");
+ buffer.append("Final: " + _final + "\n");
+ buffer.append("Static: " + _static + "\n");
+ buffer.append(Strings.collectionToString("Actual type arguments: ", Arrays.asList(getActualTypeArguments())));
+ toString = buffer.toString();
+ return toString;
}
}
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/BindingTypeModel.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/BindingTypeModel.java 2008-12-03 19:26:10 UTC (rev 396)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/BindingTypeModel.java 2008-12-03 22:49:55 UTC (rev 397)
@@ -26,6 +26,7 @@
import org.jboss.webbeans.introspector.AnnotatedMethod;
import org.jboss.webbeans.util.Reflections;
+import org.jboss.webbeans.util.Strings;
/**
*
@@ -157,12 +158,7 @@
buffer.append("BindingTypeModel:\n");
buffer.append(super.toString());
buffer.append("Hash code: " + hashCode);
- buffer.append("Non-binding types: " + nonBindingTypes.size());
- int i = 0;
- for (AnnotatedMethod<?> nonBindingType : getNonBindingTypes())
- {
- buffer.append(++i + " - " + nonBindingType.toString());
- }
+ buffer.append(Strings.collectionToString("Non-binding types: ", getNonBindingTypes()));
return buffer.toString();
}
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/StereotypeModel.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/StereotypeModel.java 2008-12-03 19:26:10 UTC (rev 396)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/StereotypeModel.java 2008-12-03 22:49:55 UTC (rev 397)
@@ -30,6 +30,8 @@
import javax.webbeans.ScopeType;
import javax.webbeans.Stereotype;
+import org.jboss.webbeans.util.Strings;
+
/**
* A meta model for a stereotype, allows us to cache a stereotype and to
* validate it
@@ -248,24 +250,9 @@
buffer.append("Default deployment type: " + getDefaultDeploymentType());
buffer.append("Default scope type: " + getDefaultScopeType());
buffer.append("Meta-annotation: " + getMetaAnnotation().toString());
- buffer.append("Interceptor bindings: " + getInterceptorBindings().size());
- int i = 0;
- for (Annotation annotation : getInterceptorBindings())
- {
- buffer.append(++i + " - " + annotation.toString());
- }
- buffer.append("Required types: " + getRequiredTypes().size());
- i = 0;
- for (Class<?> requiredType : getRequiredTypes())
- {
- buffer.append(++i + " - " + requiredType.toString());
- }
- buffer.append("Supported scopes: " + getSupportedScopes().size());
- i = 0;
- for (Class<?> supportedScope : getSupportedScopes())
- {
- buffer.append(++i + " - " + supportedScope.toString());
- }
+ buffer.append(Strings.collectionToString("Interceptor bindings: ", getInterceptorBindings()));
+ buffer.append(Strings.collectionToString("Required types: ", getRequiredTypes()));
+ buffer.append(Strings.collectionToString("Supported scopes: ", getSupportedScopes()));
return buffer.toString();
}
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/util/Strings.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/util/Strings.java 2008-12-03 19:26:10 UTC (rev 396)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/util/Strings.java 2008-12-03 22:49:55 UTC (rev 397)
@@ -80,12 +80,17 @@
public static String mapToString(String header, Map<?, ?> map)
{
StringBuffer buffer = new StringBuffer();
+ if (map == null)
+ {
+ buffer.append(header + "null\n");
+ return buffer.toString();
+ }
buffer.append(header + "[" + map.size() + " entries]\n");
int i = 0;
for (Object key : map.keySet())
{
Object value = map.get(key);
- buffer.append(" #" + ++i + ": " + key.toString() + "->");
+ buffer.append(" #" + ++i + ": " + key.toString() + " -> ");
if (value instanceof Iterable)
{
buffer.append("\n");
@@ -102,6 +107,23 @@
return buffer.toString();
}
+ public static String collectionToString(String header, Collection<?> collection)
+ {
+ StringBuffer buffer = new StringBuffer();
+ if (collection == null)
+ {
+ buffer.append(header + "null\n");
+ return buffer.toString();
+ }
+ buffer.append(header + "[" + collection.size() + " entries]\n");
+ int i = 0;
+ for (Object item : collection)
+ {
+ buffer.append(" #" + ++i + ": " + item.toString() + "\n");
+ }
+ return buffer.toString();
+ }
+
public static void main(String[] args)
{
Map map = new HashMap<String, Collection<?>>();
16 years
[webbeans-commits] Webbeans SVN: r396 - in ri/trunk: webbeans-ri/src/main/java/org/jboss/webbeans/contexts and 1 other directory.
by webbeans-commits@lists.jboss.org
Author: nickarls
Date: 2008-12-03 14:26:10 -0500 (Wed, 03 Dec 2008)
New Revision: 396
Added:
ri/trunk/webbeans-api/src/main/java/javax/webbeans/manager/Contextual.java
Modified:
ri/trunk/webbeans-api/src/main/java/javax/webbeans/manager/Bean.java
ri/trunk/webbeans-api/src/main/java/javax/webbeans/manager/Context.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/contexts/AbstractContext.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/contexts/BeanMap.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/contexts/DependentContext.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/contexts/SessionBeanMap.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/contexts/SimpleBeanMap.java
Log:
Contextual interface
Modified: ri/trunk/webbeans-api/src/main/java/javax/webbeans/manager/Bean.java
===================================================================
--- ri/trunk/webbeans-api/src/main/java/javax/webbeans/manager/Bean.java 2008-12-03 19:25:14 UTC (rev 395)
+++ ri/trunk/webbeans-api/src/main/java/javax/webbeans/manager/Bean.java 2008-12-03 19:26:10 UTC (rev 396)
@@ -26,10 +26,9 @@
*
* @author Gavin King
*
- * @param <T>
- * an API type of the Web Bean
+ * @param <T> an API type of the Web Bean
*/
-public abstract class Bean<T>
+public abstract class Bean<T> implements Contextual<T>
{
private final Manager manager;
Modified: ri/trunk/webbeans-api/src/main/java/javax/webbeans/manager/Context.java
===================================================================
--- ri/trunk/webbeans-api/src/main/java/javax/webbeans/manager/Context.java 2008-12-03 19:25:14 UTC (rev 395)
+++ ri/trunk/webbeans-api/src/main/java/javax/webbeans/manager/Context.java 2008-12-03 19:26:10 UTC (rev 396)
@@ -1,25 +1,24 @@
/*
-* JBoss, Home of Professional Open Source
-* Copyright 2008, Red Hat Middleware LLC, and individual contributors
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-* http://www.apache.org/licenses/LICENSE-2.0
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
package javax.webbeans.manager;
import java.lang.annotation.Annotation;
-
/**
* The contract between the Web Bean manager and a Web Beans context object.
* This interface should not be called directly by the application.
@@ -32,9 +31,9 @@
{
public Class<? extends Annotation> getScopeType();
-
- public <T> T get(Bean<T> bean, boolean create);
-
+
+ public <T> T get(Contextual<T> bean, boolean create);
+
boolean isActive();
-
+
}
Added: ri/trunk/webbeans-api/src/main/java/javax/webbeans/manager/Contextual.java
===================================================================
--- ri/trunk/webbeans-api/src/main/java/javax/webbeans/manager/Contextual.java (rev 0)
+++ ri/trunk/webbeans-api/src/main/java/javax/webbeans/manager/Contextual.java 2008-12-03 19:26:10 UTC (rev 396)
@@ -0,0 +1,31 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package javax.webbeans.manager;
+
+/**
+ * The contract between a Context and an object that has its lifecycle managed
+ * by the context
+ *
+ * @author Nicklas Karlsson
+ */
+public interface Contextual<T>
+{
+ public abstract T create();
+
+ public abstract void destroy(T instance);
+}
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/contexts/AbstractContext.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/contexts/AbstractContext.java 2008-12-03 19:25:14 UTC (rev 395)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/contexts/AbstractContext.java 2008-12-03 19:26:10 UTC (rev 396)
@@ -23,6 +23,7 @@
import javax.webbeans.ContextNotActiveException;
import javax.webbeans.manager.Bean;
import javax.webbeans.manager.Context;
+import javax.webbeans.manager.Contextual;
import javax.webbeans.manager.Manager;
/**
@@ -61,7 +62,7 @@
*
* @see javax.webbeans.manager.Context#get(Bean, boolean)
*/
- public <T> T get(Bean<T> bean, boolean create)
+ public <T> T get(Contextual<T> bean, boolean create)
{
if (!isActive())
{
@@ -118,7 +119,7 @@
}
// TODO Do we need this
- private <T> void destroy(Manager manager, Bean<T> bean)
+ private <T> void destroy(Manager manager, Contextual<T> bean)
{
bean.destroy(getBeanMap().get(bean));
}
@@ -126,7 +127,7 @@
// TODO Do we need this
public void destroy(Manager manager)
{
- for (Bean<? extends Object> bean : getBeanMap().keySet())
+ for (Contextual<? extends Object> bean : getBeanMap().keySet())
{
destroy(manager, bean);
}
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/contexts/BeanMap.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/contexts/BeanMap.java 2008-12-03 19:25:14 UTC (rev 395)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/contexts/BeanMap.java 2008-12-03 19:26:10 UTC (rev 396)
@@ -17,7 +17,7 @@
package org.jboss.webbeans.contexts;
-import javax.webbeans.manager.Bean;
+import javax.webbeans.manager.Contextual;
/**
* Interface for different implementations of Bean to Bean instance storage.
@@ -36,7 +36,7 @@
* @param bean The bean whose instance to return
* @return The instance. Null if not found
*/
- public abstract <T extends Object> T get(Bean<? extends T> bean);
+ public abstract <T extends Object> T get(Contextual<? extends T> bean);
/**
* Removes an instance of a bean from the storage
@@ -44,7 +44,7 @@
* @param bean The bean whose instance to remove
* @return The removed instance. Null if not found in storage.
*/
- public abstract <T extends Object> T remove(Bean<? extends T> bean);
+ public abstract <T extends Object> T remove(Contextual<? extends T> bean);
/**
* Clears the storage of any bean instances
@@ -56,7 +56,7 @@
*
* @return An Iterable over the keys in the storage
*/
- public abstract Iterable<Bean<? extends Object>> keySet();
+ public abstract Iterable<Contextual<? extends Object>> keySet();
/**
* Adds a bean instance to the storage
@@ -65,5 +65,5 @@
* @param instance The instance to add
* @return The instance added
*/
- public abstract <T> void put(Bean<? extends T> bean, T instance);
+ public abstract <T> void put(Contextual<? extends T> bean, T instance);
}
\ No newline at end of file
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/contexts/DependentContext.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/contexts/DependentContext.java 2008-12-03 19:25:14 UTC (rev 395)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/contexts/DependentContext.java 2008-12-03 19:26:10 UTC (rev 396)
@@ -19,7 +19,7 @@
import javax.webbeans.ContextNotActiveException;
import javax.webbeans.Dependent;
-import javax.webbeans.manager.Bean;
+import javax.webbeans.manager.Contextual;
/**
* The dependent context
@@ -43,7 +43,7 @@
* @param create Should a new one be created
*/
@Override
- public <T> T get(Bean<T> bean, boolean create)
+ public <T> T get(Contextual<T> bean, boolean create)
{
if (!isActive())
{
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/contexts/SessionBeanMap.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/contexts/SessionBeanMap.java 2008-12-03 19:25:14 UTC (rev 395)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/contexts/SessionBeanMap.java 2008-12-03 19:26:10 UTC (rev 396)
@@ -23,6 +23,7 @@
import javax.servlet.http.HttpSession;
import javax.webbeans.manager.Bean;
+import javax.webbeans.manager.Contextual;
import org.jboss.webbeans.ManagerImpl;
import org.jboss.webbeans.log.LogProvider;
@@ -91,7 +92,7 @@
* @param bean The bean to generate a key for.
* @return A unique key;
*/
- private String getBeanKey(Bean<?> bean)
+ private String getBeanKey(Contextual<?> bean)
{
return keyPrefix + manager.getBeans().indexOf(bean);
}
@@ -109,7 +110,7 @@
* @see org.jboss.webbeans.contexts.BeanMap#get(Bean)
*/
@SuppressWarnings("unchecked")
- public <T> T get(Bean<? extends T> bean)
+ public <T> T get(Contextual<? extends T> bean)
{
checkSession();
String key = getBeanKey(bean);
@@ -130,7 +131,7 @@
*
* @see org.jboss.webbeans.contexts.BeanMap#remove(Bean)
*/
- public <T> T remove(Bean<? extends T> bean)
+ public <T> T remove(Contextual<? extends T> bean)
{
checkSession();
T instance = get(bean);
@@ -175,11 +176,11 @@
* @see org.jboss.webbeans.contexts.BeanMap#keySet()
*/
@SuppressWarnings("unchecked")
- public Iterable<Bean<? extends Object>> keySet()
+ public Iterable<Contextual<? extends Object>> keySet()
{
checkSession();
- List<Bean<?>> beans = new ArrayList<Bean<?>>();
+ List<Contextual<?>> beans = new ArrayList<Contextual<?>>();
Enumeration names = session.getAttributeNames();
while (names.hasMoreElements())
@@ -188,7 +189,7 @@
if (name.startsWith(keyPrefix))
{
String id = name.substring(keyPrefix.length());
- Bean<?> bean = manager.getBeans().get(Integer.parseInt(id));
+ Contextual<?> bean = manager.getBeans().get(Integer.parseInt(id));
beans.add(bean);
}
}
@@ -207,7 +208,7 @@
*
* @see org.jboss.webbeans.contexts.BeanMap#put(Bean, Object)
*/
- public <T> void put(Bean<? extends T> bean, T instance)
+ public <T> void put(Contextual<? extends T> bean, T instance)
{
checkSession();
String key = getBeanKey(bean);
@@ -220,10 +221,10 @@
public String toString()
{
StringBuffer buffer = new StringBuffer();
- List<Bean<?>> beans = (List) keySet();
+ List<Contextual<?>> beans = (List) keySet();
buffer.append("Bean -> bean instance mappings in HTTP session: " + beans.size() + "\n");
int i = 0;
- for (Bean<?> bean : beans)
+ for (Contextual<?> bean : beans)
{
Object instance = get(bean);
buffer.append(++i + " - " + getBeanKey(bean) + ": " + instance + "\n");
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/contexts/SimpleBeanMap.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/contexts/SimpleBeanMap.java 2008-12-03 19:25:14 UTC (rev 395)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/contexts/SimpleBeanMap.java 2008-12-03 19:26:10 UTC (rev 396)
@@ -22,6 +22,7 @@
import java.util.concurrent.ConcurrentHashMap;
import javax.webbeans.manager.Bean;
+import javax.webbeans.manager.Contextual;
import org.jboss.webbeans.log.LogProvider;
import org.jboss.webbeans.log.Logging;
@@ -34,19 +35,19 @@
*
* @author Nicklas Karlsson
*/
-public class SimpleBeanMap extends ForwardingMap<Bean<? extends Object>, Object> implements BeanMap
+public class SimpleBeanMap extends ForwardingMap<Contextual<? extends Object>, Object> implements BeanMap
{
private static LogProvider log = Logging.getLogProvider(SimpleBeanMap.class);
// The backing map
- protected Map<Bean<? extends Object>, Object> delegate;
+ protected Map<Contextual<? extends Object>, Object> delegate;
/**
* Constructor
*/
public SimpleBeanMap()
{
- delegate = new ConcurrentHashMap<Bean<? extends Object>, Object>();
+ delegate = new ConcurrentHashMap<Contextual<? extends Object>, Object>();
}
/**
@@ -58,7 +59,7 @@
* @see org.jboss.webbeans.contexts.BeanMap#get(Bean)
*/
@SuppressWarnings("unchecked")
- public <T extends Object> T get(Bean<? extends T> bean)
+ public <T extends Object> T get(Contextual<? extends T> bean)
{
T instance = (T) super.get(bean);
log.trace("Searched bean map for " + bean + " and got " + instance);
@@ -71,7 +72,7 @@
* @return The delegate
*/
@Override
- public Map<Bean<? extends Object>, Object> delegate()
+ public Map<Contextual<? extends Object>, Object> delegate()
{
return delegate;
}
@@ -85,7 +86,7 @@
* @see org.jboss.webbeans.contexts.BeanMap#remove(Bean)
*/
@SuppressWarnings("unchecked")
- public <T extends Object> T remove(Bean<? extends T> bean)
+ public <T extends Object> T remove(Contextual<? extends T> bean)
{
T instance = (T) super.remove(bean);
log.trace("Removed instace " + instance + " for bean " + bean + " from the bean map");
@@ -110,7 +111,7 @@
*
* @see org.jboss.webbeans.contexts.BeanMap#keySet()
*/
- public Set<Bean<? extends Object>> keySet()
+ public Set<Contextual<? extends Object>> keySet()
{
return delegate.keySet();
}
@@ -123,7 +124,7 @@
*
* @see org.jboss.webbeans.contexts.BeanMap#put(Bean, Object)
*/
- public <T> void put(Bean<? extends T> bean, T instance)
+ public <T> void put(Contextual<? extends T> bean, T instance)
{
delegate.put(bean, instance);
log.trace("Stored instance " + instance + " for bean " + bean + " in bean map");
16 years
[webbeans-commits] Webbeans SVN: r395 - in ri/trunk/webbeans-ri/src: main/java/org/jboss/webbeans/bean/proxy and 2 other directories.
by webbeans-commits@lists.jboss.org
Author: pete.muir(a)jboss.org
Date: 2008-12-03 14:25:14 -0500 (Wed, 03 Dec 2008)
New Revision: 395
Modified:
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/ManagerImpl.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/MetaDataCache.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/proxy/ProxyPool.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/contexts/ContextMap.java
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/examples/Tests.java
Log:
More improvements to thread safety (some refactoring needed)
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/ManagerImpl.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/ManagerImpl.java 2008-12-03 18:44:05 UTC (rev 394)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/ManagerImpl.java 2008-12-03 19:25:14 UTC (rev 395)
@@ -19,6 +19,7 @@
import java.lang.annotation.Annotation;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
@@ -210,7 +211,7 @@
*/
public List<Class<? extends Annotation>> getEnabledDeploymentTypes()
{
- return enabledDeploymentTypes;
+ return Collections.unmodifiableList(enabledDeploymentTypes);
}
/**
@@ -289,10 +290,13 @@
*/
public Manager setBeans(Set<AbstractBean<?, ?>> beans)
{
- this.beans = new CopyOnWriteArrayList<Bean<?>>(beans);
- resolver.clear();
- initStandardBeans();
- return this;
+ synchronized (beans)
+ {
+ this.beans = new CopyOnWriteArrayList<Bean<?>>(beans);
+ resolver.clear();
+ initStandardBeans();
+ return this;
+ }
}
/**
@@ -302,7 +306,7 @@
*/
public List<Bean<?>> getBeans()
{
- return beans;
+ return Collections.unmodifiableList(beans);
}
/**
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/MetaDataCache.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/MetaDataCache.java 2008-12-03 18:44:05 UTC (rev 394)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/MetaDataCache.java 2008-12-03 19:25:14 UTC (rev 395)
@@ -21,6 +21,7 @@
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
+import java.util.concurrent.ConcurrentHashMap;
import org.jboss.webbeans.ejb.EjbMetaData;
import org.jboss.webbeans.model.AnnotationModel;
@@ -41,7 +42,7 @@
public AnnotationModelMap()
{
- delegate = new HashMap<Class<? extends Annotation>, T>();
+ delegate = new ConcurrentHashMap<Class<? extends Annotation>, T>();
}
public <S extends Annotation> T putIfAbsent(Class<S> key)
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/proxy/ProxyPool.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/proxy/ProxyPool.java 2008-12-03 18:44:05 UTC (rev 394)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/proxy/ProxyPool.java 2008-12-03 19:25:14 UTC (rev 395)
@@ -22,7 +22,11 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
+import java.util.concurrent.Callable;
import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.Future;
+import java.util.concurrent.FutureTask;
import javassist.util.proxy.ProxyFactory;
import javassist.util.proxy.ProxyObject;
@@ -49,24 +53,24 @@
*
* @author Nicklas Karlsson
*/
- private class Pool extends ForwardingMap<Bean<?>, Object>
+ private class Pool extends ForwardingMap<Bean<?>, Future<Object>>
{
- Map<Bean<?>, Object> delegate;
+ Map<Bean<?>, Future<Object>> delegate;
public Pool()
{
- delegate = new ConcurrentHashMap<Bean<?>, Object>();
+ delegate = new ConcurrentHashMap<Bean<?>, Future<Object>>();
}
@SuppressWarnings("unchecked")
- public <T> T get(Bean<T> key)
+ public <T> Future<T> get(Bean<T> key)
{
- return (T) super.get(key);
+ return (Future<T>) super.get(key);
}
@Override
- protected Map<Bean<?>, Object> delegate()
+ protected Map<Bean<?>, Future<Object>> delegate()
{
return delegate;
}
@@ -93,7 +97,7 @@
*
* @author Nicklas Karlsson
*/
- private class TypeInfo
+ private static class TypeInfo
{
Class<?>[] interfaces;
Class<?> superclass;
@@ -109,7 +113,7 @@
* @param types A set of types (interfaces and superclasses) of a class
* @return The TypeInfo with categorized information
*/
- private TypeInfo getTypeInfo(Set<Class<?>> types)
+ private static TypeInfo getTypeInfo(Set<Class<?>> types)
{
TypeInfo typeInfo = new TypeInfo();
List<Class<?>> interfaces = new ArrayList<Class<?>>();
@@ -145,7 +149,7 @@
* @throws IllegalAccessException When the proxy couldn't be created
*/
@SuppressWarnings("unchecked")
- private <T> T createClientProxy(Bean<T> bean, int beanIndex) throws RuntimeException
+ private static <T> T createClientProxy(Bean<T> bean, int beanIndex, ManagerImpl manager) throws RuntimeException
{
ProxyFactory proxyFactory = new ProxyFactory();
TypeInfo typeInfo = getTypeInfo(bean.getTypes());
@@ -178,21 +182,66 @@
* @param bean
* @return
*/
- public Object getClientProxy(Bean<?> bean)
+ public Object getClientProxy(final Bean<?> bean)
{
- Object clientProxy = pool.get(bean);
+ Future<?> clientProxy = pool.get(bean);
if (clientProxy == null)
{
- int beanIndex = manager.getBeans().indexOf(bean);
- if (beanIndex < 0)
+ FutureTask<Object> task = new FutureTask<Object>(new Callable<Object>()
{
- throw new DefinitionException(bean + " is not known to the manager");
+
+ public Object call() throws Exception
+ {
+ int beanIndex = manager.getBeans().indexOf(bean);
+ if (beanIndex < 0)
+ {
+ throw new DefinitionException(bean + " is not known to the manager");
+ }
+ return createClientProxy(bean, beanIndex, manager);
+ }
+
+ });
+ clientProxy = task;
+ pool.put(bean, task);
+ task.run();
+ }
+ boolean interrupted = false;
+ try
+ {
+ while (true)
+ {
+ try
+ {
+ return clientProxy.get();
+ }
+ catch (InterruptedException e)
+ {
+ interrupted = true;
+ }
+ catch (ExecutionException e)
+ {
+ if (e.getCause() instanceof RuntimeException)
+ {
+ throw (RuntimeException) e.getCause();
+ }
+ else if (e.getCause() instanceof Error)
+ {
+ throw (Error) e.getCause();
+ }
+ else
+ {
+ throw new IllegalStateException(e.getCause());
+ }
+ };
}
- clientProxy = createClientProxy(bean, beanIndex);
-
- pool.put(bean, clientProxy);
}
- return clientProxy;
+ finally
+ {
+ if (interrupted)
+ {
+ Thread.currentThread().interrupt();
+ }
+ }
}
@Override
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/contexts/ContextMap.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/contexts/ContextMap.java 2008-12-03 18:44:05 UTC (rev 394)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/contexts/ContextMap.java 2008-12-03 19:25:14 UTC (rev 395)
@@ -87,8 +87,12 @@
List<Context> contexts = super.get(context.getScopeType());
if (contexts == null)
{
- contexts = new CopyOnWriteArrayList<Context>();
- put(context.getScopeType(), contexts);
+ synchronized (delegate)
+ {
+ contexts = new CopyOnWriteArrayList<Context>();
+ put(context.getScopeType(), contexts);
+ }
+ contexts = super.get(context.getScopeType());
}
contexts.add(context);
}
Modified: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/examples/Tests.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/examples/Tests.java 2008-12-03 18:44:05 UTC (rev 394)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/examples/Tests.java 2008-12-03 19:25:14 UTC (rev 395)
@@ -2,6 +2,9 @@
import java.lang.reflect.Method;
+import javax.webbeans.Production;
+import javax.webbeans.Standard;
+
import org.jboss.webbeans.bean.ProducerMethodBean;
import org.jboss.webbeans.bean.SimpleBean;
import org.jboss.webbeans.test.AbstractTest;
@@ -41,7 +44,7 @@
public void testMockSentenceTranslator() throws Exception {
setupTextTranslator();
- manager.getEnabledDeploymentTypes().add(Mock.class);
+ manager.setEnabledDeploymentTypes(Standard.class, Production.class, Mock.class);
TextTranslator tt2 = manager.getInstanceByType(TextTranslator.class);
assert "Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet.".equals( tt2.translate("Hello world. How's tricks?") );
16 years
[webbeans-commits] Webbeans SVN: r394 - ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans.
by webbeans-commits@lists.jboss.org
Author: pete.muir(a)jboss.org
Date: 2008-12-03 13:44:05 -0500 (Wed, 03 Dec 2008)
New Revision: 394
Modified:
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/Resolver.java
Log:
Initial work on making resolver suitable for concurrent use - some tidyup needed
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/Resolver.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/Resolver.java 2008-12-03 17:51:11 UTC (rev 393)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/Resolver.java 2008-12-03 18:44:05 UTC (rev 394)
@@ -28,6 +28,11 @@
import java.util.SortedSet;
import java.util.TreeSet;
import java.util.Map.Entry;
+import java.util.concurrent.Callable;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.Future;
+import java.util.concurrent.FutureTask;
import javax.webbeans.NullableDependencyException;
import javax.webbeans.manager.Bean;
@@ -90,29 +95,28 @@
}
- // TODO Why can't we generify Set?
/**
* Type safe map for caching annotation metadata
*/
@SuppressWarnings("unchecked")
- private class AnnotatedItemMap extends ForwardingMap<AnnotatedItem<?, ?>, Set>
+ private class ConcurrentAnnotatedItemMap extends ForwardingMap<AnnotatedItem<?, ?>, Future>
{
- private Map<AnnotatedItem<?, ?>, Set> delegate;
+ private Map<AnnotatedItem<?, ?>, Future> delegate;
- public AnnotatedItemMap()
+ public ConcurrentAnnotatedItemMap()
{
- delegate = new HashMap<AnnotatedItem<?, ?>, Set>();
+ delegate = new ConcurrentHashMap<AnnotatedItem<?, ?>, Future>();
}
- public <T> Set<Bean<T>> get(AnnotatedItem<T, ?> key)
+ public <T> Future<Set<Bean<T>>> get(AnnotatedItem<T, ?> key)
{
- return (Set<Bean<T>>) super.get(key);
+ return (Future<Set<Bean<T>>>) super.get(key);
}
@Override
- protected Map<AnnotatedItem<?, ?>, Set> delegate()
+ protected Map<AnnotatedItem<?, ?>, Future > delegate()
{
return delegate;
}
@@ -125,10 +129,10 @@
}
- private AnnotatedItemMap resolvedInjectionPoints;
+ private ConcurrentAnnotatedItemMap resolvedInjectionPoints;
private Set<AnnotatedItem<?, ?>> injectionPoints;
- private Map<String, Set<Bean<?>>> resolvedNames;
+ private Map<String, Future<Set<Bean<?>>>> resolvedNames;
private ManagerImpl manager;
@@ -136,7 +140,7 @@
{
this.manager = manager;
this.injectionPoints = new HashSet<AnnotatedItem<?, ?>>();
- this.resolvedInjectionPoints = new AnnotatedItemMap();
+ this.resolvedInjectionPoints = new ConcurrentAnnotatedItemMap();
}
/**
@@ -147,20 +151,54 @@
{
injectionPoints.addAll(elements);
}
+
+ private void registerName(final String name)
+ {
+ FutureTask<Set<Bean<?>>> task = new FutureTask<Set<Bean<?>>>(new Callable<Set<Bean<?>>>()
+ {
+ public Set<Bean<?>> call() throws Exception
+ {
+ Set<Bean<?>> beans = new HashSet<Bean<?>>();
+ for (Bean<?> bean : manager.getBeans())
+ {
+ if ((bean.getName() == null && name == null) || (bean.getName() != null && bean.getName().equals(name)))
+ {
+ beans.add(bean);
+ }
+ }
+ return retainHighestPrecedenceBeans(beans, manager.getEnabledDeploymentTypes());
+ }
+
+ });
+ resolvedNames.put(name, task);
+
+ task.run();
+ }
+
private <T, S> void registerInjectionPoint(final AnnotatedItem<T, S> element)
{
- Set<Bean<?>> beans = retainHighestPrecedenceBeans(getMatchingBeans(element, manager.getBeans(), manager.getMetaDataCache()), manager.getEnabledDeploymentTypes());
- if (element.getType().isPrimitive())
+ FutureTask<Set<Bean<?>>> task = new FutureTask<Set<Bean<?>>>(new Callable<Set<Bean<?>>>()
{
- for (Bean<?> bean : beans)
+
+ public Set<Bean<?>> call() throws Exception
{
- if (bean.isNullable())
+ Set<Bean<?>> beans = retainHighestPrecedenceBeans(getMatchingBeans(element, manager.getBeans(), manager.getMetaDataCache()), manager.getEnabledDeploymentTypes());
+ if (element.getType().isPrimitive())
{
- throw new NullableDependencyException("Primitive injection points resolves to nullable web bean");
+ for (Bean<?> bean : beans)
+ {
+ if (bean.isNullable())
+ {
+ throw new NullableDependencyException("Primitive injection points resolves to nullable web bean");
+ }
+ }
}
+ return beans;
}
- }
+
+ });
+
resolvedInjectionPoints.put(new ResolvableAnnotatedItem<T, S>()
{
@@ -170,7 +208,9 @@
return element;
}
- }, beans);
+ }, task);
+
+ task.run();
}
/**
@@ -179,8 +219,8 @@
*/
public void clear()
{
- resolvedInjectionPoints = new AnnotatedItemMap();
- resolvedNames = new HashMap<String, Set<Bean<?>>>();
+ resolvedInjectionPoints = new ConcurrentAnnotatedItemMap();
+ resolvedNames = new HashMap<String, Future<Set<Bean<?>>>>();
}
/**
@@ -214,7 +254,6 @@
};
- // TODO We don't need this I think
if (element.getType().equals(Object.class))
{
// TODO Fix this cast
@@ -226,7 +265,44 @@
{
registerInjectionPoint(element);
}
- beans = resolvedInjectionPoints.get(element);
+
+ boolean interupted = false;
+ try
+ {
+ while (true)
+ {
+ try
+ {
+ return Collections.unmodifiableSet(resolvedInjectionPoints.get(element).get());
+ }
+ catch (ExecutionException e)
+ {
+ if (e.getCause() instanceof RuntimeException)
+ {
+ throw (RuntimeException) e.getCause();
+ }
+ else if (e.getCause() instanceof Error)
+ {
+ throw (Error) e.getCause();
+ }
+ else
+ {
+ throw new IllegalStateException(e.getCause());
+ }
+ }
+ catch (InterruptedException e)
+ {
+ interupted = true;
+ }
+ }
+ }
+ finally
+ {
+ if (interupted)
+ {
+ Thread.currentThread().interrupt();
+ }
+ }
}
return Collections.unmodifiableSet(beans);
}
@@ -236,26 +312,48 @@
*/
public Set<Bean<?>> get(String name)
{
- Set<Bean<?>> beans;
- if (resolvedNames.containsKey(name))
+ if (!resolvedNames.containsKey(name))
{
- beans = resolvedNames.get(name);
+ registerName(name);
}
- else
+
+ boolean interupted = false;
+ try
{
- beans = new HashSet<Bean<?>>();
- for (Bean<?> bean : manager.getBeans())
+ while (true)
{
- if ((bean.getName() == null && name == null) || (bean.getName() != null && bean.getName().equals(name)))
+ try
{
- beans.add(bean);
+ return Collections.unmodifiableSet(resolvedNames.get(name).get());
}
+ catch (ExecutionException e)
+ {
+ if (e.getCause() instanceof RuntimeException)
+ {
+ throw (RuntimeException) e.getCause();
+ }
+ else if (e.getCause() instanceof Error)
+ {
+ throw (Error) e.getCause();
+ }
+ else
+ {
+ throw new IllegalStateException(e.getCause());
+ }
+ }
+ catch (InterruptedException e)
+ {
+ interupted = true;
+ }
}
- beans = retainHighestPrecedenceBeans(beans, manager.getEnabledDeploymentTypes());
- resolvedNames.put(name, beans);
-
}
- return Collections.unmodifiableSet(beans);
+ finally
+ {
+ if (interupted)
+ {
+ Thread.currentThread().interrupt();
+ }
+ }
}
private static Set<Bean<?>> retainHighestPrecedenceBeans(Set<Bean<?>> beans, List<Class<? extends Annotation>> enabledDeploymentTypes)
@@ -356,7 +454,7 @@
}
buffer.append("Resolved names: " + resolvedNames.size() + "\n");
i = 0;
- for (Entry<String, Set<Bean<?>>> entry : resolvedNames.entrySet())
+ for (Entry<String, Future<Set<Bean<?>>>> entry : resolvedNames.entrySet())
{
buffer.append(++i + " - " + entry + ": " + entry.getValue().toString() + "\n");
}
16 years