FileDocCategorySizeDatePackage
DeploymentManagerService.javaAPI DocJBoss 4.2.111506Fri Jul 13 20:52:32 BST 2007org.jboss.deployment.services

DeploymentManagerService

public class DeploymentManagerService extends org.jboss.system.ServiceMBeanSupport implements DeploymentManagerServiceMBean
A service that supports the JSR-88 DeploymentManager operations.
author
Scott.Stark@jboss.org
version
$Revision: 60132 $

Fields Summary
private Map
moduleMap
private ObjectName
mainDeployer
The name of the MainDeployer
private ObjectName
carDeployer
private ObjectName
earDeployer
private ObjectName
ejbDeployer
private ObjectName
rarDeployer
private ObjectName
warDeployer
File
uploadDir
The local directory for uploaded content.
private boolean
failOnCollision
private boolean
deleteOnUndeploy
Constructors Summary
Methods Summary
public voiddeploy(org.jboss.deployment.spi.SerializableTargetModuleID moduleID)

      String url = moduleID.getModuleID();

      // Create a status object
      URL deployURL = new URL(url);
      URLConnection conn = deployURL.openConnection();
      int contentLength = conn.getContentLength();
      log.debug("Begin deploy, url: " + deployURL + ", contentLength: " + contentLength);

      // Create the local path
      File path = new File(deployURL.getFile());
      String archive = path.getName();
      File deployFile = new File(uploadDir, archive);
      if (failOnCollision && deployFile.exists())
         throw new IOException("deployURL(" + deployURL + ") collides with: " + deployFile.getPath());

      if (deployFile.exists())
         Files.delete(deployFile);

      File parentFile = deployFile.getParentFile();
      if (parentFile.exists() == false)
      {
         if (parentFile.mkdirs() == false)
            throw new IOException("Failed to create local path: " + parentFile);
      }

      InputStream is = conn.getInputStream();
      BufferedInputStream bis = new BufferedInputStream(is);
      byte[] buffer = new byte[4096];
      FileOutputStream fos = new FileOutputStream(deployFile);
      BufferedOutputStream bos = new BufferedOutputStream(fos);
      int count = 0;
      while ((count = bis.read(buffer)) > 0)
      {
         bos.write(buffer, 0, count);
      }
      bis.close();
      bos.close();

      moduleMap.put(url, moduleID);
   
private voidfillChildrenTargetModuleID(org.jboss.deployment.spi.SerializableTargetModuleID moduleID, org.jboss.deployment.DeploymentInfo info)

      Iterator it = info.subDeployments.iterator();
      while (it.hasNext())
      {
         DeploymentInfo sdi = (DeploymentInfo)it.next();
         try
         {
            ModuleType type = getModuleType(sdi);
            // Discard unknown ModuleTypes
            if (type != null)
            {
               String module = sdi.url.toString();
               boolean isRunning = (DeploymentState.STARTED == sdi.state);
               SerializableTargetModuleID child = new SerializableTargetModuleID(moduleID, module, type.getValue(), isRunning);
               moduleID.addChildTargetModuleID(child);
               fillChildrenTargetModuleID(child, sdi);
            }
         }
         catch (UnsupportedOperationException e)
         {
            if (log.isTraceEnabled())
               log.trace("Ignoring", e);
         }
      }
   
public org.jboss.deployment.spi.SerializableTargetModuleID[]getAvailableModules(int moduleType)

      ArrayList matches = new ArrayList();
      Iterator modules = moduleMap.values().iterator();
      while (modules.hasNext())
      {
         SerializableTargetModuleID module = (SerializableTargetModuleID)modules.next();
         if (module.getModuleType() == moduleType)
            matches.add(module);
      }

      SerializableTargetModuleID[] ids = new SerializableTargetModuleID[matches.size()];
      matches.toArray(ids);
      return ids;
   
public javax.management.ObjectNamegetCARDeployer()

return
The CARDeployer mbean name
jmx:managed-attribute

      return carDeployer;
   
public javax.management.ObjectNamegetEARDeployer()

return
The EARDeployer mbean name
jmx:managed-attribute

      return earDeployer;
   
public javax.management.ObjectNamegetEJBDeployer()

return
The EJBDeployer mbean name
jmx:managed-attribute

      return ejbDeployer;
   
public javax.management.ObjectNamegetMainDeployer()


     
   
      return mainDeployer;
   
public java.util.MapgetModuleMap()

      return Collections.unmodifiableMap(moduleMap);
   
private javax.enterprise.deploy.shared.ModuleTypegetModuleType(org.jboss.deployment.DeploymentInfo info)

      if (info.deployer == null)
         return null;

      ModuleType type = null;
      ObjectName deployer = info.deployer.getServiceName();

      // Validate an ejb vs car based on the watch url
      if (deployer.equals(carDeployer))
      {
         type = ModuleType.CAR;
      }
      else if (deployer.equals(ejbDeployer))
      {
         type = ModuleType.EJB;
      }
      else if (deployer.equals(earDeployer))
      {
         type = ModuleType.EAR;
      }
      else if (deployer.equals(rarDeployer))
      {
         type = ModuleType.RAR;
      }
      else if (deployer.equals(warDeployer))
      {
         type = ModuleType.WAR;
      }

      return type;
   
public javax.management.ObjectNamegetRARDeployer()

return
The RARDeployer mbean name
jmx:managed-attribute

      return rarDeployer;
   
public java.io.FilegetUploadDir()

      return this.uploadDir;
   
public javax.management.ObjectNamegetWARDeployer()

return
The WARDeployer mbean name
jmx:managed-attribute

      return warDeployer;
   
public booleanisDeleteOnUndeploy()

      return deleteOnUndeploy;
   
public booleanisFailOnCollision()

      return failOnCollision;
   
public voidsetCARDeployer(javax.management.ObjectName name)

param
name The CARDeployer mbean name
jmx:managed-attribute

      this.carDeployer = name;
   
public voidsetDeleteOnUndeploy(boolean deleteOnUndeploy)

      this.deleteOnUndeploy = deleteOnUndeploy;
   
public voidsetEARDeployer(javax.management.ObjectName name)

param
name The EARDeployer mbean name
jmx:managed-attribute

      this.earDeployer = name;
   
public voidsetEJBDeployer(javax.management.ObjectName name)

param
name The EJBDeployer mbean name
jmx:managed-attribute

      this.ejbDeployer = name;
   
public voidsetFailOnCollision(boolean failOnCollision)

      this.failOnCollision = failOnCollision;
   
public voidsetMainDeployer(javax.management.ObjectName mainDeployer)

      this.mainDeployer = mainDeployer;
   
public voidsetRARDeployer(javax.management.ObjectName name)

param
name The RARDeployer mbean name
jmx:managed-attribute

      this.rarDeployer = name;
   
public voidsetUploadDir(java.io.File uploadDir)

      this.uploadDir = uploadDir;
   
public voidsetWARDeployer(javax.management.ObjectName name)

param
name The WARDeployer mbean name
jmx:managed-attribute

      this.warDeployer = name;
   
public voidstart(java.lang.String url)

      SerializableTargetModuleID moduleID = (SerializableTargetModuleID)moduleMap.get(url);
      if (moduleID == null)
         throw new IOException("deployURL(" + url + ") has not been distributed");

      URL deployURL = new URL(url);
      // Build the local path
      File path = new File(deployURL.getFile());
      String archive = path.getName();
      File deployFile = new File(uploadDir, archive);
      if (deployFile.exists() == false)
         throw new IOException("deployURL(" + url + ") has no local archive");

      MainDeployerMBean proxy = (MainDeployerMBean)MBeanServerInvocationHandler.newProxyInstance(server, mainDeployer, MainDeployerMBean.class, false);
      proxy.deploy(deployFile.toURL());
      moduleID.setRunning(true);
      moduleID.clearChildModuleIDs();
      // Repopulate the child modules
      DeploymentInfo info = proxy.getDeployment(deployFile.toURL());
      fillChildrenTargetModuleID(moduleID, info);
   
public voidstop(java.lang.String url)

      SerializableTargetModuleID moduleID = (SerializableTargetModuleID)moduleMap.get(url);
      if (moduleID == null)
         throw new IOException("deployURL(" + url + ") has not been distributed");

      URL deployURL = new URL(url);
      // Build the local path
      File path = new File(deployURL.getFile());
      String archive = path.getName();
      File deployFile = new File(uploadDir, archive);
      if (deployFile.exists() == false)
         throw new IOException("deployURL(" + url + ") has no local archive");

      MainDeployerMBean proxy = (MainDeployerMBean)MBeanServerInvocationHandler.newProxyInstance(server, mainDeployer, MainDeployerMBean.class, false);
      proxy.undeploy(deployFile.toURL());
      moduleID.setRunning(false);
   
public voidundeploy(java.lang.String url)

      SerializableTargetModuleID moduleID = (SerializableTargetModuleID)moduleMap.get(url);
      if (moduleID == null)
         return;

      // If the module is still running, stop it
      if (moduleID.isRunning())
         stop(url);

      URL deployURL = new URL(url);
      // Build the local path
      File path = new File(deployURL.getFile());
      String archive = path.getName();
      File deployFile = new File(uploadDir, archive);
      if (deployFile.exists() == false)
         throw new IOException("deployURL(" + url + ") has not been distributed");

      if (deleteOnUndeploy)
         Files.delete(deployFile);

      moduleMap.remove(url);