You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@batchee.apache.org by st...@apache.org on 2014/07/09 23:45:13 UTC

git commit: BATCHEE-46 improve boot problem logging

Repository: incubator-batchee
Updated Branches:
  refs/heads/master cd766e032 -> adb3d5505


BATCHEE-46 improve boot problem logging


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

Branch: refs/heads/master
Commit: adb3d550524f5fd510d34d24578447ffef28924e
Parents: cd766e0
Author: Mark Struberg <st...@apache.org>
Authored: Wed Jul 9 23:44:33 2014 +0200
Committer: Mark Struberg <st...@apache.org>
Committed: Wed Jul 9 23:44:33 2014 +0200

----------------------------------------------------------------------
 .../batchee/container/impl/JobOperatorImpl.java | 21 +++++---
 .../container/services/ServicesManager.java     | 50 ++++++++++++++++----
 .../apache/batchee/jmx/BatchEEMBeanImpl.java    |  2 +-
 3 files changed, 56 insertions(+), 17 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-batchee/blob/adb3d550/jbatch/src/main/java/org/apache/batchee/container/impl/JobOperatorImpl.java
----------------------------------------------------------------------
diff --git a/jbatch/src/main/java/org/apache/batchee/container/impl/JobOperatorImpl.java b/jbatch/src/main/java/org/apache/batchee/container/impl/JobOperatorImpl.java
index a64249f..4003d6d 100755
--- a/jbatch/src/main/java/org/apache/batchee/container/impl/JobOperatorImpl.java
+++ b/jbatch/src/main/java/org/apache/batchee/container/impl/JobOperatorImpl.java
@@ -57,11 +57,15 @@ import java.util.List;
 import java.util.Map;
 import java.util.Properties;
 import java.util.Set;
