deltaspike-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From strub...@apache.org
Subject git commit: DELTASPIKE-375 improve performance and use internal ClassUtils common code
Date Mon, 17 Jun 2013 08:40:42 GMT
Updated Branches:
  refs/heads/master ee00aab11 -> eb526e50a


DELTASPIKE-375 improve performance and use internal ClassUtils common code


Project: http://git-wip-us.apache.org/repos/asf/deltaspike/repo
Commit: http://git-wip-us.apache.org/repos/asf/deltaspike/commit/eb526e50
Tree: http://git-wip-us.apache.org/repos/asf/deltaspike/tree/eb526e50
Diff: http://git-wip-us.apache.org/repos/asf/deltaspike/diff/eb526e50

Branch: refs/heads/master
Commit: eb526e50a1925a11412e256f598ff787c42d2950
Parents: ee00aab
Author: Mark Struberg <struberg@apache.org>
Authored: Mon Jun 17 08:22:20 2013 +0200
Committer: Mark Struberg <struberg@apache.org>
Committed: Mon Jun 17 08:23:04 2013 +0200

----------------------------------------------------------------------
 .../servlet/impl/event/EventEmitter.java        | 24 ++++++++++++++++----
 .../impl/produce/ServletContextHolder.java      | 18 ++++-----------
 2 files changed, 24 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/deltaspike/blob/eb526e50/deltaspike/modules/servlet/impl/src/main/java/org/apache/deltaspike/servlet/impl/event/EventEmitter.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/servlet/impl/src/main/java/org/apache/deltaspike/servlet/impl/event/EventEmitter.java
b/deltaspike/modules/servlet/impl/src/main/java/org/apache/deltaspike/servlet/impl/event/EventEmitter.java
index 899e3f7..7ef367d 100644
--- a/deltaspike/modules/servlet/impl/src/main/java/org/apache/deltaspike/servlet/impl/event/EventEmitter.java
+++ b/deltaspike/modules/servlet/impl/src/main/java/org/apache/deltaspike/servlet/impl/event/EventEmitter.java
@@ -18,6 +18,7 @@
  */
 package org.apache.deltaspike.servlet.impl.event;
 
+import javax.enterprise.inject.spi.BeanManager;
 import java.lang.annotation.Annotation;
 
 import org.apache.deltaspike.core.api.provider.BeanManagerProvider;
@@ -30,14 +31,27 @@ import org.apache.deltaspike.core.api.provider.BeanManagerProvider;
  */
 abstract class EventEmitter
 {
+    private volatile BeanManager beanManager;
 
     protected void fireEvent(Object event, Annotation... qualifier)
     {
-        /*
-         * No need to cache the BeanManager reference because the providers already does
this on a context class loader
-         * level.
-         */
-        BeanManagerProvider.getInstance().getBeanManager().fireEvent(event, qualifier);
+        getBeanManager().fireEvent(event, qualifier);
+    }
+
+    protected BeanManager getBeanManager()
+    {
+        if (beanManager == null)
+        {
+            synchronized (this)
+            {
+                if (beanManager == null)
+                {
+                    beanManager = BeanManagerProvider.getInstance().getBeanManager();
+                }
+            }
+        }
+
+        return beanManager;
     }
 
 }

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/eb526e50/deltaspike/modules/servlet/impl/src/main/java/org/apache/deltaspike/servlet/impl/produce/ServletContextHolder.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/servlet/impl/src/main/java/org/apache/deltaspike/servlet/impl/produce/ServletContextHolder.java
b/deltaspike/modules/servlet/impl/src/main/java/org/apache/deltaspike/servlet/impl/produce/ServletContextHolder.java
index 14044d8..1d4f292 100644
--- a/deltaspike/modules/servlet/impl/src/main/java/org/apache/deltaspike/servlet/impl/produce/ServletContextHolder.java
+++ b/deltaspike/modules/servlet/impl/src/main/java/org/apache/deltaspike/servlet/impl/produce/ServletContextHolder.java
@@ -25,6 +25,8 @@ import java.util.logging.Logger;
 
 import javax.servlet.ServletContext;
 
+import org.apache.deltaspike.core.util.ClassUtils;
+
 /**
  * This class holds the {@link ServletContext} for each context class loader.
  * 
@@ -52,7 +54,7 @@ class ServletContextHolder
      */
     static void bind(ServletContext servletContext)
     {
-        ClassLoader classLoader = getContextClassLoader();
+        ClassLoader classLoader = ClassUtils.getClassLoader(null);
         ServletContext existingContext = CONTEXT_BY_CLASSLOADER.put(classLoader, servletContext);
         if (existingContext != null)
         {
@@ -69,7 +71,7 @@ class ServletContextHolder
      */
     static ServletContext get()
     {
-        ClassLoader classLoader = getContextClassLoader();
+        ClassLoader classLoader = ClassUtils.getClassLoader(null);
         ServletContext servletContext = CONTEXT_BY_CLASSLOADER.get(classLoader);
         if (servletContext == null)
         {
@@ -84,7 +86,7 @@ class ServletContextHolder
      */
     static void release()
     {
-        ClassLoader classLoader = getContextClassLoader();
+        ClassLoader classLoader = ClassUtils.getClassLoader(null);
         ServletContext removedContext = CONTEXT_BY_CLASSLOADER.remove(classLoader);
         if (removedContext == null)
         {
@@ -92,14 +94,4 @@ class ServletContextHolder
         }
     }
 
-    private static ClassLoader getContextClassLoader()
-    {
-        ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
-        if (classLoader == null)
-        {
-            throw new IllegalStateException("Unable to obtain the context class loader for
the current thread");
-        }
-        return classLoader;
-    }
-
 }


Mime
View raw message