You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@batchee.apache.org by rm...@apache.org on 2014/03/30 20:43:19 UTC

git commit: BATCHEE616 removing OpenEJBJobOperatorClassLoaderFinder

Repository: incubator-batchee
Updated Branches:
  refs/heads/master 6f9c3c35c -> 2523e389a


BATCHEE616 removing OpenEJBJobOperatorClassLoaderFinder


Project: http://git-wip-us.apache.org/repos/asf/incubator-batchee/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-batchee/commit/2523e389
Tree: http://git-wip-us.apache.org/repos/asf/incubator-batchee/tree/2523e389
Diff: http://git-wip-us.apache.org/repos/asf/incubator-batchee/diff/2523e389

Branch: refs/heads/master
Commit: 2523e389aceabf3beb8678333c7ec04af11e8c6e
Parents: 6f9c3c3
Author: Romain Manni-Bucau <rm...@gmail.com>
Authored: Sun Mar 30 20:43:04 2014 +0200
Committer: Romain Manni-Bucau <rm...@gmail.com>
Committed: Sun Mar 30 20:43:04 2014 +0200

----------------------------------------------------------------------
 gui/servlet/pom.xml                             |  7 --
 .../batchee/servlet/JBatchController.java       | 55 +-------------
 .../spi/JobOperatorClassLoaderFinder.java       | 26 -------
 .../OpenEJBJobOperatorClassLoaderFinder.java    | 75 --------------------
 4 files changed, 1 insertion(+), 162 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-batchee/blob/2523e389/gui/servlet/pom.xml
----------------------------------------------------------------------
diff --git a/gui/servlet/pom.xml b/gui/servlet/pom.xml
index 3fa6bd3..7c42298 100644
--- a/gui/servlet/pom.xml
+++ b/gui/servlet/pom.xml
@@ -48,13 +48,6 @@
     </dependency>
 
     <dependency>
-      <groupId>org.apache.openejb</groupId>
-      <artifactId>openejb-core</artifactId>
-      <version>4.6.0</version>
-      <scope>provided</scope>
-    </dependency>
-
-    <dependency>
       <groupId>org.apache.cxf</groupId>
       <artifactId>cxf-rt-frontend-jaxrs</artifactId>
     </dependency>

http://git-wip-us.apache.org/repos/asf/incubator-batchee/blob/2523e389/gui/servlet/src/main/java/org/apache/batchee/servlet/JBatchController.java
----------------------------------------------------------------------
diff --git a/gui/servlet/src/main/java/org/apache/batchee/servlet/JBatchController.java b/gui/servlet/src/main/java/org/apache/batchee/servlet/JBatchController.java
index cbd119b..87cf32b 100644
--- a/gui/servlet/src/main/java/org/apache/batchee/servlet/JBatchController.java
+++ b/gui/servlet/src/main/java/org/apache/batchee/servlet/JBatchController.java
@@ -16,8 +16,6 @@
  */
 package org.apache.batchee.servlet;
 
-import org.apache.batchee.servlet.spi.JobOperatorClassLoaderFinder;
-
 import javax.batch.operations.BatchRuntimeException;
 import javax.batch.operations.JobExecutionNotRunningException;
 import javax.batch.operations.JobOperator;
@@ -35,9 +33,6 @@ import java.io.ByteArrayOutputStream;
 import java.io.FileNotFoundException;
 import java.io.IOException;
 import java.io.InputStream;
-import java.lang.reflect.InvocationHandler;
-import java.lang.reflect.Method;
-import java.lang.reflect.Proxy;
 import java.net.URLDecoder;
 import java.util.ArrayList;
 import java.util.Collections;
