tomee-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rmannibu...@apache.org
Subject tomee git commit: TOMEE-2016 ensure we use the right app classloader in batchee even if coming from a cxf container loader (rest)
Date Mon, 13 Feb 2017 13:51:54 GMT
Repository: tomee
Updated Branches:
  refs/heads/master 51bf8b649 -> ebe3b7232


TOMEE-2016 ensure we use the right app classloader in batchee even if coming from a cxf container
loader (rest)


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

Branch: refs/heads/master
Commit: ebe3b7232f0b364c64c44efeef64e807234c8f36
Parents: 51bf8b6
Author: rmannibucau <rmannibucau@apache.org>
Authored: Mon Feb 13 14:50:39 2017 +0100
Committer: rmannibucau <rmannibucau@apache.org>
Committed: Mon Feb 13 14:50:39 2017 +0100

----------------------------------------------------------------------
 .../openejb/batchee/BatchEEServiceManager.java  | 32 +++++++++++++++++++-
 .../openejb/util/classloader/Unwrappable.java   | 21 +++++++++++++
 .../transport/util/CxfContainerClassLoader.java |  9 +++++-
 3 files changed, 60 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tomee/blob/ebe3b723/container/openejb-core/src/main/java/org/apache/openejb/batchee/BatchEEServiceManager.java
----------------------------------------------------------------------
diff --git a/container/openejb-core/src/main/java/org/apache/openejb/batchee/BatchEEServiceManager.java
b/container/openejb-core/src/main/java/org/apache/openejb/batchee/BatchEEServiceManager.java
index 09aecc8..096861c 100644
--- a/container/openejb-core/src/main/java/org/apache/openejb/batchee/BatchEEServiceManager.java
+++ b/container/openejb-core/src/main/java/org/apache/openejb/batchee/BatchEEServiceManager.java
@@ -18,14 +18,17 @@ package org.apache.openejb.batchee;
 
 import org.apache.batchee.container.services.ServicesManager;
 import org.apache.batchee.container.services.ServicesManagerLocator;
+import org.apache.batchee.container.services.executor.DefaultThreadPoolService;
 import org.apache.batchee.container.services.factory.CDIBatchArtifactFactory;
 import org.apache.batchee.spi.BatchArtifactFactory;
+import org.apache.batchee.spi.BatchThreadPoolService;
 import org.apache.openejb.AppContext;
 import org.apache.openejb.assembler.classic.event.AssemblerAfterApplicationCreated;
 import org.apache.openejb.loader.SystemInstance;
 import org.apache.openejb.observer.Observes;
 import org.apache.openejb.observer.event.ObserverAdded;
 import org.apache.openejb.util.AppFinder;
+import org.apache.openejb.util.classloader.Unwrappable;
 import org.apache.webbeans.config.WebBeansContext;
 
 import javax.enterprise.inject.spi.BeanManager;
