[jboss-cvs] JBossAS SVN: r84308 - in projects/jboss-deployers/trunk/deployers-impl/src: test/java/org/jboss/test/deployers/main/test and 1 other directory.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Tue Feb 17 09:19:10 EST 2009
Author: alesj
Date: 2009-02-17 09:19:10 -0500 (Tue, 17 Feb 2009)
New Revision: 84308
Modified:
projects/jboss-deployers/trunk/deployers-impl/src/main/java/org/jboss/deployers/plugins/main/MainDeployerImpl.java
projects/jboss-deployers/trunk/deployers-impl/src/test/java/org/jboss/test/deployers/main/test/DeployerCheckCompleteTestCase.java
Log:
[JBDEPLOYER-159]; fix redeploy.
Modified: projects/jboss-deployers/trunk/deployers-impl/src/main/java/org/jboss/deployers/plugins/main/MainDeployerImpl.java
===================================================================
--- projects/jboss-deployers/trunk/deployers-impl/src/main/java/org/jboss/deployers/plugins/main/MainDeployerImpl.java 2009-02-17 13:50:42 UTC (rev 84307)
+++ projects/jboss-deployers/trunk/deployers-impl/src/main/java/org/jboss/deployers/plugins/main/MainDeployerImpl.java 2009-02-17 14:19:10 UTC (rev 84308)
@@ -28,6 +28,8 @@
import java.util.Comparator;
import java.util.List;
import java.util.Map;
+import java.util.ListIterator;
+import java.util.LinkedHashMap;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.atomic.AtomicBoolean;
@@ -102,6 +104,9 @@
private Comparator<DeploymentContext> comparator;
private Comparator<DeploymentContext> reverted;
+ /** The deployment waiting to be processed */
+ private Map<String, Deployment> toDeploy = Collections.synchronizedMap(new LinkedHashMap<String, Deployment>());
+
/**
* Set the top deployment context comparator.
*
@@ -111,6 +116,7 @@
{
if (comparator == null)
throw new IllegalArgumentException("Null comparator");
+
this.comparator = comparator;
this.reverted = new RevertedDeploymentContextComparator(comparator);
}
@@ -135,6 +141,7 @@
{
if (deployers == null)
throw new IllegalArgumentException("Null deployers");
+
this.deployers = deployers;
}
@@ -158,6 +165,7 @@
{
if (deployers == null)
throw new IllegalArgumentException("Null deployers");
+
structuralDeployers = deployers;
}
@@ -184,9 +192,10 @@
public Deployment getDeployment(String name)
{
DeploymentContext context = getTopLevelDeploymentContext(name);
- if (context == null)
- return null;
- return context.getDeployment();
+ if (context != null)
+ return context.getDeployment();
+ else
+ return toDeploy.get(name);
}
@Deprecated
@@ -204,6 +213,7 @@
DeploymentContext context = getDeploymentContext(name);
if (errorNotFound && context == null)
throw new DeploymentException("Context " + name + " not found");
+
return context;
}
@@ -220,6 +230,7 @@
DeploymentUnit unit = getDeploymentUnit(name);
if (errorNotFound && unit == null)
throw new DeploymentException("Unit " + name + " not found");
+
return unit;
}
@@ -233,6 +244,7 @@
{
if (name == null)
throw new IllegalArgumentException("Null name");
+
return topLevelDeployments.get(name);
}
@@ -284,10 +296,61 @@
public void addDeployment(Deployment deployment) throws DeploymentException
{
- addDeployment(deployment, true);
+ if (deployment == null)
+ throw new DeploymentException("Null context");
+
+ String name = deployment.getName();
+ lockRead();
+ try
+ {
+ checkExistingTopLevelDeployment(name, true);
+ toDeploy.put(name, deployment);
+ }
+ finally
+ {
+ unlockRead();
+ }
}
/**
+ * Process added deployments.
+ *
+ * @throws DeploymentException for any error
+ */
+ protected void processToDeploy() throws DeploymentException
+ {
+ List<String> added = new ArrayList<String>();
+
+ try
+ {
+ for (Map.Entry<String, Deployment> entry : toDeploy.entrySet())
+ {
+ determineDeploymentContext(entry.getValue(), true);
+ added.add(entry.getKey());
+ }
+ }
+ catch (DeploymentException e)
+ {
+ ListIterator<String> iter = added.listIterator(added.size());
+ while (iter.hasPrevious())
+ {
+ try
+ {
+ removeDeployment(iter.previous(), true);
+ }
+ catch (Throwable ignored)
+ {
+ }
+ }
+ throw e;
+ }
+ finally
+ {
+ toDeploy.clear();
+ }
+ }
+
+ /**
* Add a deployment
*
* @param deployment the deployment
@@ -308,51 +371,75 @@
String name = deployment.getName();
log.debug("Add deployment: " + name);
- DeploymentContext previous = topLevelDeployments.get(name);
- boolean topLevelFound = false;
+ checkExistingTopLevelDeployment(name, addToDeploy);
+ determineDeploymentContext(deployment, addToDeploy);
+ }
+ finally
+ {
+ unlockRead();
+ }
+ }
+
+ /**
+ * Check for existing deployment context - redeploy.
+ * Method should take read lock.
+ *
+ * @param name the deployment name
+ * @param addToDeploy should we add this deployment to deploy collection
+ */
+ protected void checkExistingTopLevelDeployment(String name, boolean addToDeploy)
+ {
+ DeploymentContext previous = topLevelDeployments.get(name);
+ if (previous != null)
+ {
+ log.debug("Removing previous deployment: " + previous.getName());
+ removeContext(previous, addToDeploy);
+ }
+ else
+ {
+ previous = allDeployments.get(name);
if (previous != null)
- {
- log.debug("Removing previous deployment: " + previous.getName());
- removeContext(previous, addToDeploy);
- topLevelFound = true;
- }
+ throw new IllegalStateException("Deployment already exists as a subdeployment: " + name);
+ }
+ }
- if (topLevelFound == false)
+ /**
+ * Determine deployment context.
+ * Method should take read lock.
+ *
+ * @param deployment the deployment
+ * @param addToDeploy should we add this deployment to deploy collection
+ * @throws DeploymentException for any error
+ */
+ protected void determineDeploymentContext(Deployment deployment, boolean addToDeploy) throws DeploymentException
+ {
+ String name = deployment.getName();
+ DeploymentContext context = null;
+ try
+ {
+ context = determineStructure(deployment);
+ if (DeploymentState.ERROR.equals(context.getState()))
{
- previous = allDeployments.get(name);
- if (previous != null)
- throw new IllegalStateException("Deployment already exists as a subdeployment: " + name);
+ errorDeployments.put(name, context);
}
- DeploymentContext context = null;
- try
- {
- context = determineStructure(deployment);
- if (DeploymentState.ERROR.equals(context.getState()))
- errorDeployments.put(name, context);
-
- context.getTransientAttachments().addAttachment(MainDeployer.class, this);
- topLevelDeployments.put(name, context);
- addContext(context, addToDeploy);
- }
- catch (DeploymentException e)
- {
+ context.getTransientAttachments().addAttachment(MainDeployer.class, this);
+ topLevelDeployments.put(name, context);
+ addContext(context, addToDeploy);
+ }
+ catch (DeploymentException e)
+ {
+ missingDeployers.put(name, deployment);
+ throw e;
+ }
+ catch (Throwable t)
+ {
+ // was structure determined?
+ if (context == null)
missingDeployers.put(name, deployment);
- throw e;
- }
- catch (Throwable t)
- {
- // was structure determined?
- if (context == null)
- missingDeployers.put(name, deployment);
- throw DeploymentException.rethrowAsDeploymentException("Error determining deployment structure for " + name, t);
- }
+ throw DeploymentException.rethrowAsDeploymentException("Error determining deployment structure for " + name, t);
}
- finally
- {
- unlockRead();
- }
}
public boolean removeDeployment(Deployment deployment) throws DeploymentException
@@ -534,15 +621,13 @@
if (deployers == null)
throw new IllegalStateException("No deployers");
- lockRead();
+ lockWrite();
try
{
if (shutdown.get())
throw new IllegalStateException("The main deployer is shutdown");
List<DeploymentContext> undeployContexts = null;
- List<DeploymentContext> deployContexts = null;
-
if (undeploy.isEmpty() == false)
{
// Undeploy in reverse order (subdeployments first)
@@ -553,40 +638,36 @@
Collections.sort(undeployContexts, reverted);
undeploy.clear();
}
- if (deploy.isEmpty() == false)
+ if (undeployContexts != null)
{
- deployContexts = new ArrayList<DeploymentContext>(deploy);
- if (comparator != null)
- Collections.sort(deployContexts, comparator);
- deploy.clear();
+ deployers.process(null, undeployContexts);
}
- if (undeployContexts == null && deployContexts == null)
- {
- log.debug("Asked to process() when there is nothing to do.");
- return;
- }
-
try
{
- deployers.process(deployContexts, undeployContexts);
+ processToDeploy();
}
- catch (RuntimeException e)
+ catch (DeploymentException e)
{
- throw e;
+ throw new RuntimeException("Error while processing new deployments", e);
}
- catch (Error e)
+
+ List<DeploymentContext> deployContexts = null;
+ if (deploy.isEmpty() == false)
{
- throw e;
+ deployContexts = new ArrayList<DeploymentContext>(deploy);
+ if (comparator != null)
+ Collections.sort(deployContexts, comparator);
+ deploy.clear();
}
- catch (Throwable t)
+ if (deployContexts != null)
{
- throw new RuntimeException("Unexpected error in process()", t);
+ deployers.process(deployContexts, null);
}
}
finally
{
- unlockRead();
+ unlockWrite();
}
}
Modified: projects/jboss-deployers/trunk/deployers-impl/src/test/java/org/jboss/test/deployers/main/test/DeployerCheckCompleteTestCase.java
===================================================================
--- projects/jboss-deployers/trunk/deployers-impl/src/test/java/org/jboss/test/deployers/main/test/DeployerCheckCompleteTestCase.java 2009-02-17 13:50:42 UTC (rev 84307)
+++ projects/jboss-deployers/trunk/deployers-impl/src/test/java/org/jboss/test/deployers/main/test/DeployerCheckCompleteTestCase.java 2009-02-17 14:19:10 UTC (rev 84308)
@@ -100,11 +100,11 @@
try
{
main.addDeployment(deployment);
+ main.process();
}
- catch (DeploymentException ignored)
+ catch (Throwable ignored)
{
}
- main.process();
try
{
main.checkComplete();
More information about the jboss-cvs-commits
mailing list