You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by dj...@apache.org on 2005/02/18 07:56:50 UTC
svn commit: r154242 - in
geronimo/trunk/modules/deploy-tool/src/java/org/apache/geronimo/deployment/plugin/local:
AbstractDeployCommand.java CommandSupport.java DistributeCommand.java
RedeployCommand.java
Author: djencks
Date: Thu Feb 17 22:56:48 2005
New Revision: 154242
URL: http://svn.apache.org/viewcvs?view=rev&rev=154242
Log:
If the event has already happened, send it to newly registering listeners on registration. Also refactor and fix RedeployCommand
Modified:
geronimo/trunk/modules/deploy-tool/src/java/org/apache/geronimo/deployment/plugin/local/AbstractDeployCommand.java
geronimo/trunk/modules/deploy-tool/src/java/org/apache/geronimo/deployment/plugin/local/CommandSupport.java
geronimo/trunk/modules/deploy-tool/src/java/org/apache/geronimo/deployment/plugin/local/DistributeCommand.java
geronimo/trunk/modules/deploy-tool/src/java/org/apache/geronimo/deployment/plugin/local/RedeployCommand.java
Modified: geronimo/trunk/modules/deploy-tool/src/java/org/apache/geronimo/deployment/plugin/local/AbstractDeployCommand.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/deploy-tool/src/java/org/apache/geronimo/deployment/plugin/local/AbstractDeployCommand.java?view=diff&r1=154241&r2=154242
==============================================================================
--- geronimo/trunk/modules/deploy-tool/src/java/org/apache/geronimo/deployment/plugin/local/AbstractDeployCommand.java (original)
+++ geronimo/trunk/modules/deploy-tool/src/java/org/apache/geronimo/deployment/plugin/local/AbstractDeployCommand.java Thu Feb 17 22:56:48 2005
@@ -18,16 +18,21 @@
import java.util.Set;
import java.util.Iterator;
+import java.util.List;
import java.io.File;
import java.io.InputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.FileOutputStream;
import javax.enterprise.deploy.shared.CommandType;
+import javax.enterprise.deploy.spi.TargetModuleID;
+import javax.enterprise.deploy.spi.Target;
import javax.management.ObjectName;
import org.apache.geronimo.kernel.jmx.JMXUtil;
import org.apache.geronimo.kernel.jmx.KernelMBean;
+import org.apache.geronimo.common.DeploymentException;
+import org.apache.geronimo.deployment.plugin.TargetModuleIDImpl;
/**
* @version $Rev: $ $Date: $
@@ -36,10 +41,21 @@
private final static String DEPLOYER_NAME = "*:name=Deployer,j2eeType=Deployer,*";
protected final KernelMBean kernel;
+ private static final String[] DEPLOY_SIG = {File.class.getName(), File.class.getName()};
+ protected final boolean spool;
+ protected File moduleArchive;
+ protected File deploymentPlan;
+ protected InputStream moduleStream;
+ protected InputStream deploymentStream;
- public AbstractDeployCommand(CommandType command, KernelMBean kernel) {
+ public AbstractDeployCommand(CommandType command, KernelMBean kernel, File moduleArchive, File deploymentPlan, InputStream moduleStream, InputStream deploymentStream, boolean spool) {
super(command);
this.kernel = kernel;
+ this.moduleArchive = moduleArchive;
+ this.deploymentPlan = deploymentPlan;
+ this.moduleStream = moduleStream;
+ this.deploymentStream = deploymentStream;
+ this.spool = spool;
}
protected ObjectName getDeployerName() {
@@ -69,5 +85,24 @@
} finally {
os.close();
}
+ }
+
+ protected void doDeploy(ObjectName deployer, Target target) throws Exception {
+ Object[] args = {moduleArchive, deploymentPlan};
+ List objectNames = (List) kernel.invoke(deployer, "deploy", args, DEPLOY_SIG);
+ if (objectNames == null || objectNames.isEmpty()) {
+ DeploymentException deploymentException = new DeploymentException("Got empty list");
+ deploymentException.printStackTrace();
+ throw deploymentException;
+ }
+ String parentName = (String) objectNames.get(0);
+ String[] childIDs = new String[objectNames.size()-1];
+ for (int j=0; j < childIDs.length; j++) {
+ childIDs[j] = (String)objectNames.get(j+1);
+ }
+
+ TargetModuleID moduleID = new TargetModuleIDImpl(target, parentName.toString(), childIDs);
+ addModule(moduleID);
+ complete("Completed with id " + parentName);
}
}
Modified: geronimo/trunk/modules/deploy-tool/src/java/org/apache/geronimo/deployment/plugin/local/CommandSupport.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/deploy-tool/src/java/org/apache/geronimo/deployment/plugin/local/CommandSupport.java?view=diff&r1=154241&r2=154242
==============================================================================
--- geronimo/trunk/modules/deploy-tool/src/java/org/apache/geronimo/deployment/plugin/local/CommandSupport.java (original)
+++ geronimo/trunk/modules/deploy-tool/src/java/org/apache/geronimo/deployment/plugin/local/CommandSupport.java Thu Feb 17 22:56:48 2005
@@ -36,8 +36,6 @@
import javax.management.MBeanException;
/**
- *
- *
* @version $Rev$ $Date$
*/
public abstract class CommandSupport implements ProgressObject, Runnable {
@@ -49,6 +47,8 @@
private final List moduleIDs = new ArrayList();
private boolean logErrors;
+ private ProgressEvent event = null;
+
protected CommandSupport(CommandType command) {
this.command = command;
this.action = ActionType.EXECUTE;
@@ -88,8 +88,15 @@
throw new OperationUnsupportedException("stop not supported");
}
- public synchronized void addProgressListener(ProgressListener pol) {
- listeners.add(pol);
+ public void addProgressListener(ProgressListener pol) {
+ ProgressEvent event = null;
+ synchronized (this) {
+ listeners.add(pol);
+ event = this.event;
+ }
+ if (event != null) {
+ pol.handleProgressEvent(event);
+ }
}
public synchronized void removeProgressListener(ProgressListener pol) {
@@ -107,20 +114,20 @@
protected void doFail(Exception e) {
// todo dain: kernel does not throw any JMX exceptions anymore... do we still need this
if (e instanceof MBeanException) {
- e = ((MBeanException)e).getTargetException();
+ e = ((MBeanException) e).getTargetException();
}
-
- if( logErrors ) {
- System.err.println("Deployer operation failed: "+e.getMessage());
- e.printStackTrace(System.err);
+
+ if (logErrors) {
+ System.err.println("Deployer operation failed: " + e.getMessage());
+ e.printStackTrace(System.err);
}
-
+
StringWriter writer = new StringWriter();
- PrintWriter printWriter = new PrintWriter(writer);
- printWriter.println(e.getMessage());
- e.printStackTrace(printWriter);
- fail(writer.toString());
- }
+ PrintWriter printWriter = new PrintWriter(writer);
+ printWriter.println(e.getMessage());
+ e.printStackTrace(printWriter);
+ fail(writer.toString());
+ }
private void sendEvent(String message, StateType state) {
assert !Thread.holdsLock(this) : "Trying to send event whilst holding lock";
@@ -132,9 +139,9 @@
this.state = state;
newStatus = getDeploymentStatus();
toNotify = (ProgressListener[]) listeners.toArray(new ProgressListener[listeners.size()]);
+ event = new ProgressEvent(this, null, newStatus);
}
- ProgressEvent event = new ProgressEvent(this, null, newStatus);
for (int i = 0; i < toNotify.length; i++) {
toNotify[i].handleProgressEvent(event);
}
@@ -193,12 +200,12 @@
return buf.toString();
}
}
-
- public boolean isLogErrors() {
- return logErrors;
- }
-
- public void setLogErrors(boolean logErrors) {
- this.logErrors = logErrors;
- }
+
+ public boolean isLogErrors() {
+ return logErrors;
+ }
+
+ public void setLogErrors(boolean logErrors) {
+ this.logErrors = logErrors;
+ }
}
Modified: geronimo/trunk/modules/deploy-tool/src/java/org/apache/geronimo/deployment/plugin/local/DistributeCommand.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/deploy-tool/src/java/org/apache/geronimo/deployment/plugin/local/DistributeCommand.java?view=diff&r1=154241&r2=154242
==============================================================================
--- geronimo/trunk/modules/deploy-tool/src/java/org/apache/geronimo/deployment/plugin/local/DistributeCommand.java (original)
+++ geronimo/trunk/modules/deploy-tool/src/java/org/apache/geronimo/deployment/plugin/local/DistributeCommand.java Thu Feb 17 22:56:48 2005
@@ -39,30 +39,16 @@
* @version $Rev$ $Date$
*/
public class DistributeCommand extends AbstractDeployCommand {
- private static final String[] DEPLOY_SIG = {File.class.getName(), File.class.getName()};
- private final Target[] targetList;
- private final boolean spool;
- private File moduleArchive;
- private File deploymentPlan;
- private InputStream moduleStream;
- private InputStream deploymentStream;
+ protected final Target[] targetList;
public DistributeCommand(KernelMBean kernel, Target[] targetList, File moduleArchive, File deploymentPlan) {
- super(CommandType.DISTRIBUTE, kernel);
+ super(CommandType.DISTRIBUTE, kernel, moduleArchive, deploymentPlan, null, null, false);
this.targetList = targetList;
- this.moduleArchive = moduleArchive;
- this.deploymentPlan = deploymentPlan;
- spool = false;
}
public DistributeCommand(KernelMBean kernel, Target[] targetList, InputStream moduleStream, InputStream deploymentStream) {
- super(CommandType.DISTRIBUTE, kernel);
+ super(CommandType.DISTRIBUTE, kernel, null, null, moduleStream, deploymentStream, true);
this.targetList = targetList;
- this.moduleArchive = null ;
- this.deploymentPlan = null;
- this.moduleStream = moduleStream;
- this.deploymentStream = deploymentStream;
- spool = true;
}
public void run() {
@@ -82,22 +68,8 @@
return;
}
- Object[] args = {moduleArchive, deploymentPlan};
- List objectNames = (List) kernel.invoke(deployer, "deploy", args, DEPLOY_SIG);
- if (objectNames == null || objectNames.isEmpty()) {
- DeploymentException deploymentException = new DeploymentException("Got empty list");
- deploymentException.printStackTrace();
- throw deploymentException;
- }
- String parentName = (String) objectNames.get(0);
- String[] childIDs = new String[objectNames.size()-1];
- for (int j=0; j < childIDs.length; j++) {
- childIDs[j] = (String)objectNames.get(j+1);
- }
+ doDeploy(deployer, targetList[0]);
- TargetModuleID moduleID = new TargetModuleIDImpl(targetList[0], parentName.toString(), childIDs);
- addModule(moduleID);
- complete("Completed with id " + parentName);
} catch (Exception e) {
doFail(e);
} finally {
Modified: geronimo/trunk/modules/deploy-tool/src/java/org/apache/geronimo/deployment/plugin/local/RedeployCommand.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/deploy-tool/src/java/org/apache/geronimo/deployment/plugin/local/RedeployCommand.java?view=diff&r1=154241&r2=154242
==============================================================================
--- geronimo/trunk/modules/deploy-tool/src/java/org/apache/geronimo/deployment/plugin/local/RedeployCommand.java (original)
+++ geronimo/trunk/modules/deploy-tool/src/java/org/apache/geronimo/deployment/plugin/local/RedeployCommand.java Thu Feb 17 22:56:48 2005
@@ -21,6 +21,7 @@
import java.net.URI;
import javax.enterprise.deploy.shared.CommandType;
import javax.enterprise.deploy.spi.TargetModuleID;
+import javax.enterprise.deploy.spi.Target;
import javax.management.ObjectName;
import org.apache.geronimo.deployment.plugin.TargetImpl;
@@ -35,26 +36,15 @@
private static final String[] DEPLOY_SIG = {File.class.getName(), File.class.getName()};
private static final String[] UNINSTALL_SIG = {URI.class.getName()};
private final TargetModuleID[] modules;
- private File moduleArchive;
- private File deploymentPlan;
- private InputStream moduleStream;
- private InputStream deploymentStream;
- private final boolean spool;
-
- public RedeployCommand(KernelMBean kernel, TargetModuleID modules[], File moduleArchive, File deploymentPlan) {
- super(CommandType.START, kernel);
- this.modules = modules;
- this.moduleArchive = moduleArchive;
- this.deploymentPlan = deploymentPlan;
- spool = false;
+
+ public RedeployCommand(KernelMBean kernel, TargetModuleID[] moduleIDList, File moduleArchive, File deploymentPlan) {
+ super(CommandType.DISTRIBUTE, kernel, moduleArchive, deploymentPlan, null, null, false);
+ this.modules = moduleIDList;
}
public RedeployCommand(KernelMBean kernel, TargetModuleID[] moduleIDList, InputStream moduleArchive, InputStream deploymentPlan) {
- super(CommandType.START, kernel);
+ super(CommandType.START, kernel, null, null, moduleArchive, deploymentPlan, true);
this.modules = moduleIDList;
- moduleStream = moduleArchive;
- deploymentStream = deploymentPlan;
- spool = true;
}
public void run() {
@@ -84,14 +74,20 @@
ObjectName storeName = target.getObjectName();
kernel.invoke(storeName, "uninstall", new Object[]{configID}, UNINSTALL_SIG);
- Object[] args = {moduleArchive, deploymentPlan};
- URI configId = (URI) kernel.invoke(deployer, "deploy", args, DEPLOY_SIG);
- module = new TargetModuleIDImpl(module.getTarget(), configId.toString());
- addModule(module);
+ doDeploy(deployer, module.getTarget());
}
complete("Completed");
} catch (Exception e) {
doFail(e);
+ } finally {
+ if (spool) {
+ if (moduleArchive != null) {
+ moduleArchive.delete();
+ }
+ if (deploymentPlan != null) {
+ deploymentPlan.delete();
+ }
+ }
}
}
}