1 22 package org.jboss.deployment.spi; 23 24 import java.io.File ; 25 import java.io.PrintWriter ; 26 import java.io.StringWriter ; 27 import java.net.MalformedURLException ; 28 import java.net.URL ; 29 30 import javax.enterprise.deploy.shared.CommandType ; 31 import javax.enterprise.deploy.shared.StateType ; 32 import javax.enterprise.deploy.spi.TargetModuleID ; 33 import javax.enterprise.deploy.spi.status.ProgressObject ; 34 35 import org.jboss.deployment.spi.status.ProgressObjectImpl; 36 import org.jboss.logging.Logger; 37 38 45 public class DeploymentWorker extends Thread 46 { 47 private static final Logger log = Logger.getLogger(DeploymentWorker.class); 49 50 private ProgressObjectImpl progress; 51 52 public DeploymentWorker(ProgressObject progress) 53 { 54 this.progress = (ProgressObjectImpl)progress; 55 } 56 57 60 public void run() 61 { 62 63 CommandType cmdType = progress.getDeploymentStatus().getCommand(); 64 TargetModuleID [] modules = progress.getResultTargetModuleIDs(); 65 for (int i = 0; i < modules.length; i++) 66 { 67 TargetModuleID moduleid = modules[i]; 68 JBossTarget target = (JBossTarget)moduleid.getTarget(); 69 try 70 { 71 progress.sendProgressEvent(StateType.RUNNING, "Operation " + cmdType + " started", moduleid); 72 if (cmdType == CommandType.DISTRIBUTE) 73 { 74 target.deploy(moduleid); 75 deleteDeployment(moduleid); 76 } 77 else if (cmdType == CommandType.START) 78 { 79 target.start(moduleid); 80 } 81 else if (cmdType == CommandType.STOP) 82 { 83 target.stop(moduleid); 84 } 85 else if (cmdType == CommandType.UNDEPLOY) 86 { 87 target.undeploy(moduleid); 88 deleteDeployment(moduleid); 89 } 90 progress.sendProgressEvent(StateType.COMPLETED, "Operation " + cmdType + " completed", moduleid); 91 } 92 catch (Exception e) 93 { 94 String message = "Operation " + cmdType + " failed on target " + target; 95 StringWriter sw = new StringWriter (); 96 PrintWriter pw = new PrintWriter (sw); 97 pw.println(message); 98 e.printStackTrace(pw); 99 pw.close(); 100 message = sw.toString(); 101 progress.sendProgressEvent(StateType.FAILED, message, moduleid); 102 log.error(message, e); 103 } 104 } 105 } 106 107 private void deleteDeployment(TargetModuleID moduleid) throws MalformedURLException 108 { 109 File deployment = new File (new URL (moduleid.getModuleID()).getPath()); 110 if (deployment.exists()) 111 { 112 if (!deployment.delete()) 113 { 114 log.warn("Cannot delete deployment file " + deployment + ", will be deleted on exit"); 115 deployment.deleteOnExit(); 116 } 117 } 118 else 119 { 120 log.error("Deployment does not exist: " + deployment); 121 } 122 } 123 } 124 | Popular Tags |