[prev in list] [next in list] [prev in thread] [next in thread] 

List:       opennms-cvs
Subject:    [opennms-cvs] SF.net SVN: opennms: [6296]
From:       djgregor () users ! sourceforge ! net
Date:       2007-05-23 2:06:07
Message-ID: E1HqgEp-0007oz-6n () sc8-pr-svn3 ! sourceforge ! net
[Download RAW message or body]

Revision: 6296
          http://svn.sourceforge.net/opennms/?rev=6296&view=rev
Author:   djgregor
Date:     2007-05-22 19:06:04 -0700 (Tue, 22 May 2007)

Log Message:
-----------
Wrap all invocations of service methods in a try/finally block that saves the log4j \
category prefix before calling the method and restores it upon exit.  Caught by \
david@. 

Modified Paths:
--------------
    opennms/trunk/opennms-services/src/main/java/org/opennms/netmgt/vmmgr/Invoker.java


Modified: opennms/trunk/opennms-services/src/main/java/org/opennms/netmgt/vmmgr/Invoker.java
 ===================================================================
--- opennms/trunk/opennms-services/src/main/java/org/opennms/netmgt/vmmgr/Invoker.java	2007-05-23 \
                00:25:19 UTC (rev 6295)
+++ opennms/trunk/opennms-services/src/main/java/org/opennms/netmgt/vmmgr/Invoker.java	2007-05-23 \
02:06:04 UTC (rev 6296) @@ -13,6 +13,9 @@
  *
  * Modifications:
  *
+ * 2007 May 22: Wrap all invocations of service methods in a try/finally block
+ *              that saves the log4j category prefix before calling the method
+ *              and restores it upon exit.  Caught by david@. - dj@opennms.org
  * 2003 Jan 31: Cleaned up some unused imports.
  *
  * Original code base Copyright (C) 1999-2001 Oculan Corp. All rights
@@ -109,6 +112,7 @@
     }
     
     public void instantiateClasses() {
+
         /*
          * Preload the classes and register a new instance with the
          * MBeanServer.
@@ -128,8 +132,15 @@
                     log().debug("create new instance of "
                             + service.getClassName());
                 }
-                Object bean = clazz.newInstance();
 
+                String log4jPrefix = ThreadCategory.getPrefix();
+                Object bean;
+                try {
+                    bean = clazz.newInstance();
+                } finally {
+                    ThreadCategory.setPrefix(log4jPrefix);
+                }
+
                 // Register the mbean
                 if (log().isDebugEnabled()) {
                     log().debug("registering mbean instance "
@@ -149,6 +160,7 @@
                         }
 
                         getServer().setAttribute(name, getAttribute(attribs[j]));
+                        ThreadCategory.setPrefix(log4jPrefix);
                     }
                 }
             } catch (Throwable t) {
@@ -297,7 +309,12 @@
 
         Object object;
         try {
-            object = getServer().invoke(mbean.getObjectName(), invoke.getMethod(), \
parms, sig); +            String log4jPrefix = ThreadCategory.getPrefix(); 
+            try {
+                object = getServer().invoke(mbean.getObjectName(), \
invoke.getMethod(), parms, sig); +            } finally {
+                ThreadCategory.setPrefix(log4jPrefix);
+            }
         } catch (Throwable t) {
             log().error("An error occurred invoking operation "
                       + invoke.getMethod() + " on MBean "
@@ -314,7 +331,13 @@
         Class attribClass = Class.forName(attrib.getValue().getType());
         Constructor construct = attribClass.getConstructor(new Class[] { \
String.class });  
-        Object value = construct.newInstance(new Object[] { \
attrib.getValue().getContent() }); +        Object value;
+        String log4jPrefix = ThreadCategory.getPrefix(); 
+        try {
+            value = construct.newInstance(new Object[] { \
attrib.getValue().getContent() }); +        } finally {
+            ThreadCategory.setPrefix(log4jPrefix);
+        }
 
         return new Attribute(attrib.getName(), value);
     }
@@ -323,7 +346,12 @@
         Class argClass = Class.forName(arg.getType());
         Constructor construct = argClass.getConstructor(new Class[] { String.class \
});  
-        return construct.newInstance(new Object[] { arg.getContent() });
+        String log4jPrefix = ThreadCategory.getPrefix(); 
+        try {
+            return construct.newInstance(new Object[] { arg.getContent() });
+        } finally {
+            ThreadCategory.setPrefix(log4jPrefix);
+        }
     }
 
     private Category log() {


This was sent by the SourceForge.net collaborative development platform, the world's \
largest Open Source development site.

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Please read the OpenNMS Mailing List FAQ:
http://www.opennms.org/wiki/index.php?page=MailingListFaq
opennms-cvs mailing list

To *unsubscribe* or change your subscription options, see the bottom of this page:
https://lists.sourceforge.net/lists/listinfo/opennms-cvs


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic