openwebbeans-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dblev...@apache.org
Subject svn commit: r1041634 - in /openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans: config/WebBeansContext.java config/WebBeansFinder.java container/BeanManagerImpl.java corespi/DefaultSingletonService.java
Date Thu, 02 Dec 2010 23:14:38 GMT
Author: dblevins
Date: Thu Dec  2 23:14:37 2010
New Revision: 1041634

URL: http://svn.apache.org/viewvc?rev=1041634&view=rev
Log:
OWB-503: Reduce static synchronized hashmap usage
Sort of a first step.  Doesn't yet eliminate anything, but does begin to provide means for
non-static referral of the core objects

Added:
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/WebBeansContext.java
  (with props)
Modified:
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/WebBeansFinder.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/BeanManagerImpl.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/corespi/DefaultSingletonService.java

Added: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/WebBeansContext.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/WebBeansContext.java?rev=1041634&view=auto
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/WebBeansContext.java
(added)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/WebBeansContext.java
Thu Dec  2 23:14:37 2010
@@ -0,0 +1,236 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.webbeans.config;
+
+import org.apache.webbeans.container.BeanManagerImpl;
+import org.apache.webbeans.container.SerializableBeanVault;
+import org.apache.webbeans.context.creational.CreationalContextFactory;
+import org.apache.webbeans.corespi.se.DefaultContextsService;
+import org.apache.webbeans.corespi.se.DefaultJndiService;
+import org.apache.webbeans.corespi.se.DefaultScannerService;
+import org.apache.webbeans.decorator.DecoratorsManager;
+import org.apache.webbeans.deployment.StereoTypeManager;
+import org.apache.webbeans.exception.WebBeansException;
+import org.apache.webbeans.inject.AlternativesManager;
+import org.apache.webbeans.intercept.InterceptorsManager;
+import org.apache.webbeans.jms.JMSManager;
+import org.apache.webbeans.plugins.PluginLoader;
+import org.apache.webbeans.portable.AnnotatedElementFactory;
+import org.apache.webbeans.portable.events.ExtensionLoader;
+import org.apache.webbeans.proxy.JavassistProxyFactory;
+import org.apache.webbeans.util.ClassUtil;
+import org.apache.webbeans.xml.WebBeansNameSpaceContainer;
+import org.apache.webbeans.xml.XMLAnnotationTypeManager;
+import org.apache.webbeans.xml.XMLSpecializesManager;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class WebBeansContext
+{
+
+    private OpenWebBeansConfiguration openWebBeansConfiguration = new OpenWebBeansConfiguration();
+    private AnnotatedElementFactory annotatedElementFactory = new AnnotatedElementFactory();
+    private BeanManagerImpl beanManagerImpl = new BeanManagerImpl(this);
+    private SerializableBeanVault serializableBeanVault = new SerializableBeanVault();
+    private CreationalContextFactory creationalContextFactory = new CreationalContextFactory();
+    private DefaultContextsService defaultContextsService = new DefaultContextsService();
+    private DefaultJndiService defaultJndiService = new DefaultJndiService();
+    private DefaultScannerService defaultScannerService = new DefaultScannerService();
+    private DecoratorsManager decoratorsManager = new DecoratorsManager();
+    private StereoTypeManager stereoTypeManager = new StereoTypeManager();
+    private AlternativesManager alternativesManager = new AlternativesManager();
+    private InterceptorsManager interceptorsManager = new InterceptorsManager();
+    private JMSManager jmsManager = new JMSManager();
+    private PluginLoader pluginLoader = new PluginLoader();
+    private ExtensionLoader extensionLoader = new ExtensionLoader();
+    private JavassistProxyFactory javassistProxyFactory = new JavassistProxyFactory();
+    private WebBeansNameSpaceContainer webBeansNameSpaceContainer = new WebBeansNameSpaceContainer();
+    private XMLAnnotationTypeManager xmlAnnotationTypeManager = new XMLAnnotationTypeManager();
+    private XMLSpecializesManager xmlSpecializesManager = new XMLSpecializesManager();
+
+    private final Map<String, Object> managerMap = new HashMap<String, Object>();
+
+    public WebBeansContext() {
+        // Add them all into the map for backwards compatibility
+        managerMap.put(OpenWebBeansConfiguration.class.getName(), openWebBeansConfiguration);
+        managerMap.put(BeanManagerImpl.class.getName(), beanManagerImpl);
+        managerMap.put(SerializableBeanVault.class.getName(), serializableBeanVault);
+        managerMap.put(CreationalContextFactory.class.getName(), creationalContextFactory);
+        managerMap.put(DefaultContextsService.class.getName(), defaultContextsService);
+        managerMap.put(DefaultJndiService.class.getName(), defaultJndiService);
+        managerMap.put(DefaultScannerService.class.getName(), defaultScannerService);
+        managerMap.put(DecoratorsManager.class.getName(), decoratorsManager);
+        managerMap.put(StereoTypeManager.class.getName(), stereoTypeManager);
+        managerMap.put(AlternativesManager.class.getName(), alternativesManager);
+        managerMap.put(InterceptorsManager.class.getName(), interceptorsManager);
+        managerMap.put(JMSManager.class.getName(), jmsManager);
+        managerMap.put(PluginLoader.class.getName(), pluginLoader);
+        managerMap.put(AnnotatedElementFactory.class.getName(), annotatedElementFactory);
+        managerMap.put(ExtensionLoader.class.getName(), extensionLoader);
+        managerMap.put(JavassistProxyFactory.class.getName(), javassistProxyFactory);
+        managerMap.put(WebBeansNameSpaceContainer.class.getName(), webBeansNameSpaceContainer);
+        managerMap.put(XMLAnnotationTypeManager.class.getName(), xmlAnnotationTypeManager);
+        managerMap.put(XMLSpecializesManager.class.getName(), xmlSpecializesManager);
+    }
+
+    public OpenWebBeansConfiguration getOpenWebBeansConfiguration()
+    {
+        return openWebBeansConfiguration;
+    }
+
+    public AnnotatedElementFactory getAnnotatedElementFactory()
+    {
+        return annotatedElementFactory;
+    }
+
+    public BeanManagerImpl getBeanManagerImpl()
+    {
+        return beanManagerImpl;
+    }
+
+    public SerializableBeanVault getSerializableBeanVault()
+    {
+        return serializableBeanVault;
+    }
+
+    public CreationalContextFactory getCreationalContextFactory()
+    {
+        return creationalContextFactory;
+    }
+
+    public DefaultContextsService getDefaultContextsService()
+    {
+        return defaultContextsService;
+    }
+
+    public DefaultJndiService getDefaultJndiService()
+    {
+        return defaultJndiService;
+    }
+
+    public DefaultScannerService getDefaultScannerService()
+    {
+        return defaultScannerService;
+    }
+
+    public DecoratorsManager getDecoratorsManager()
+    {
+        return decoratorsManager;
+    }
+
+    public StereoTypeManager getStereoTypeManager()
+    {
+        return stereoTypeManager;
+    }
+
+    public AlternativesManager getAlternativesManager()
+    {
+        return alternativesManager;
+    }
+
+    public InterceptorsManager getInterceptorsManager()
+    {
+        return interceptorsManager;
+    }
+
+    public JMSManager getjMSManager()
+    {
+        return jmsManager;
+    }
+
+    public PluginLoader getPluginLoader()
+    {
+        return pluginLoader;
+    }
+
+    public ExtensionLoader getExtensionLoader()
+    {
+        return extensionLoader;
+    }
+
+    public JavassistProxyFactory getJavassistProxyFactory()
+    {
+        return javassistProxyFactory;
+    }
+
+    public WebBeansNameSpaceContainer getWebBeansNameSpaceContainer()
+    {
+        return webBeansNameSpaceContainer;
+    }
+
+    public XMLAnnotationTypeManager getxMLAnnotationTypeManager()
+    {
+        return xmlAnnotationTypeManager;
+    }
+
+    public XMLSpecializesManager getxMLSpecializesManager()
+    {
+        return xmlSpecializesManager;
+    }
+
+    public Object get(String singletonName)
+    {
+
+        Object object = managerMap.get(singletonName);
+
+        /* No singleton for this application, create one */
+        if (object == null)
+        {
+            try
+            {
+                //Load class
+                Class<?> clazz = ClassUtil.getClassFromName(singletonName);
+                if (clazz == null)
+                {
+                    throw new ClassNotFoundException("Class with name: " + singletonName
+ " is not found in the system");
+                }
+
+                //Create instance
+                object = clazz.newInstance();
+
+                //Save it
+                managerMap.put(singletonName, object);
+
+            }
+            catch (InstantiationException e)
+            {
+                throw new WebBeansException("Unable to instantiate class : " + singletonName,
e);
+            }
+            catch (IllegalAccessException e)
+            {
+                throw new WebBeansException("Illegal access exception in creating instance
with class : " + singletonName, e);
+            }
+            catch (ClassNotFoundException e)
+            {
+                throw new WebBeansException("Class not found exception in creating instance
with class : " + singletonName, e);
+            }
+        }
+
+        return object;
+    }
+
+    public void clear()
+    {
+        managerMap.clear();
+    }
+}

Propchange: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/WebBeansContext.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/WebBeansFinder.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/WebBeansFinder.java?rev=1041634&r1=1041633&r2=1041634&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/WebBeansFinder.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/WebBeansFinder.java
Thu Dec  2 23:14:37 2010
@@ -67,7 +67,12 @@ public final class WebBeansFinder
     {
         singletonService.clear(key);
     }
-    
+
+    /**
+     * TODO Delete - only used one place
+     * @param singletonInstance
+     * @return
+     */
     public static Object getSingletonClassLoader(Object singletonInstance)
     {
         return singletonService.getKey(singletonInstance);

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/BeanManagerImpl.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/BeanManagerImpl.java?rev=1041634&r1=1041633&r2=1041634&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/BeanManagerImpl.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/BeanManagerImpl.java
Thu Dec  2 23:14:37 2010
@@ -62,6 +62,7 @@ import org.apache.webbeans.component.New
 import org.apache.webbeans.component.OwbBean;
 import org.apache.webbeans.component.WebBeansType;
 import org.apache.webbeans.component.third.ThirdpartyBeanImpl;
+import org.apache.webbeans.config.WebBeansContext;
 import org.apache.webbeans.config.WebBeansFinder;
 import org.apache.webbeans.context.ContextFactory;
 import org.apache.webbeans.context.creational.CreationalContextFactory;
@@ -188,11 +189,11 @@ public class BeanManagerImpl implements 
      * Called by the system. Do not use outside of the
      * system.
      */
-    public BeanManagerImpl()
+    public BeanManagerImpl(WebBeansContext webBeansContext)
     {
         injectionResolver = new InjectionResolver(this);
         notificationManager = new NotificationManager();
-        annotatedElementFactory = AnnotatedElementFactory.getInstance();
+        annotatedElementFactory = webBeansContext.getAnnotatedElementFactory();
     }    
     
     public <T> void putInjectionTargetWrapper(Contextual<T> contextual, InjectionTargetWrapper<T>
wrapper)

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/corespi/DefaultSingletonService.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/corespi/DefaultSingletonService.java?rev=1041634&r1=1041633&r2=1041634&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/corespi/DefaultSingletonService.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/corespi/DefaultSingletonService.java
Thu Dec  2 23:14:37 2010
@@ -19,16 +19,13 @@
 package org.apache.webbeans.corespi;
 
 import java.lang.ref.WeakReference;
-import java.util.HashMap;
 import java.util.IdentityHashMap;
 import java.util.Map;
-import java.util.Map.Entry;
 import java.util.WeakHashMap;
 
-import org.apache.webbeans.exception.WebBeansException;
+import org.apache.webbeans.config.WebBeansContext;
 import org.apache.webbeans.spi.SingletonService;
 import org.apache.webbeans.util.Asserts;
-import org.apache.webbeans.util.ClassUtil;
 import org.apache.webbeans.util.WebBeansUtil;
 
 public class DefaultSingletonService implements SingletonService 
@@ -37,7 +34,7 @@ public class DefaultSingletonService imp
      * Keys --> ClassLoaders
      * Values --> Maps of singleton class name with object
      */
-    private final Map<ClassLoader, Map<String, Object>> singletonMap = new WeakHashMap<ClassLoader,
Map<String,Object>>();
+    private final Map<ClassLoader, WebBeansContext> singletonMap = new WeakHashMap<ClassLoader,
WebBeansContext>();
     
     private final Map<Object, WeakReference<ClassLoader>> objectToClassLoaderMap
= new IdentityHashMap<Object, WeakReference<ClassLoader>>();
 
@@ -64,50 +61,18 @@ public class DefaultSingletonService imp
 
         synchronized (singletonMap)
         {
-            Map<String, Object> managerMap = singletonMap.get(classLoader);
+            WebBeansContext managerMap = singletonMap.get(classLoader);
 
             if (managerMap == null)
             {
-                managerMap = new HashMap<String, Object>();
+                managerMap = new WebBeansContext();
                 singletonMap.put(classLoader, managerMap);
             }
-            
+
+            // WebBeansContext never returns null
             object = managerMap.get(singletonName);
-            /* No singleton for this application, create one */
-            if (object == null)
-            {
-                try
-                {
-                    //Load class
-                    Class<?> clazz = ClassUtil.getClassFromName(singletonName);
-                    if(clazz == null)
-                    {
-                        throw new ClassNotFoundException("Class with name: " + singletonName
+ " is not found in the system");
-                    }
-                    
-                    //Create instance
-                    object = clazz.newInstance();
-
-                    //Save it
-                    managerMap.put(singletonName, object);
-                    
-                    //Save it object --> classloader
-                    objectToClassLoaderMap.put(object, new WeakReference<ClassLoader>(classLoader));
 
-                }
-                catch (InstantiationException e)
-                {
-                    throw new WebBeansException("Unable to instantiate class : " + singletonName,
e);
-                }
-                catch (IllegalAccessException e)
-                {
-                    throw new WebBeansException("Illegal access exception in creating instance
with class : " + singletonName, e);
-                }
-                catch (ClassNotFoundException e)
-                {
-                    throw new WebBeansException("Class not found exception in creating instance
with class : " + singletonName, e);
-                }
-            }
+            objectToClassLoaderMap.put(object, new WeakReference<ClassLoader>(classLoader));
         }
 
         return object;
@@ -121,20 +86,7 @@ public class DefaultSingletonService imp
      */
     public Object getExistingSingletonInstance(String singletonName, ClassLoader cl)
     {
-        Object object = null;
-        synchronized (singletonMap)
-        {
-            Map<String, Object> managerMap = singletonMap.get(cl);
-            if (managerMap == null)
-            {
-                return null;
-            }
-            else
-            {
-                object = managerMap.get(singletonName);
-            }
-        }
-        return object;
+        throw new UnsupportedOperationException("getExistingSingletonInstance is never used");
     }
     
     /**
@@ -146,14 +98,7 @@ public class DefaultSingletonService imp
         Asserts.assertNotNull(classLoader, "classloader is null");
         synchronized (singletonMap)
         {
-            Map<String, Object> objects = singletonMap.remove(classLoader);
-            if(objects != null)
-            {
-                for(Entry<String, Object> entry : objects.entrySet())
-                {
-                    objectToClassLoaderMap.remove(entry.getValue());
-                }
-            }
+            singletonMap.remove(classLoader);
         }
     }
     



Mime
View raw message