@@ -60,15 +55,12 @@ public class JBatchController extends HttpServlet {
     private static final String START_MAPPING = "/start/";
     private static final String DO_START_MAPPING = "/doStart/";
     private static final String VIEW_MAPPING = "/view/";
-    public static final String BATCHEE_CLASSLOADER_FINDER_KEY = "batchee.classloader-finder";
 
     private JobOperator operator;
 
     private String context;
     private String mapping = DEFAULT_MAPPING_SERVLET25;
     private int executionByPage = DEFAULT_PAGE_SIZE;
-    private ClassLoader controllerLoader;
-    private JobOperatorClassLoaderFinder classLoaderFinder;
 
     public JBatchController mapping(final String rawMapping) {
         this.mapping = rawMapping.substring(0, rawMapping.length() - 2); // mapping pattern is /xxx/*
@@ -82,29 +74,7 @@ public class JBatchController extends HttpServlet {
 
     @Override
     public void init(final ServletConfig config) throws ServletException {
-        controllerLoader = Thread.currentThread().getContextClassLoader();
-
-        final JobOperator delegate = BatchRuntime.getJobOperator();
-        classLoaderFinder = newClassLoaderFinder(
-                System.getProperty(BATCHEE_CLASSLOADER_FINDER_KEY, config.getInitParameter(BATCHEE_CLASSLOADER_FINDER_KEY)),
-                controllerLoader);
-
-        this.operator = JobOperator.class.cast(Proxy.newProxyInstance(
-                controllerLoader,
-                new Class<?>[] { JobOperator.class },
-                new InvocationHandler() {
-                    @Override
-                    public Object invoke(final Object proxy, final Method method, final Object[] args) throws Throwable {
-                        final Thread thread = Thread.currentThread();
-                        final ClassLoader original = thread.getContextClassLoader();
-                        thread.setContextClassLoader(findLoaderToUse(original, method.getName(), args));
-                        try {
-                            return method.invoke(delegate, args);
-                        } finally {
-                            thread.setContextClassLoader(original);
-                        }
-                    }
-                }));
+        this.operator = BatchRuntime.getJobOperator();
 
         this.context = config.getServletContext().getContextPath();
         if ("/".equals(context)) {
@@ -114,29 +84,6 @@ public class JBatchController extends HttpServlet {
         mapping = context + mapping;
     }
 
-    private JobOperatorClassLoaderFinder newClassLoaderFinder(final String initParameter, final ClassLoader webappLoader) {
-        if (initParameter == null) {
-            return null;
-        }
-        try {
-            return JobOperatorClassLoaderFinder.class.cast(
-                    controllerLoader.loadClass(initParameter.trim()).getConstructor(ClassLoader.class)
-                            .newInstance(webappLoader));
-        } catch (final Exception e) {
-            throw new BatchRuntimeException(e.getMessage(), e);
-        }
-    }
-
-    protected ClassLoader findLoaderToUse(final ClassLoader original, String name, Object[] args) {
-        if (classLoaderFinder != null) {
-            final ClassLoader found = classLoaderFinder.find(name, args);
-            if (found != null) {
-                return found;
-            }
-        }
-        return original;
-    }
-
     @Override
     protected void service(final HttpServletRequest req, final HttpServletResponse resp) throws ServletException, IOException {
         resp.setContentType("text/html");

http://git-wip-us.apache.org/repos/asf/incubator-batchee/blob/2523e389/gui/servlet/src/main/java/org/apache/batchee/servlet/spi/JobOperatorClassLoaderFinder.java
----------------------------------------------------------------------
diff --git a/gui/servlet/src/main/java/org/apache/batchee/servlet/spi/JobOperatorClassLoaderFinder.java b/gui/servlet/src/main/java/org/apache/batchee/servlet/spi/JobOperatorClassLoaderFinder.java
deleted file mode 100644
index f1f715d..0000000
--- a/gui/servlet/src/main/java/org/apache/batchee/servlet/spi/JobOperatorClassLoaderFinder.java
+++ /dev/null
@@ -1,26 +0,0 @@
-/*
- * 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.batchee.servlet.spi;
-
-public interface JobOperatorClassLoaderFinder {
-    /**
-     * @param name JobOperator method
-     * @param args arguments of the method
-     * @return
-     */
-    ClassLoader find(String name, Object[] args);
-}

http://git-wip-us.apache.org/repos/asf/incubator-batchee/blob/2523e389/gui/servlet/src/main/java/org/apache/batchee/servlet/spi/internal/OpenEJBJobOperatorClassLoaderFinder.java
----------------------------------------------------------------------
diff --git a/gui/servlet/src/main/java/org/apache/batchee/servlet/spi/internal/OpenEJBJobOperatorClassLoaderFinder.java b/gui/servlet/src/main/java/org/apache/batchee/servlet/spi/internal/OpenEJBJobOperatorClassLoaderFinder.java
deleted file mode 100644
index e65b620..0000000
--- a/gui/servlet/src/main/java/org/apache/batchee/servlet/spi/internal/OpenEJBJobOperatorClassLoaderFinder.java
+++ /dev/null
@@ -1,75 +0,0 @@
-/*
- * 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.batchee.servlet.spi.internal;
-
-import org.apache.batchee.servlet.spi.JobOperatorClassLoaderFinder;
-import org.apache.openejb.AppContext;
-import org.apache.openejb.loader.SystemInstance;
-import org.apache.openejb.spi.ContainerSystem;
-
-import java.util.List;
-import java.util.Properties;
-
-// simple impl taking just *the* other app if tomee deploys a single application
-// or a specific one if you specifiy in properties batchee.application
-//
-// side note: it needs the persistence to be shared accross apps (case in a server or with database usage)
-public class OpenEJBJobOperatorClassLoaderFinder implements JobOperatorClassLoaderFinder {
-    private static final String BATCHEE_APPLICATION = "batchee.application";
-
-    private final ClassLoader ignoreLoader;
-
-    public OpenEJBJobOperatorClassLoaderFinder(final ClassLoader ignoreLoader) {
-        this.ignoreLoader = ignoreLoader;
-    }
-
-    @Override
-    public ClassLoader find(final String name, final Object[] args) {
-        final String idToFind = extractId(name, args);
-
-        ClassLoader potentialLoader = null;
-
-        final List<AppContext> appContexts = SystemInstance.get().getComponent(ContainerSystem.class).getAppContexts();
-        for (final AppContext app : appContexts) {
-            final  String id = app.getId();
-            if ("tomee".equals(id) || "openejb".equals(id)) {
-                continue;
-            }
-
-            potentialLoader = app.getClassLoader();
-            if (potentialLoader == ignoreLoader) {
-                continue;
-            }
-
-            if (id.equals(idToFind)) {
-                return potentialLoader;
-            }
-        }
-        return potentialLoader;
-    }
-
-    private String extractId(final String name, final Object[] args) {
-        if (args != null) {
-            for (final Object o : args) {
-                if (Properties.class.isInstance(o)) {
-                    return Properties.class.cast(o).getProperty(BATCHEE_APPLICATION);
-                }
-            }
-        }
-        return null;
-    }
-}