@@ -48,6 +51,9 @@ public class BatchEEServiceManager implements ServicesManagerLocator {
         final ServicesManager servicesManager = new ServicesManager();
         try {
             if (properties.getProperty(BatchArtifactFactory.class.getName()) == null) {
+                properties.setProperty(BatchThreadPoolService.class.getName(), TomEEThreadPoolService.class.getName());
+            }
+            if (properties.getProperty(BatchArtifactFactory.class.getName()) == null) {
                 properties.setProperty(BatchArtifactFactory.class.getName(), TomEEArtifactFactory.class.getName());
             }
             servicesManager.init(properties); // will look for batchee.properties so need
the right classloader
@@ -60,7 +66,7 @@ public class BatchEEServiceManager implements ServicesManagerLocator {
 
     @Override
     public ServicesManager find() {
-        final ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
+        final ClassLoader contextClassLoader = unwrap(Thread.currentThread().getContextClassLoader());
         final AppContext context = AppFinder.findAppContextOrWeb(contextClassLoader, AppFinder.AppContextTransformer.INSTANCE);
         if (context != null) {
             return context.get(ServicesManager.class);
@@ -68,10 +74,34 @@ public class BatchEEServiceManager implements ServicesManagerLocator {
         throw new IllegalStateException("Can't find ServiceManager for " + contextClassLoader);
     }
 
+    private static ClassLoader unwrap(final ClassLoader tccl) {
+        if (Unwrappable.class.isInstance(tccl)) {
+            final ClassLoader unwrapped = Unwrappable.class.cast(tccl).unwrap();
+            if (unwrapped != null) {
+                return unwrapped;
+            }
+        }
+        return tccl;
+    }
+
     public static class TomEEArtifactFactory extends CDIBatchArtifactFactory {
         @Override
         protected BeanManager getBeanManager() {
             return WebBeansContext.currentInstance().getBeanManagerImpl();
         }
     }
+
+    public static class TomEEThreadPoolService extends DefaultThreadPoolService {
+        @Override
+        public void executeTask(final Runnable work, final Object config) {
+            final Thread thread = Thread.currentThread();
+            final ClassLoader tccl = thread.getContextClassLoader();
+            thread.setContextClassLoader(unwrap(tccl));
+            try {
+                super.executeTask(work, config);
+            } finally {
+                thread.setContextClassLoader(tccl);
+            }
+        }
+    }
 }

http://git-wip-us.apache.org/repos/asf/tomee/blob/ebe3b723/container/openejb-core/src/main/java/org/apache/openejb/util/classloader/Unwrappable.java
----------------------------------------------------------------------
diff --git a/container/openejb-core/src/main/java/org/apache/openejb/util/classloader/Unwrappable.java
b/container/openejb-core/src/main/java/org/apache/openejb/util/classloader/Unwrappable.java
new file mode 100644
index 0000000..79812bb
--- /dev/null
+++ b/container/openejb-core/src/main/java/org/apache/openejb/util/classloader/Unwrappable.java
@@ -0,0 +1,21 @@
+/*
+ * 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.openejb.util.classloader;
+
+public interface Unwrappable {
+    ClassLoader unwrap();
+}

http://git-wip-us.apache.org/repos/asf/tomee/blob/ebe3b723/server/openejb-cxf-transport/src/main/java/org/apache/openejb/server/cxf/transport/util/CxfContainerClassLoader.java
----------------------------------------------------------------------
diff --git a/server/openejb-cxf-transport/src/main/java/org/apache/openejb/server/cxf/transport/util/CxfContainerClassLoader.java
b/server/openejb-cxf-transport/src/main/java/org/apache/openejb/server/cxf/transport/util/CxfContainerClassLoader.java
index 8961a17..d16a4bb 100644
--- a/server/openejb-cxf-transport/src/main/java/org/apache/openejb/server/cxf/transport/util/CxfContainerClassLoader.java
+++ b/server/openejb-cxf-transport/src/main/java/org/apache/openejb/server/cxf/transport/util/CxfContainerClassLoader.java
@@ -16,11 +16,13 @@
  */
 package org.apache.openejb.server.cxf.transport.util;
 
+import org.apache.openejb.util.classloader.Unwrappable;
+
 import java.io.IOException;
 import java.net.URL;
 import java.util.Enumeration;
 
-public class CxfContainerClassLoader extends ClassLoader {
+public class CxfContainerClassLoader extends ClassLoader implements Unwrappable {
     private static final ClassLoader CONTAINER_LOADER = CxfUtil.class.getClassLoader();
     public static final String CXF_PACKAGE = "org.apache.cxf.";
 
@@ -129,4 +131,9 @@ public class CxfContainerClassLoader extends ClassLoader {
         }
         return classLoader.hashCode();
     }
+
+    @Override
+    public ClassLoader unwrap() {
+        return tccl();
+    }
 }


Mime
View raw message