deltaspike-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From strub...@apache.org
Subject deltaspike git commit: DELTASPIKE-1125 make ParentExtension mechanism configurable
Date Mon, 11 Apr 2016 09:57:34 GMT
Repository: deltaspike
Updated Branches:
  refs/heads/master 16b77919b -> 2abbba651


DELTASPIKE-1125 make ParentExtension mechanism configurable

The feature is now off by default.
If you run DeltaSpike in e.g. an EAR on TomEE you might configure
deltaspike.parent.extension.enabled=true


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

Branch: refs/heads/master
Commit: 2abbba651ff386d67cedd96e6d8efba942b37841
Parents: 16b7791
Author: Mark Struberg <struberg@apache.org>
Authored: Mon Apr 11 10:59:38 2016 +0200
Committer: Mark Struberg <struberg@apache.org>
Committed: Mon Apr 11 11:01:27 2016 +0200

----------------------------------------------------------------------
 .../core/util/ParentExtensionStorage.java       | 48 +++++++++++++++-----
 1 file changed, 36 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/deltaspike/blob/2abbba65/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/util/ParentExtensionStorage.java
----------------------------------------------------------------------
diff --git a/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/util/ParentExtensionStorage.java
b/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/util/ParentExtensionStorage.java
index 6e1f044..00bf3ad 100644
--- a/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/util/ParentExtensionStorage.java
+++ b/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/util/ParentExtensionStorage.java
@@ -25,6 +25,8 @@ import java.util.HashSet;
 import java.util.Iterator;
 import java.util.Set;
 
+import org.apache.deltaspike.core.api.config.ConfigResolver;
+
 /**
  * Support for Containers with 'hierarchic BeanManagers'
  * This is mostly useful for EAR applications.
@@ -38,6 +40,10 @@ import java.util.Set;
  * To acknowledge this solution we provide a mechanism to lookup 'parent Extensions'
  * which is very similar to handling parent ClassLoaders.
  *
+ * Please note that you need to enable this handling if you are running DeltaSpike
+ * in an EAR on a container which supports parent Extensions.
+ * You can do that by settting {@link #CONFIG_ENABLE_PARENT_EXTENSION} to &quote;true&quote;
+ *
  * All your Extension has to do is to register itself in
  * {@link javax.enterprise.inject.spi.BeforeBeanDiscovery}.
  * Later at boot time the Extension can lookup it's parent Extension instance and
@@ -47,6 +53,10 @@ import java.util.Set;
  */
 public final class ParentExtensionStorage
 {
+    /**
+     * Enable DeltaSpike ParentExtension handling by setting this configuration option to
&quote;true&quote;
+     */
+    public static final String CONFIG_ENABLE_PARENT_EXTENSION = "deltaspike.parent.extension.enabled";
 
     private static Set<ExtensionStorageInfo> extensionStorage = new HashSet<ExtensionStorageInfo>();
 
@@ -61,16 +71,27 @@ public final class ParentExtensionStorage
      */
     public static synchronized void addExtension(Extension extension)
     {
-        removeAbandonedExtensions();
+        if (usingParentExtension())
+        {
+            removeAbandonedExtensions();
 
-        ClassLoader classLoader = ClassUtils.getClassLoader(null);
-        extensionStorage.add(new ExtensionStorageInfo(classLoader, extension));
+            ClassLoader classLoader = ClassUtils.getClassLoader(null);
+            extensionStorage.add(new ExtensionStorageInfo(classLoader, extension));
+        }
     }
 
     /**
      * When adding a new Extension we also clean up ExtensionInfos
      * from ClassLoaders which got unloaded.
      */
+
+    private static boolean usingParentExtension()
+    {
+        final boolean usingParentExtension =
+            Boolean.parseBoolean(ConfigResolver.getPropertyValue(CONFIG_ENABLE_PARENT_EXTENSION));
+        return usingParentExtension;
+    }
+
     private static void removeAbandonedExtensions()
     {
         Iterator<ExtensionStorageInfo> it = extensionStorage.iterator();
@@ -89,17 +110,20 @@ public final class ParentExtensionStorage
      */
     public static synchronized <T extends Extension> T getParentExtension(Extension
extension)
     {
-        ClassLoader parentClassLoader = ClassUtils.getClassLoader(null).getParent();
-
-        Iterator<ExtensionStorageInfo> extIt = extensionStorage.iterator();
-        while (extIt.hasNext())
+        if (usingParentExtension())
         {
-            ExtensionStorageInfo extensionInfo = extIt.next();
-            if (!extensionInfo.isAbandoned() && // weak reference case
-                extension.getClass().equals(extensionInfo.getExtension().getClass()) &&
-                extensionInfo.getClassLoader().equals(parentClassLoader))
+            ClassLoader parentClassLoader = ClassUtils.getClassLoader(null).getParent();
+
+            Iterator<ExtensionStorageInfo> extIt = extensionStorage.iterator();
+            while (extIt.hasNext())
             {
-                return (T) extensionInfo.getExtension();
+                ExtensionStorageInfo extensionInfo = extIt.next();
+                if (!extensionInfo.isAbandoned() && // weak reference case
+                    extension.getClass().equals(extensionInfo.getExtension().getClass())
&&
+                    extensionInfo.getClassLoader().equals(parentClassLoader))
+                {
+                    return (T) extensionInfo.getExtension();
+                }
             }
         }
         return null;


Mime
View raw message