User: user57  
  Date: 01/07/25 20:50:49

  Modified:    src/main/org/jboss/jmx/client Deployer.java
  Log:
   o re-indent and documented (mostly) JMXAdapter
   o moved server.invoke() in Deployer to Deployer.invoke(), which will
     decode JMX exceptions.
  
  Revision  Changes    Path
  1.8       +137 -73   jboss/src/main/org/jboss/jmx/client/Deployer.java
  
  Index: Deployer.java
  ===================================================================
  RCS file: /cvsroot/jboss/jboss/src/main/org/jboss/jmx/client/Deployer.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- Deployer.java     2001/06/18 20:01:26     1.7
  +++ Deployer.java     2001/07/26 03:50:49     1.8
  @@ -9,102 +9,166 @@
   
   import java.io.File;
   import java.net.URL;
  -
  +import java.net.MalformedURLException;
  +   
   import javax.management.ObjectName;
  +import javax.management.MalformedObjectNameException;
  +import javax.management.MBeanException;
  +import javax.management.ReflectionException;
  +import javax.management.RuntimeOperationsException;
  +import javax.management.RuntimeMBeanException;
  +import javax.management.RuntimeErrorException;
  +
   import javax.naming.InitialContext;
  +import javax.naming.NamingException;
   
   import org.jboss.jmx.interfaces.JMXAdaptor;
   
   /**
  - *   <description> 
  + * A JMX client to deploy an application into a running JBoss server.
    *      
  - *   @see <related>
  - *   @author <a href="mailto:[EMAIL PROTECTED]";>Rickard �berg</a>
  - *   @version $Revision: 1.7 $
  + * @author <a href="mailto:[EMAIL PROTECTED]";>Rickard �berg</a>
  + * @author <a href="mailto:[EMAIL PROTECTED]";>Jason Dillon</a>
  + * @version $Revision: 1.8 $
    */
   public class Deployer
   {
  -   // Constants -----------------------------------------------------
  -    
  -   // Attributes ----------------------------------------------------
  -   
  -   // Static --------------------------------------------------------
  -    public static void main(String[] args)
  -    throws Exception {
  -        for(int count=0;count<args.length;count++) {            
  -            if(!args[count].equalsIgnoreCase("-undeploy")) { 
  -                System.out.println("Deploying " + args[count]);
  -                new Deployer().deploy(args[count]);
  -                System.out.println(args[count] + " has been deployed successfully");
  -            } else {
  -                System.out.println("Undeploying " + args[++count]);
  -                new Deployer().undeploy(args[count]);
  -                System.out.println(args[count] + " has been successfully 
undeployed");
  -            }
  -        }
  -    }
  +   /**
  +    * A command line driven interface to the deployer.
  +    */
  +   public static void main(final String[] args)
  +      throws Exception {
  +      for (int count=0;count<args.length;count++) {            
  +         if (!args[count].equalsIgnoreCase("-undeploy")) { 
  +            System.out.println("Deploying " + args[count]);
  +            new Deployer().deploy(args[count]);
  +            System.out.println(args[count] +
  +                               " has been deployed successfully");
  +         } else {
  +            System.out.println("Undeploying " + args[++count]);
  +            new Deployer().undeploy(args[count]);
  +            System.out.println(args[count] +
  +                               " has been successfully undeployed");
  +         }
  +      }
  +   }
   
  -   // Constructors --------------------------------------------------
  -   
  -   // Public --------------------------------------------------------
  -   public void deploy(String url)
  -             throws Exception
  +   /**
  +    * Deploys the app under the given url spec.
  +    *
  +    * @param url    The url spec of the application to deploy.
  +    *
  +    * @throws Exception    Failed to deploy application.
  +    */
  +   public void deploy(final String url) throws Exception
      {
  -        ObjectName containerFactory = createFactoryName();
  -
  -        URL deploymentUrl =createUrl(url);
  -          
  -        JMXAdaptor server = lookupAdaptor();
  -           
  -        server.invoke(containerFactory, 
  -                      "deploy", 
  -                         new Object[] { deploymentUrl.toString() }, 
  -                      new String[] { "java.lang.String" });
  +      invoke(url, "deploy");
      }
        
  -  /** undeploys the app under the given url spec
  -   *  @author cgjung 
  -   */
  -  public void undeploy(String url)
  -             throws Exception
  +   /**
  +    * Undeploys the app under the given url spec.
  +    *
  +    * @param url    The url spec of the application to undeploy.
  +    *
  +    * @throws Exception    Failed to undeploy application.
  +    */
  +   public void undeploy(final String url) throws Exception
      {
  -        ObjectName containerFactory = createFactoryName();
  -           
  -        URL deploymentUrl=createUrl(url);
  -          
  -        JMXAdaptor server = lookupAdaptor();
  -           server.invoke(containerFactory, 
  -                         "undeploy", 
  -                      new Object[] { deploymentUrl.toString() }, 
  -                      new String[] { "java.lang.String" });
  -   }
  -
  -   /** creation of objectname for the deployer
  -    *  factored out
  -    *  @author cgjung
  +      invoke(url, "undeploy");
  +   }
  +
  +   /**
  +    * Get the JMX object name of the factory to use.
       */
  -   protected ObjectName createFactoryName() throws 
javax.management.MalformedObjectNameException {
  -       return new ObjectName("J2EE:service=J2eeDeployer");
  +   protected ObjectName getFactoryName()
  +      throws MalformedObjectNameException
  +   {
  +      return new ObjectName("J2EE:service=J2eeDeployer");
      }
      
  -   /** creation of url factored out
  -    *  @author cgjung
  +   /**
  +    * Create a url from the given application url spec.
  +    *
  +    * <p>Will attempt to create a file:// url first.
  +    * 
  +    * @author cgjung
       */
  -   protected URL createUrl(String url) throws java.net.MalformedURLException {
  -       if (new File(url).exists())
  -           return new File(url).toURL();
  -       else
  -           return new URL(url);
  +   protected URL createURL(final String url) throws MalformedURLException {
  +      if (new File(url).exists()) {
  +         return new File(url).toURL();
  +      }
  +      else {
  +         return new URL(url);
  +      }
      }
  -   
  -   /** lookup of JMXadaptor factored out
  -    *  @author cgjung
  +
  +   /**
  +    * Lookup of JMXadaptor factored out.
  +    *  
  +    * @author cgjung
       */
  -   protected JMXAdaptor lookupAdaptor() throws javax.naming.NamingException {
  -        return (JMXAdaptor)new InitialContext().lookup("jmx");
  +   protected JMXAdaptor lookupAdaptor() throws NamingException {
  +      JMXAdaptor adapter;
  +      InitialContext ctx = new InitialContext();
  +      try {
  +         adapter = (JMXAdaptor)ctx.lookup("jmx");
  +      }
  +      finally {
  +         ctx.close();
  +      }
  +      
  +      return adapter;
      }
      
  +   /**
  +    * Invoke the target deployer and decode JMX exceptions that
  +    * are thrown.
  +    *
  +    * @param url      The raw url
  +    * @param method   Either "deploy" or "undeploy"
  +    *
  +    * @throws Exception    Server invoke failed.
  +    */
  +   protected void invoke(final String url, final String method)
  +      throws Exception
  +   {
  +      URL _url = createURL(url);
  +      JMXAdaptor server = lookupAdaptor();
   
  -   // Protected -----------------------------------------------------
  +      // lookup the adapter to use
  +      JMXAdaptor adapter;
  +      InitialContext ctx = new InitialContext();
  +      try {
  +         adapter = (JMXAdaptor)ctx.lookup("jmx");
  +      }
  +      finally {
  +         ctx.close();
  +      }
  +
  +      // get the deployer name to use
  +      ObjectName name = getFactoryName();
  +
  +      // invoke the server and decode jmx exceptions
  +      try {
  +         server.invoke(name, method,
  +                       new Object[] { _url.toString() },
  +                       new String[] { "java.lang.String" });
  +      }
  +      catch (MBeanException e) {
  +         throw e.getTargetException();
  +      }
  +      catch (ReflectionException e) {
  +         throw e.getTargetException();
  +      }
  +      catch (RuntimeOperationsException e) {
  +         throw e.getTargetException();
  +      }
  +      catch (RuntimeMBeanException e) {
  +         throw e.getTargetException();
  +      }
  +      catch (RuntimeErrorException e) {
  +         throw e.getTargetError();
  +      }
  +   }
   }
   
  
  
  

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

Reply via email to