FileDocCategorySizeDatePackage
DeploymentWorker.javaAPI DocJBoss 4.2.14202Fri Jul 13 20:52:34 BST 2007org.jboss.deployment.spi

DeploymentWorker

public class DeploymentWorker extends Thread
A thread that deployes the given deployment on all targets contained in the progress object. It sends events to the progress object.
author
thomas.diesler@jboss.org
version
$Revision: 62526 $

Fields Summary
private static final Logger
log
private org.jboss.deployment.spi.status.ProgressObjectImpl
progress
Constructors Summary
public DeploymentWorker(javax.enterprise.deploy.spi.status.ProgressObject progress)


     
   
      this.progress = (ProgressObjectImpl)progress;
   
Methods Summary
private voiddeleteDeployment(javax.enterprise.deploy.spi.TargetModuleID moduleid)

      File deployment = new File(new URL(moduleid.getModuleID()).getPath());
      if (deployment.exists())
      {
         if (!deployment.delete())
         {
            log.warn("Cannot delete deployment file " + deployment + ", will be deleted on exit");
            deployment.deleteOnExit();
         }
      }
      else
      {
         log.error("Deployment does not exist: " + deployment);
      }
   
public voidrun()
Deploy the module on each given target


      CommandType cmdType = progress.getDeploymentStatus().getCommand();
      TargetModuleID[] modules = progress.getResultTargetModuleIDs();
      for (int i = 0; i < modules.length; i++)
      {
         TargetModuleID moduleid = modules[i];
         JBossTarget target = (JBossTarget)moduleid.getTarget();
         try
         {
            progress.sendProgressEvent(StateType.RUNNING, "Operation " + cmdType + " started", moduleid);
            if (cmdType == CommandType.DISTRIBUTE)
            {
               target.deploy(moduleid);
            }
            else if (cmdType == CommandType.START)
            {
               target.start(moduleid);
            }
            else if (cmdType == CommandType.STOP)
            {
               target.stop(moduleid);
            }
            else if (cmdType == CommandType.UNDEPLOY)
            {
               target.undeploy(moduleid);
               deleteDeployment(moduleid);
            }
            progress.sendProgressEvent(StateType.COMPLETED, "Operation " + cmdType + " completed", moduleid);
         }
         catch (Exception e)
         {
            String message = "Operation " + cmdType + " failed on target " + target;
            StringWriter sw = new StringWriter();
            PrintWriter pw = new PrintWriter(sw);
            pw.println(message);
            e.printStackTrace(pw);
            pw.close();
            message = sw.toString();
            progress.sendProgressEvent(StateType.FAILED, message, moduleid);
            log.error(message, e);
         }
      }