User: user57  
  Date: 02/03/04 19:08:06

  Modified:    src/main/org/jboss/system ServiceController.java
  Log:
   o Use JMXExceptionDecoder to handle those pesky JMX exceptions
  
  Revision  Changes    Path
  1.2       +21 -88    jboss-system/src/main/org/jboss/system/ServiceController.java
  
  Index: ServiceController.java
  ===================================================================
  RCS file: 
/cvsroot/jboss/jboss-system/src/main/org/jboss/system/ServiceController.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ServiceController.java    24 Feb 2002 10:24:34 -0000      1.1
  +++ ServiceController.java    5 Mar 2002 03:08:06 -0000       1.2
  @@ -12,6 +12,7 @@
   import java.lang.reflect.InvocationHandler;
   import java.lang.reflect.Method;
   import java.lang.reflect.Proxy;
  +
   import java.util.ArrayList;
   import java.util.HashMap;
   import java.util.Iterator;
  @@ -19,6 +20,7 @@
   import java.util.LinkedList;
   import java.util.ListIterator;
   import java.util.Map;
  +
   import javax.management.InstanceNotFoundException;
   import javax.management.JMException;
   import javax.management.JMRuntimeException;
  @@ -29,14 +31,14 @@
   import javax.management.MBeanServer;
   import javax.management.MalformedObjectNameException;
   import javax.management.ObjectName;
  -import javax.management.ReflectionException;
  -import javax.management.RuntimeErrorException;
  -import javax.management.RuntimeMBeanException;
  -import javax.management.RuntimeOperationsException;
   
   import org.w3c.dom.Element;
  +
   import org.jboss.logging.Logger;
   
  +import org.jboss.util.jmx.JMXExceptionDecoder;
  +import org.jboss.util.UnreachableStatementException;
  +
   /**
    * This is the main Service Controller. A controller can deploy a service to a
    * jboss.system It installs by delegating, it configures by delegating
  @@ -45,7 +47,7 @@
    * 
    * @author <a href="mailto:[EMAIL PROTECTED]";>Marc Fleury</a>
    * @author <a href="mailto:[EMAIL PROTECTED]";>David Jencks</a>
  - * @version $Revision: 1.1 $ <p>
  + * @version $Revision: 1.2 $ <p>
    *
    * <b>Revisions:</b> <p>
    *
  @@ -91,10 +93,6 @@
      
      // Public --------------------------------------------------------
      
  -   public Logger getLog() { return log;}
  -   
  -   public String getName() { return "Service Controller"; }
  -   
      /**
      * Gets the Deployed attribute of the ServiceController object
      *
  @@ -138,7 +136,7 @@
      * @throws Exception ???
      */
      public synchronized ObjectName install(Element mbeanElement)
  -   throws Exception
  +      throws Exception
      {
         boolean debug = log.isDebugEnabled();
         
  @@ -150,39 +148,13 @@
         //remove(objectName);
         
         // It is not there so really create the component now, this registers the 
component in the mbeanserver
  -      try
  -      {
  +
  +      // deal with those pesky JMX exceptions
  +      try {
            creator.install(mbeanElement);
         }
  -      catch (MBeanException mbe)
  -      {
  -         mbe.getTargetException().printStackTrace();
  -         throw mbe.getTargetException();
  -      }
  -      catch (RuntimeMBeanException mbe)
  -      {
  -         mbe.getTargetException().printStackTrace();
  -         throw mbe.getTargetException();
  -      }
  -      catch (RuntimeErrorException ree)
  -      {
  -         ree.getTargetError().printStackTrace();
  -         throw ree.getTargetError();
  -      }
  -      //
  -      // catch (MalformedObjectNameException mone) {}
  -      // catch (ReflectionException re) {}
  -      // catch (InstanceNotFoundException re) {}
  -      //
  -      catch (Throwable e)
  -      {
  -         log.error("Could not create MBean: " + ctx.objectName, e);
  -         if (e instanceof Exception)
  -            throw (Exception)e;
  -         if (e instanceof Error)
  -            throw (Error)e;
  -         
  -         throw new Error("unexpected throwable: " + e);
  +      catch (Exception e) {
  +         JMXExceptionDecoder.rethrow(e);
         }
         
         // We got this far
  @@ -522,7 +494,7 @@
      * @exception Exception Description of Exception
      */
      public ObjectName preRegister(MBeanServer server, ObjectName name)
  -   throws Exception
  +      throws Exception
      {
         this.server = server;
         
  @@ -640,44 +612,14 @@
         return new ObjectName(name);
      }
      
  -   /**
  -   * Go through the myriad of nested JMX exception to pull out the true
  -   * exception if possible and log it.
  -   * 
  -   * @param e The exception to be logged.
  -   */
  -   private void logException(String message, Throwable e)
  -   {
  -      if (e instanceof RuntimeErrorException)
  -      {
  -         e = ((RuntimeErrorException)e).getTargetError();
  -      }
  -      else if (e instanceof RuntimeMBeanException)
  -      {
  -         e = ((RuntimeMBeanException)e).getTargetException();
  -      }
  -      else if (e instanceof RuntimeOperationsException)
  -      {
  -         e = ((RuntimeOperationsException)e).getTargetException();
  -      }
  -      else if (e instanceof MBeanException)
  -      {
  -         e = ((MBeanException)e).getTargetException();
  -      }
  -      else if (e instanceof ReflectionException)
  -      {
  -         e = ((ReflectionException)e).getTargetException();
  -      }
  -      log.error(message, e);
  -   }
  -   
      // Inner classes -------------------------------------------------
      
      // Create a Service Context for the service, or get one if it exists
      public synchronized ServiceContext getServiceContext(ObjectName objectName)
      {
         // If it is already there just return it
  -      if (nameToServiceMap.containsKey(objectName)) return (ServiceContext) 
nameToServiceMap.get(objectName);
  +      if (nameToServiceMap.containsKey(objectName)) 
  +         return (ServiceContext)nameToServiceMap.get(objectName);
            
         // If not create it, add it and return it
         ServiceContext ctx = new ServiceContext();
  @@ -766,29 +708,20 @@
         * @throws Throwable
         */
         public Object invoke(Object proxy, Method method, Object[] args)
  -      throws Throwable
  +         throws Throwable
         {
            String name = method.getName();
            Integer opID = (Integer)serviceOpMap.get(name);
            
            if (opID != null && hasOp[opID.intValue()] == true)
            {
  -            try
  -            {
  +            // deal with those pesky JMX exceptions
  +            try {
                  String[] sig = {};
                  server.invoke(objectName, name, args, sig);
               }
  -            catch (JMRuntimeException e)
  -            {
  -               logException("JMRuntimeException thrown during ServiceProxy 
operation " +
  -                  name + " on mbean " + objectName, e);
  -               throw e;
  -            }
  -            catch (JMException e)
  -            {
  -               logException("JMException thrown during ServiceProxy operation " +
  -                  name + " on mbean " + objectName, e);
  -               throw e;
  +            catch (Exception e) {
  +               throw JMXExceptionDecoder.decode(e);
               }
            }
            
  
  
  

_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-development

Reply via email to