You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@isis.apache.org by da...@apache.org on 2013/02/14 19:05:04 UTC

[1/2] git commit: ISIS-327: improving log messaging for domain service init/shutdown

ISIS-327: improving log messaging for domain service init/shutdown

- of the calling of the @PostConstruct and @PreDestroy methods.


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

Branch: refs/heads/master
Commit: 3a323d75c99dac794bf6eff6834a5d037933a48a
Parents: 27c766e
Author: Dan Haywood <da...@apache.org>
Authored: Thu Feb 14 18:03:24 2013 +0000
Committer: Dan Haywood <da...@apache.org>
Committed: Thu Feb 14 18:03:24 2013 +0000

----------------------------------------------------------------------
 .../system/session/IsisSessionFactoryAbstract.java |   28 ++++++++++----
 1 files changed, 20 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/isis/blob/3a323d75/core/runtime/src/main/java/org/apache/isis/core/runtime/system/session/IsisSessionFactoryAbstract.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/isis/core/runtime/system/session/IsisSessionFactoryAbstract.java b/core/runtime/src/main/java/org/apache/isis/core/runtime/system/session/IsisSessionFactoryAbstract.java
index 4915bb9..b63ebcf 100644
--- a/core/runtime/src/main/java/org/apache/isis/core/runtime/system/session/IsisSessionFactoryAbstract.java
+++ b/core/runtime/src/main/java/org/apache/isis/core/runtime/system/session/IsisSessionFactoryAbstract.java
@@ -129,7 +129,7 @@ public abstract class IsisSessionFactoryAbstract implements IsisSessionFactory {
     }
 
     private void validatePostConstructMethods(Object service, Method method) {
-        PostConstruct postConstruct = method.getAnnotation(PostConstruct.class);
+        final PostConstruct postConstruct = method.getAnnotation(PostConstruct.class);
         if(postConstruct == null) {
             return;
         }
@@ -144,7 +144,7 @@ public abstract class IsisSessionFactoryAbstract implements IsisSessionFactory {
     }
 
     private void validatePreDestroyMethods(Object service, Method method) {
-        PreDestroy preDestroy = method.getAnnotation(PreDestroy.class);
+        final PreDestroy preDestroy = method.getAnnotation(PreDestroy.class);
         if(preDestroy == null) {
             return;
         }
@@ -200,20 +200,23 @@ public abstract class IsisSessionFactoryAbstract implements IsisSessionFactory {
     protected void initServices(IsisConfiguration configuration) {
         final List<Object> services = getServices();
         Map<String, String> props = configuration.asMap();
+        LOG.info("calling @PostConstruct on all domain services");
         for (Object service : services) {
             callPostConstructIfExists(service, props);
         }
     }
 
     private void callPostConstructIfExists(Object service, Map<String, String> props) {
-        LOG.info("calling @PostConstruct on all domain services");
+        LOG.debug("looking for @PostConstruct methods on " + service.getClass().getName());
         Method[] methods = service.getClass().getMethods();
+        boolean found = false;
         for (Method method : methods) {
             PostConstruct postConstruct = method.getAnnotation(PostConstruct.class);
             if(postConstruct == null) {
                 continue;
             }
-            LOG.info("calling @PostConstruct method: " + service.getClass().getName() + ": " + method.getName());
+            found = true;
+            LOG.info("... calling @PostConstruct method: " + service.getClass().getName() + ": " + method.getName());
 
             final int numParams = method.getParameterTypes().length;
             
@@ -224,32 +227,41 @@ public abstract class IsisSessionFactoryAbstract implements IsisSessionFactory {
                 InvokeUtils.invoke(method, service, new Object[]{props});
             }
         }
+        if(!found) {
+            LOG.info("... found no @PostConstruct methods on " + service.getClass().getName());
+        }
     }
 
 
     protected void shutdownServices() {
         final List<Object> services = getServices();
+        LOG.info("calling @PreDestroy on all domain services");
         for (Object service : services) {
             callPreDestroyIfExists(service);
         }
     }
 
     private void callPreDestroyIfExists(Object service) {
-        LOG.info("calling @PreDestroy on all domain services");
+        LOG.debug("looking for @PreDestroy methods on " + service.getClass().getName());
         final Method[] methods = service.getClass().getMethods();
+        boolean found = false;
         for (Method method : methods) {
-            PreDestroy preDestroy = method.getAnnotation(PreDestroy.class);
+            final PreDestroy preDestroy = method.getAnnotation(PreDestroy.class);
             if(preDestroy == null) {
                 continue;
             }
-            LOG.info("calling @PreDestroy method: " + service.getClass().getName() + ": " + method.getName());
+            found = true;
+            LOG.info("... calling @PreDestroy method: " + service.getClass().getName() + ": " + method.getName());
             try {
                 InvokeUtils.invoke(method, service);
             } catch(Exception ex) {
                 // do nothing
-                LOG.warn("@PreDestroy method threw exception - continuing anyway", ex);
+                LOG.warn("... @PreDestroy method threw exception - continuing anyway", ex);
             }
         }
+        if(!found) {
+            LOG.info("... found no @PreDestroy methods on " + service.getClass().getName());
+        }
     }