+import java.util.logging.Level;
+import java.util.logging.Logger;
 
 import static org.apache.batchee.container.util.ClassLoaderAwareHandler.makeLoaderAware;
 
 
 public class JobOperatorImpl implements JobOperator {
+    private static final Logger LOGGER = Logger.getLogger(JobOperatorImpl.class.getName());
+
     static {
         Init.doInit();
 
@@ -111,12 +115,17 @@ public class JobOperatorImpl implements JobOperator {
 
     public JobOperatorImpl() {
         final ServicesManager servicesManager = ServicesManager.find();
-        kernelService = servicesManager.service(BatchKernelService.class);
-        persistenceManagerService = servicesManager.service(PersistenceManagerService.class);
-        xmlLoaderService = servicesManager.service(JobXMLLoaderService.class);
-        statusManagerService = servicesManager.service(JobStatusManagerService.class);
-        securityService = servicesManager.service(SecurityService.class);
-        callbackService = servicesManager.service(JobExecutionCallbackService.class);
+        try {
+            kernelService = servicesManager.service(BatchKernelService.class);
+            persistenceManagerService = servicesManager.service(PersistenceManagerService.class);
+            xmlLoaderService = servicesManager.service(JobXMLLoaderService.class);
+            statusManagerService = servicesManager.service(JobStatusManagerService.class);
+            securityService = servicesManager.service(SecurityService.class);
+            callbackService = servicesManager.service(JobExecutionCallbackService.class);
+        } catch (RuntimeException e) {
+            LOGGER.log(Level.SEVERE, "Error while booting BatchEE", e);
+            throw e;
+        }
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/incubator-batchee/blob/adb3d550/jbatch/src/main/java/org/apache/batchee/container/services/ServicesManager.java
----------------------------------------------------------------------
diff --git a/jbatch/src/main/java/org/apache/batchee/container/services/ServicesManager.java b/jbatch/src/main/java/org/apache/batchee/container/services/ServicesManager.java
index f094129..7b38fd5 100755
--- a/jbatch/src/main/java/org/apache/batchee/container/services/ServicesManager.java
+++ b/jbatch/src/main/java/org/apache/batchee/container/services/ServicesManager.java
@@ -43,6 +43,7 @@ import org.apache.batchee.spi.TransactionManagementService;
 import java.io.IOException;
 import java.io.InputStream;
 import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
 import java.util.Map;
 import java.util.Properties;
 import java.util.concurrent.ConcurrentHashMap;
@@ -186,6 +187,7 @@ public class ServicesManager implements BatchContainerConstants {
                 }
             }
         } catch (final Throwable e1) {
+            handleBatchContainerRuntimeException(e1);
             throw new IllegalArgumentException("Could not instantiate service " + className + " due to exception: " + e1);
         }
 
@@ -201,20 +203,48 @@ public class ServicesManager implements BatchContainerConstants {
     }
 
     private <T> T load(final Class<T> expected, final String className) throws Exception {
-        final Class<?> cls = getLoader().loadClass(className);
-        if (cls != null) {
-            try {
-                final Constructor<?> constructor = cls.getConstructor(ServicesManager.class);
-                return expected.cast(constructor.newInstance(this));
-            } catch (final Throwable th) {
-                // try no arg constructor
-            }
+        Class<?> cls = null;
+
+        try {
+            cls = getLoader().loadClass(className);
+        } catch (Exception e) {
+            handleBatchContainerRuntimeException(e);
+            throw new BatchContainerRuntimeException("Could not load Service class " + className + ". Make sure it exists", e);
+        }
+        Throwable problem = null;
+        try {
+            final Constructor<?> constructor = cls.getConstructor(ServicesManager.class);
+            return expected.cast(constructor.newInstance(this));
+        } catch (final Throwable th) {
+            handleBatchContainerRuntimeException(th);
+            // remember the first problem and try no arg constructor
+            problem = th;
+        }
+        try {
             if (cls.getConstructor() != null) {
                 return expected.cast(cls.newInstance());
             }
-            throw new BatchContainerRuntimeException("Service class " + className + " should  have a default constructor defined");
+        } catch (Throwable th) {
+            handleBatchContainerRuntimeException(th);
+            // default ct works neither, lets report the original problem
+        }
+        throw new BatchContainerRuntimeException("Service class " + className + " cannnot be loaded", problem);
+    }
+
+    /**
+     * prevent BatchContainerRuntimeExceptions to get swallowed
+     */
+    private void handleBatchContainerRuntimeException(Throwable e) throws BatchContainerRuntimeException {
+        if (e instanceof BatchContainerRuntimeException) {
+            throw (BatchContainerRuntimeException) e;
+        }
+        if (e instanceof InvocationTargetException) {
+            InvocationTargetException ite = (InvocationTargetException) e;
+            if (ite.getCause() instanceof BatchContainerRuntimeException) {
+                throw (BatchContainerRuntimeException) ite.getCause();
+            }
         }
-        throw new Exception("Exception loading Service class " + className + " make sure it exists");
+        // else all is fine
     }
 
     private ClassLoader getLoader() {

http://git-wip-us.apache.org/repos/asf/incubator-batchee/blob/adb3d550/jbatch/src/main/java/org/apache/batchee/jmx/BatchEEMBeanImpl.java
----------------------------------------------------------------------
diff --git a/jbatch/src/main/java/org/apache/batchee/jmx/BatchEEMBeanImpl.java b/jbatch/src/main/java/org/apache/batchee/jmx/BatchEEMBeanImpl.java
index 1ae670f..b396ee5 100644
--- a/jbatch/src/main/java/org/apache/batchee/jmx/BatchEEMBeanImpl.java
+++ b/jbatch/src/main/java/org/apache/batchee/jmx/BatchEEMBeanImpl.java
@@ -150,7 +150,7 @@ public class BatchEEMBeanImpl implements BatchEEMBean {
         return -1;
     }
 
-    private BatchEEMBeanImpl() {
+    public BatchEEMBeanImpl() {
         // no-op
     }