User: mnf999  
  Date: 01/12/18 14:59:38

  Modified:    src/main/org/jboss/deployment DeployerMBeanSupport.java
  Log:
  factor out the inner class of deployment info
  
  Revision  Changes    Path
  1.15      +202 -281  jboss/src/main/org/jboss/deployment/DeployerMBeanSupport.java
  
  Index: DeployerMBeanSupport.java
  ===================================================================
  RCS file: 
/cvsroot/jboss/jboss/src/main/org/jboss/deployment/DeployerMBeanSupport.java,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- DeployerMBeanSupport.java 2001/12/09 05:24:25     1.14
  +++ DeployerMBeanSupport.java 2001/12/18 22:59:37     1.15
  @@ -1,9 +1,9 @@
   /*
  - * JBoss, the OpenSource J2EE webOS
  - *
  - * Distributable under LGPL license.
  - * See terms of license at gnu.org.
  - */
  +* JBoss, the OpenSource J2EE webOS
  +*
  +* Distributable under LGPL license.
  +* See terms of license at gnu.org.
  +*/
   package org.jboss.deployment;
   
   import java.io.File;
  @@ -30,60 +30,59 @@
   import java.util.List;
   
   /**
  - * An abstract base class for deployer service implementations.
  - *
  - * @author <a href="mailto:[EMAIL PROTECTED]";>Toby Allsopp</a>
  - * @author <a href="mailto:[EMAIL PROTECTED]";>David Jencks</a>
  - * @version $Revision: 1.14 $
  - *
  - * <p><b>Revisions:</b>
  - *
  - * <p><b>20010725 Toby Allsopp (patch from David Jencks)</b>
  - * <ul><li>Added <code>getDeployments</code> method so that subclasses
  - * can find out what has been deployed.</li></ul>
  - */
  +* An abstract base class for deployer service implementations.
  +*
  +* @author <a href="mailto:[EMAIL PROTECTED]";>Toby Allsopp</a>
  +* @author <a href="mailto:[EMAIL PROTECTED]";>David Jencks</a>
  +* @author <a href="mailto:[EMAIL PROTECTED]";>Marc Fleury</a>
  +* @version $Revision: 1.15 $
  +*
  +* <p><b>Revisions:</b>
  +*
  +* <p><b>20010725 Toby Allsopp (patch from David Jencks)</b>
  +* <ul><li>Added <code>getDeployments</code> method so that subclasses
  +* can find out what has been deployed.</li></ul>
  +* <p><b>20011219 Marc Fleury</b>
  +* <ul><li>Factored out inner class for deployment info</li></ul>
  +*/
   public abstract class DeployerMBeanSupport
  -   extends ServiceMBeanSupport
  -   implements DeployerMBean
  +extends ServiceMBeanSupport
  +implements DeployerMBean
   {
      // Constants -----------------------------------------------------
   
  -   private static final String SERVICE_CONTROLLER_NAME =
  -      "JBOSS-SYSTEM:spine=ServiceController";
  -   
  +   private static final String SERVICE_CONTROLLER_NAME = 
"JBOSS-SYSTEM:spine=ServiceController";
      // Attributes --------------------------------------------------------
  -
      private ObjectName serviceControllerName;
  -
      private Map deployments = new HashMap();
  -
  +   
      /**
  -    *  The directory that will contain local copies of deployed packages
  -    */
  +   *  The directory that will contain local copies of deployed packages
  +   */
      private File deployDir;
  -
  +   
      // Static --------------------------------------------------------
  -
  +   
      private static int nextNum = 0;
  -
  +   
      private static synchronized String generateUniqueDirName()
      {
         int thisNum = nextNum++;
         return "deploy." + thisNum;
      }
  -
  +   
      // Constructors --------------------------------------------------
      public DeployerMBeanSupport()
      {
      }
  -
  -
  +   
  +   
      // Public --------------------------------------------------------
  -
  +   
      // DeployerMBean implementation ----------------------------------
  -
  +   
      public void deploy (String url)
  -      throws MalformedURLException, IOException, DeploymentException
  +   throws MalformedURLException, IOException, DeploymentException
      {
         URL u = new URL(url);
         synchronized (deployments)
  @@ -104,7 +103,7 @@
               if (t instanceof Exception)
               {
                  if (t instanceof IOException) throw (IOException) t;
  -               if (t instanceof DeploymentException)
  +                  if (t instanceof DeploymentException)
                     throw (DeploymentException) t;
                  throw (RuntimeException) t;
               }
  @@ -112,9 +111,9 @@
            }
         }
      }
  -
  +   
      public void undeploy (String url)
  -      throws MalformedURLException, IOException, DeploymentException
  +   throws MalformedURLException, IOException, DeploymentException
      {
         URL u = new URL(url);
         synchronized (deployments)
  @@ -126,9 +125,9 @@
            }
         }
      }
  -
  +   
      public boolean isDeployed (String url)
  -      throws MalformedURLException, DeploymentException
  +   throws MalformedURLException, DeploymentException
      {
         URL u = new URL(url);
         synchronized (deployments)
  @@ -136,26 +135,29 @@
            return deployments.containsKey(u);
         }
      }
  -
  +   
      // ServiceMBeanSupport overrides ---------------------------------
  -
  -    /**
  -     * The <code>startService</code> method sets up a temporary directory
  -     * to hold the copies of deployed packages and possibly inflations
  -     * of those copies.  The format is 
(jboss.system.home)/tmp/deploy/(deployername).
  -     *
  -     * @exception Exception if an error occurs
  -     */
  -    protected void startService()
  -          throws Exception
  -   {
  -      // find the temp directory - referenced to jboss.system.home property
  -      File jbossHomeDir = new File(System.getProperty("jboss.system.home"));
  -      File tmpDir = new File(jbossHomeDir, "tmp"+File.separator);
  -
  -      // Create our temp directory
  -      File deployTmpDir = new File(tmpDir, "deploy");
  -      deployDir = new File(deployTmpDir, getName());
  +   
  +   /**
  +   * The <code>startService</code> method sets up a temporary directory
  +   * to hold the copies of deployed packages and possibly inflations
  +   * of those copies.  The format is (jboss.system.home)/tmp/deploy/(deployername).
  +   *
  +   * @exception Exception if an error occurs
  +   */
  +   protected void startService()
  +   throws Exception
  +   {
  +      
  +      // FIXME MARCF I think we should keep the old code around (would speed up 
boot time)
  +      // Just delete on undeploy and if there is new stuff
  +      
  +      deployDir = new File(
  +         // from the top of the jboss home distribution
  +         System.getProperty("jboss.system.home"), 
  +         // create a local temporary deployment directory
  +         "tmp"+File.separator+"deploy"+File.separator+getName());
  +      
         if (deployDir.exists())
         {
            log.debug("Found a temp directory left over " +
  @@ -172,16 +174,16 @@
         if (!deployDir.exists() && !deployDir.mkdirs())
         {
            throw new DeploymentException("Can't create temp directory '" +
  -                                       deployDir + "'");
  +            deployDir + "'");
         }
         log.info("Temporary deploy directory is " + deployDir);
      }
  -
  -    /**
  -     * The <code>stopService</code> method tries to remove the
  -     * directory created in the initService method.
  -     *
  -     */
  +   
  +   /**
  +   * The <code>stopService</code> method tries to remove the
  +   * directory created in the createService method.
  +   *
  +   */
      protected void stopService()
      {
         // Remove our temp directory
  @@ -192,22 +194,22 @@
                     "server is next restarted.");
         }
      }
  -
  +   
      // Package protected ---------------------------------------------
  -
  +   
      // Protected -----------------------------------------------------
  -
  +   
      /**
  -    * Retrieves the object associated with a deployment. This
  -    * association is made during deployment using the object returned
  -    * from <code>deploy(URL)</code>. If there is no such deployment,
  -    * null is returned. Note that this is distinguishable from the
  -    * case of a deployment with an null information object only using
  -    * <code>isDeployed(URL)</code>.
  -    *
  -    * @param url the deployment for which information is required
  -    * @return an object, possibly null
  -    */
  +   * Retrieves the object associated with a deployment. This
  +   * association is made during deployment using the object returned
  +   * from <code>deploy(URL)</code>. If there is no such deployment,
  +   * null is returned. Note that this is distinguishable from the
  +   * case of a deployment with an null information object only using
  +   * <code>isDeployed(URL)</code>.
  +   *
  +   * @param url the deployment for which information is required
  +   * @return an object, possibly null
  +   */
      protected Object getInfo(URL url)
      {
         synchronized (deployments)
  @@ -215,38 +217,38 @@
            return deployments.get(url);
         }
      }
  -
  +   
      /**
  -    * Subclasses override to perform actual deployment.
  -    *
  -    * @param url the location to be deployed
  -    * @return an object, possibly null, that will be passed back to
  -    *         <code>undeploy</code> and can be obtained using
  -    *         <code>getInfo(URL)</code>
  -    */
  +   * Subclasses override to perform actual deployment.
  +   *
  +   * @param url the location to be deployed
  +   * @return an object, possibly null, that will be passed back to
  +   *         <code>undeploy</code> and can be obtained using
  +   *         <code>getInfo(URL)</code>
  +   */
      protected abstract Object deploy(URL url)
  -      throws IOException, DeploymentException;
  -
  +   throws IOException, DeploymentException;
  +   
      /**
  -    * Subclasses override to perform any actions neccessary for
  -    * undeployment.
  -    *
  -    * @param url the location to be undeployed
  -    * @param info the object that was returned by the corresponding
  -    *             <code>deploy</code>
  -    */
  +   * Subclasses override to perform any actions neccessary for
  +   * undeployment.
  +   *
  +   * @param url the location to be undeployed
  +   * @param info the object that was returned by the corresponding
  +   *             <code>deploy</code>
  +   */
      protected abstract void undeploy(URL url, Object info)
  -      throws IOException, DeploymentException;
  -
  +   throws IOException, DeploymentException;
  +   
      /**
  -    * Returns the deployments that have been deployed by this
  -    * deployer.  The <code>Map</code> returned from this method is a
  -    * snapshot of the deployments at the time the method is called and
  -    * will not reflect any subsequent deployments or undeployments.
  -    *
  -    * @return a mapping from <code>URL</code> to
  -    *         <code>DeploymentInfo</code>
  -    */
  +   * Returns the deployments that have been deployed by this
  +   * deployer.  The <code>Map</code> returned from this method is a
  +   * snapshot of the deployments at the time the method is called and
  +   * will not reflect any subsequent deployments or undeployments.
  +   *
  +   * @return a mapping from <code>URL</code> to
  +   *         <code>DeploymentInfo</code>
  +   */
      protected Map getDeployments()
      {
         Map ret = new HashMap();
  @@ -256,41 +258,41 @@
         }
         return ret;
      }
  -
  -
  -    // Below here are helper methods to deal with copying packages,
  -    // unpacking packages recursively, finding things in packages,
  -    // and similar tasks needed for most deployment activities.
  -     //
  -    /**
  -     * The <code>inflateJar</code> copies the jar entries
  -     * from the jar url jarUrl to the directory destDir.
  -     * It can be used on the whole jar, a directory, or
  -     * a specific file in the jar.
  -     *
  -     * @param jarUrl the <code>URL</code> if the directory or entry to copy.
  -     * @param destDir the <code>File</code> value of the directory in which to
  -     * place the inflated copies.
  -     * @exception DeploymentException if an error occurs
  -     * @exception IOException if an error occurs
  -     */
  -    protected void inflateJar(URL url, File destDir, String path)
  -          throws DeploymentException, IOException
  +   
  +   
  +   // Below here are helper methods to deal with copying packages,
  +   // unpacking packages recursively, finding things in packages,
  +   // and similar tasks needed for most deployment activities.
  +   //
  +   /**
  +   * The <code>inflateJar</code> copies the jar entries
  +   * from the jar url jarUrl to the directory destDir.
  +   * It can be used on the whole jar, a directory, or
  +   * a specific file in the jar.
  +   *
  +   * @param jarUrl the <code>URL</code> if the directory or entry to copy.
  +   * @param destDir the <code>File</code> value of the directory in which to
  +   * place the inflated copies.
  +   * @exception DeploymentException if an error occurs
  +   * @exception IOException if an error occurs
  +   */
  +   protected void inflateJar(URL url, File destDir, String path)
  +   throws DeploymentException, IOException
      {
         /*
         //Why doesn't this work???? Maybe in java 1.4?
         URL jarUrl;
         try
         {
  -         jarUrl = new URL("jar:" + url.toString() + "!/");
  +      jarUrl = new URL("jar:" + url.toString() + "!/");
         }
         catch (MalformedURLException mfue)
         {
  -         throw new DeploymentException("Oops! Couldn't convert URL to a jar URL", 
mfue);
  +      throw new DeploymentException("Oops! Couldn't convert URL to a jar URL", 
mfue);
         }
  -
  +      
         JarURLConnection jarConnection =
  -            (JarURLConnection)jarUrl.openConnection();
  +      (JarURLConnection)jarUrl.openConnection();
         JarFile jarFile = jarConnection.getJarFile();
         */
         String filename = url.getFile();
  @@ -306,7 +308,7 @@
                  File outFile = new File(destDir, name);
                  if (!outFile.exists())
                  {
  -
  +                  
                     if (entry.isDirectory())
                     {
                        outFile.mkdirs();
  @@ -331,10 +333,10 @@
                           in.close();
                        }
                     }
  -
  +               
                  } // end of if (outFile.exists())
               } // end of if (matches path)
  -
  +         
            }
         }
         finally
  @@ -342,43 +344,38 @@
            jarFile.close();
         }
      }
  -
  -   protected void extractPackages(URL url, DeploymentInfo di)
  -          throws DeploymentException, IOException
  +   
  +   protected void extractPackages(URL url, ServiceDeploymentInfo di)
  +   throws DeploymentException, IOException
      {
         if (url.getFile().endsWith(".xml"))
         {
            di.addXmlUrl(url);
  +         // Nothing to extract
            return;
         }
  -
  -      //if its a zip, jar or war, add to list and stop
  +      
  +      //if its a zip, jar or war, add to list and stop, these are class suppliers
         if (url.getFile().endsWith(".zip") || url.getFile().endsWith(".jar") || 
url.getFile().endsWith(".war"))
         {
            di.addClassUrl(url);
            return;
         }
  -      //Sars may contain files or other packages
  -      if (url.getFile().endsWith(".sar"))
  -      {
  -         di.addClassUrl(url);
  -      }
  -
  -
  +      
  +      //Sars may contain files or other packages, the sar itself is a class supplier
  +      if (url.getFile().endsWith(".sar"))  di.addClassUrl(url);
  +         
  +      
         URL jarUrl;
  -      try
  -      {
  -         jarUrl = new URL("jar:" + url.toString() + "!/");
  -      }
  -      catch (MalformedURLException mfue)
  -      {
  -         throw new DeploymentException("Oops! Couldn't convert URL to a jar URL", 
mfue);
  -      }
  -
  +      // jar:<theURL>!/...
  +      try { jarUrl = new URL("jar:" + url.toString() + "!/"); }
  +         
  +      catch (MalformedURLException mfue) { throw new DeploymentException("Oops! 
Couldn't convert URL to a jar URL", mfue);}
  +      
         JarURLConnection jarConnection =
  -            (JarURLConnection)jarUrl.openConnection();
  +      (JarURLConnection)jarUrl.openConnection();
         JarFile jarFile = jarConnection.getJarFile();
  -
  +      
         try
         {
            for (Enumeration e = jarFile.entries(); e.hasMoreElements(); )
  @@ -386,28 +383,29 @@
               JarEntry entry = (JarEntry)e.nextElement();
               String name = entry.getName();
               /*
  -//jar urls don't seem to work!
  
-jar:file:/usr/java/jboss/co6/jboss-all/build/output/jboss-3.0.0alpha/tmp/deploy/ServiceDeployer/copydeploy.28/jmx-ejb-connector-server.sar!/META-INF/jboss-service.xml
  -cannot be opened!
  +            //jar urls don't seem to work!
  +            
jar:file:/usr/java/jboss/co6/jboss-all/build/output/jboss-3.0.0alpha/tmp/deploy/ServiceDeployer/copydeploy.28/jmx-ejb-connector-server.sar!/META-INF/jboss-service.xml
  +            cannot be opened!
               if (name.endsWith(".xml"))
               {
  -               di.addXmlUrl(new URL(jarUrl, name));
  +            di.addXmlUrl(new URL(jarUrl, name));
               } // end of if ()
  -
  +            
               else
               */
               if (name.endsWith(".jar")
  -                || name.endsWith(".xml")
  -                || name.endsWith(".sar")
  -                || name.endsWith(".ear")
  -                || name.endsWith(".rar")
  -                || name.endsWith(".war")
  -                || name.endsWith(".zip"))
  +               || name.endsWith(".xml")
  +               || name.endsWith(".sar")
  +               || name.endsWith(".ear")
  +               || name.endsWith(".rar")
  +               || name.endsWith(".war")
  +               || name.endsWith(".zip"))
               {
  +               
                  File outFile = new File(getUniqueDir(di), name);
                  File outFileParent = outFile.getParentFile();
                  outFileParent.mkdirs();
  -
  +               
                  InputStream in = jarFile.getInputStream(entry);
                  try
                  {
  @@ -428,8 +426,8 @@
                  //stop for these,
                  URL packageURL = new URL("file:" + outFile.toString());
                  if (name.endsWith(".jar")
  -                   || name.endsWith(".zip")
  -                   || name.endsWith(".war"))
  +                  || name.endsWith(".zip")
  +                  || name.endsWith(".war"))
                  {
                     di.addClassUrl(packageURL);
                  } // end of if ()
  @@ -439,19 +437,18 @@
                     extractPackages(packageURL, di);
                  } // end of else
               }
  -
  -
  +         
            } // end of if ()
  -
  +      
         }
         finally
         {
            jarFile.close();
         }
      }
  -
  +   
      protected void copy(InputStream in, OutputStream out)
  -          throws IOException
  +   throws IOException
      {
         byte[] buffer = new byte[1024];
         int read;
  @@ -460,7 +457,7 @@
            out.write(buffer, 0, read);
         }
      }
  -
  +   
      protected boolean recursiveDelete(File f)
      {
         if (f.isDirectory())
  @@ -476,21 +473,26 @@
         }
         return f.delete();
      }
  -
  -   protected File getDeployDir()
  -   {
  -      return deployDir;
  -   }
  -
  -
  -   protected File getLocalCopy(URL url, DeploymentInfo di)
  -       throws IOException
  +   
  +   public File getDeployDir() { return deployDir; }
  +   
  +   
  +   public File getLocalCopy(URL url, ServiceDeploymentInfo di)
  +   throws IOException
      {
  -      File localDir = getUniqueDir(di);
  +      // Create a directory into which we are going to put the bytes
  +      File localDir = new File(deployDir, generateUniqueDirName()+ File.separator);
  +      
  +      // Create the directories
         localDir.mkdirs();
  -      String name = new File(url.getFile()).getName();//end of file name,no path
  -
  -      File copyFile = new File(localDir, name);
  +      
  +      // Keep track of the directory we are using
  +      di.addDir(localDir);
  +      
  +      // Get the name of the file (no path) create that file as "copyFile"
  +      File copyFile = new File(localDir, new File(url.getFile()).getName());
  +      
  +      // Copy the stuff into it
         InputStream input = url.openStream();
         try
         {
  @@ -510,6 +512,7 @@
         }
         return copyFile;
      }
  +   
      protected ObjectName getServiceControllerName() throws DeploymentException
      {
         if (serviceControllerName == null)
  @@ -525,100 +528,18 @@
         }
         return serviceControllerName;
      }
  -
  -
  +   
  +   
      // Private -------------------------------------------------------
  -   private File getUniqueDir(DeploymentInfo di)
  +   
  +   
  +   private File getUniqueDir(ServiceDeploymentInfo di)
      {
  -      File dir = new File(getDeployDir(), generateUniqueDirName() + File.separator);
  -      di.addDir(dir);
  -      return dir;
  +   File dir = new File(deployDir, generateUniqueDirName() + File.separator);
  +   di.addDir(dir);
  +   return dir;
      }
  -
  +   
      // Inner classes -------------------------------------------------
  -   protected static class DeploymentInfo
  -   {
  -      private URL key;
  -      private List dirs = new ArrayList();
  -      private List classUrls = new ArrayList();
  -      private List xmlUrls = new ArrayList();
  -      private URLClassLoader cl;
  -
  -      public DeploymentInfo(URL key)
  -      {
  -         this.key = key;
  -      }
  -
  -      public void addDir(File dir)
  -      {
  -         dirs.add(dir);
  -      }
   
  -      public void addClassUrl(URL url)
  -      {
  -         classUrls.add(url);
  -      }
  -
  -      public void addXmlUrl(URL url)
  -      {
  -         xmlUrls.add(url);
  -      }
  -
  -      public List getClassUrls()
  -      {
  -         return classUrls;
  -      }
  -
  -      public List getXmlUrls()
  -      {
  -         return xmlUrls;
  -      }
  -
  -      public URLClassLoader createClassLoader()
  -      {
  -         URL[] urlArray = (URL[])classUrls.toArray(new URL[classUrls.size()]);
  -         cl = new URLClassLoader(urlArray, key);
  -         return cl;
  -      }
  -
  -      public URLClassLoader removeClassLoader()
  -      {
  -         URLClassLoader localcl = cl;
  -         cl = null;
  -         return localcl;
  -      }
  -
  -      public void cleanup(Logger log)
  -      {
  -         classUrls.clear();
  -         xmlUrls.clear();
  -         for (Iterator i = dirs.iterator(); i.hasNext(); )
  -         {
  -            File dir = (File)i.next();
  -            if (!recursiveDelete(dir))
  -            {
  -               log.info("could not delete directory " + dir + ". Will be removed on 
server shutdown or restart");
  -            } // end of if ()
  -           ;
  -         } // end of for ()
  -         dirs.clear();
  -      }
  -
  -      private boolean recursiveDelete(File f)
  -      {
  -         if (f.isDirectory())
  -         {
  -            File[] files = f.listFiles();
  -            for (int i = 0; i < files.length; ++i)
  -            {
  -               if (!recursiveDelete(files[i]))
  -               {
  -                  return false;
  -               }
  -            }
  -         }
  -         return f.delete();
  -      }
  -
  -   }
   }
  
  
  

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

Reply via email to