[jboss-cvs] JBossAS SVN: r90584 - in projects/jboss-deployers/trunk: deployers-impl/src/main/java/org/jboss/deployers/plugins/deployers and 1 other directory.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Thu Jun 25 04:42:36 EDT 2009
Author: richard.opalka at jboss.com
Date: 2009-06-25 04:42:36 -0400 (Thu, 25 Jun 2009)
New Revision: 90584
Modified:
projects/jboss-deployers/trunk/deployers-client-spi/src/main/java/org/jboss/deployers/spi/deployer/DeploymentStage.java
projects/jboss-deployers/trunk/deployers-client-spi/src/main/java/org/jboss/deployers/spi/deployer/DeploymentStages.java
projects/jboss-deployers/trunk/deployers-impl/src/main/java/org/jboss/deployers/plugins/deployers/DeployersImpl.java
Log:
[JBDEPLOY-201] implemented DeploymentStage ordering (WIP) - API changes
Modified: projects/jboss-deployers/trunk/deployers-client-spi/src/main/java/org/jboss/deployers/spi/deployer/DeploymentStage.java
===================================================================
--- projects/jboss-deployers/trunk/deployers-client-spi/src/main/java/org/jboss/deployers/spi/deployer/DeploymentStage.java 2009-06-25 08:14:27 UTC (rev 90583)
+++ projects/jboss-deployers/trunk/deployers-client-spi/src/main/java/org/jboss/deployers/spi/deployer/DeploymentStage.java 2009-06-25 08:42:36 UTC (rev 90584)
@@ -24,155 +24,202 @@
import java.io.Serializable;
/**
- * DeploymentStage.
+ * Comparable deployment stage.
*
* @author <a href="adrian at jboss.org">Adrian Brock</a>
+ * @author <a href="ropalka at redhat.com">Richard Opalka</a>
* @version $Revision: 1.1 $
*/
-public class DeploymentStage implements Serializable
+public final class DeploymentStage implements Comparable< DeploymentStage >, Serializable
{
+
+ // TODO: Do I have to provide read/writeObject() methods as well?
/** The serialVersionUID */
- private static final long serialVersionUID = 3302613286025012191L;
+ private static final long serialVersionUID = 3302613286025012192L;
/** Our stage */
- private String name;
+ private final String name;
- /** The previous state */
- private String after;
+ /** The previous stage */
+ private DeploymentStage after;
- /** The next state */
- private String before;
+ /** The next stage */
+ private DeploymentStage before;
+
+ /** Stage index. */
+ private int index;
+
+ /** Computed hashCode(). */
+ private int hashCode;
+
+ /** Computed toString(). */
+ private String toString;
+
+ /** Initialization flag. */
+ private boolean initialized;
/**
- * Safely get the name of stage
+ * Create a new DeploymentStage.
*
- * @param stage the stage
- * @param context the context for an error
- * @return the stage name
+ * @param name the name of the stage
*/
- private static String getStageName(DeploymentStage stage, String context)
+ public DeploymentStage( final String name )
{
- if (stage == null)
- throw new IllegalArgumentException("Null " + context);
- return stage.getName();
+ if ( name == null )
+ {
+ throw new NullPointerException( "Null name" );
+ }
+
+ this.name = name;
}
/**
- * Create a new DeploymentStage.
+ * Initializes this deployment stage and makes it immutable.
*
- * @param name the name of the stage
- * @throws IllegalArgumentException for a null name
+ * @param after the deployment stage preceding this one
+ * @param before the deployment stage following this one
+ * @param index deployment stage index
*/
- public DeploymentStage(String name)
+ public synchronized void initialize( final DeploymentStage after, final DeploymentStage before, final int index )
{
- this(name, (String) null);
+ if ( false == this.initialized )
+ {
+ this.after = after;
+ this.before = before;
+ this.index = index;
+ this.hashCode = computeHashCode();
+ this.toString = computeToString();
+ this.initialized = true;
+ }
}
/**
- * Create a new DeploymentStage.
+ * Get the name.
*
- * @param name the name of the stage
- * @param after the name of the stage before our stage
- * @throws IllegalArgumentException for a null name
+ * @return the name.
*/
- public DeploymentStage(String name, String after)
+ public String getName()
{
- this(name, after, null);
+ return name;
}
/**
- * Create a new DeploymentStage.
+ * Get the after stage.
*
- * @param name the name of the stage
- * @param after the stage before our stage
- * @throws IllegalArgumentException for a null parameter
+ * @return the after stage.
*/
- public DeploymentStage(String name, DeploymentStage after)
+ public DeploymentStage getAfter()
{
- this(name, getStageName(after, "after"), null);
+ return after;
}
/**
- * Create a new DeploymentStage.
+ * Get the before stage.
*
- * @param name the name of the stage
- * @param after he stage before our stage
- * @param before the stage after our stage
- * @throws IllegalArgumentException for a null parameter
+ * @return the before stage.
*/
- public DeploymentStage(String name, DeploymentStage after, DeploymentStage before)
+ public DeploymentStage getBefore()
{
- this(name, getStageName(after, "after"), getStageName(before, "before"));
+ return before;
}
/**
- * Create a new DeploymentStage.
- *
- * @param name the name of the stage
- * @param after the name of the stage before our stage
- * @param before the name of the stage after our stage
- * @throws IllegalArgumentException for a null name
+ * See {@link java.lang.Object#equals(Object)}
*/
- public DeploymentStage(String name, String after, String before)
+ @Override
+ public boolean equals( final Object obj )
{
- if (name == null)
- throw new IllegalArgumentException("Null name");
- this.name = name;
- this.after = after;
- this.before = before;
+ if ( obj == this )
+ {
+ return true;
+ }
+ if ( obj == null || false == ( obj instanceof DeploymentStage ) )
+ {
+ return false;
+ }
+
+ final DeploymentStage other = ( DeploymentStage ) obj;
+
+ if ( false == this.getName().equals( other.getName() ) )
+ {
+ return false;
+ }
+ if ( false == ( this.index == other.index ) )
+ {
+ return false;
+ }
+ if ( false == this.getAfter().equals( other.getAfter() ) )
+ {
+ return false;
+ }
+ if ( false == this.getBefore().equals( other.getBefore() ) )
+ {
+ return false;
+ }
+
+ return true;
}
/**
- * Get the name.
- *
- * @return the name.
+ * See {@link java.lang.Object#hashCode()}
*/
- public String getName()
+ @Override
+ public int hashCode()
{
- return name;
+ return this.hashCode;
}
+
+ /**
+ * See {@link java.lang.Object#toString()}
+ */
+ @Override
+ public String toString()
+ {
+ return this.toString;
+ }
+
+ /**
+ * See {@link java.lang.Comparable#compareTo(Object)}
+ */
+ public int compareTo( final DeploymentStage other )
+ {
+ return this.index - other.index;
+ }
+
/**
- * Get the after.
+ * Computes hashCode - performance optimization.
*
- * @return the after.
+ * @return computed hashCode value
*/
- public String getAfter()
+ private int computeHashCode()
{
- return after;
+ int result = 17;
+
+ result = 37 * result + this.name.hashCode();
+ result = 37 * result + this.index;
+ result = 37 * result + ( this.after == null ? 0 : this.after.hashCode() );
+ result = 37 * result + ( this.before == null ? 0 : this.before.hashCode() );
+
+ return result;
}
/**
- * Get the before.
+ * Computes toString - performance optimization.
*
- * @return the before.
+ * @return computed toString value
*/
- public String getBefore()
+ private String computeToString()
{
- return before;
- }
-
- @Override
- public boolean equals(Object obj)
- {
- if (obj == this)
- return true;
- if (obj == null || obj instanceof DeploymentStage == false)
- return false;
+ final StringBuilder sb = new StringBuilder();
+
+ sb.append( this.getName() ).append( "[after=" );
+ sb.append( ( this.after != null ) ? this.after.getName() : null );
+ sb.append( ",before=" );
+ sb.append( ( this.before != null ) ? this.before.getName() : null );
+ sb.append( "]" );
- DeploymentStage other = (DeploymentStage) obj;
- return getName().equals(other.getName());
+ return sb.toString();
}
- @Override
- public int hashCode()
- {
- return getName().hashCode();
- }
-
- @Override
- public String toString()
- {
- return getName();
- }
}
Modified: projects/jboss-deployers/trunk/deployers-client-spi/src/main/java/org/jboss/deployers/spi/deployer/DeploymentStages.java
===================================================================
--- projects/jboss-deployers/trunk/deployers-client-spi/src/main/java/org/jboss/deployers/spi/deployer/DeploymentStages.java 2009-06-25 08:14:27 UTC (rev 90583)
+++ projects/jboss-deployers/trunk/deployers-client-spi/src/main/java/org/jboss/deployers/spi/deployer/DeploymentStages.java 2009-06-25 08:42:36 UTC (rev 90584)
@@ -22,40 +22,98 @@
package org.jboss.deployers.spi.deployer;
/**
- * The Standard DeploymentStages.
+ * The standard deployment stages.
*
* @author <a href="adrian at jboss.org">Adrian Brock</a>
+ * @author <a href="ropalka at redhat.com">Richard Opalka</a>
* @version $Revision: 1.1 $
*/
-public interface DeploymentStages
+public final class DeploymentStages
{
+
+ /**
+ * Forbidden constructor.
+ */
+ private DeploymentStages()
+ {
+ super();
+ }
+
/** The not installed stage - nothing is done here */
- DeploymentStage NOT_INSTALLED = new DeploymentStage("Not Installed");
+ public static final DeploymentStage NOT_INSTALLED = new DeploymentStage("Not Installed");
/** The parse stage - where metadata is read */
- DeploymentStage PARSE = new DeploymentStage("Parse", NOT_INSTALLED);
+ public static final DeploymentStage PARSE = new DeploymentStage("Parse");
/** The post parse stage - where metadata can be fixed up */
- DeploymentStage POST_PARSE = new DeploymentStage("PostParse", PARSE);
+ public static final DeploymentStage POST_PARSE = new DeploymentStage("PostParse");
/** The pre describe stage - where default dependencies metadata can be created */
- DeploymentStage PRE_DESCRIBE = new DeploymentStage("PreDescribe", POST_PARSE);
+ public static final DeploymentStage PRE_DESCRIBE = new DeploymentStage("PreDescribe");
/** The describe stage - where dependencies are established */
- DeploymentStage DESCRIBE = new DeploymentStage("Describe", PRE_DESCRIBE);
+ public static final DeploymentStage DESCRIBE = new DeploymentStage("Describe");
/** The classloader stage - where classloaders are created */
- DeploymentStage CLASSLOADER = new DeploymentStage("ClassLoader", DESCRIBE);
+ public static final DeploymentStage CLASSLOADER = new DeploymentStage("ClassLoader");
/** The post classloader stage - e.g. aop */
- DeploymentStage POST_CLASSLOADER = new DeploymentStage("PostClassLoader", CLASSLOADER);
+ public static final DeploymentStage POST_CLASSLOADER = new DeploymentStage("PostClassLoader");
/** The pre real stage - where before real deployments are done */
- DeploymentStage PRE_REAL = new DeploymentStage("PreReal", POST_CLASSLOADER);
+ public static final DeploymentStage PRE_REAL = new DeploymentStage("PreReal");
/** The real stage - where real deployment processing is done */
- DeploymentStage REAL = new DeploymentStage("Real", PRE_REAL);
+ public static final DeploymentStage REAL = new DeploymentStage("Real");
/** The installed stage - could be used to provide valve in future? */
- DeploymentStage INSTALLED = new DeploymentStage("Installed", REAL);
+ public static final DeploymentStage INSTALLED = new DeploymentStage("Installed");
+
+ /**
+ * Turn deployment stages into immutable objects.
+ */
+ static
+ {
+ int index = 1;
+ DeploymentStages.NOT_INSTALLED.initialize( null, PARSE, index++ );
+ DeploymentStages.PARSE.initialize( NOT_INSTALLED, POST_PARSE, index++ );
+ DeploymentStages.POST_PARSE.initialize( PARSE, PRE_DESCRIBE, index++ );
+ DeploymentStages.PRE_DESCRIBE.initialize( POST_PARSE, DESCRIBE, index++ );
+ DeploymentStages.DESCRIBE.initialize( PRE_DESCRIBE, CLASSLOADER, index++ );
+ DeploymentStages.CLASSLOADER.initialize( DESCRIBE, POST_CLASSLOADER, index++ );
+ DeploymentStages.POST_CLASSLOADER.initialize( CLASSLOADER, PRE_REAL, index++ );
+ DeploymentStages.PRE_REAL.initialize( POST_CLASSLOADER, REAL, index++ );
+ DeploymentStages.REAL.initialize( PRE_REAL, INSTALLED, index++ );
+ DeploymentStages.INSTALLED.initialize( REAL, null, index++ );
+ }
+
+ /**
+ * Returns DeploymentStage instance associated with <b>stageAsString</b> stage name.
+ *
+ * @param stageAsString name of the stage
+ * @return associated DeploymentStage
+ */
+ public static final DeploymentStage valueOf( final String stageAsString )
+ {
+ if ( null == stageAsString )
+ {
+ throw new NullPointerException( "stage" );
+ }
+
+ DeploymentStage currentStage = DeploymentStages.NOT_INSTALLED;
+ while ( currentStage != null )
+ {
+ if ( currentStage.getName().equals( stageAsString ) )
+ {
+ return currentStage;
+ }
+ else
+ {
+ currentStage = currentStage.getBefore();
+ }
+ }
+
+ throw new IllegalArgumentException( "Uknown stage: " + stageAsString );
+ }
+
}
Modified: projects/jboss-deployers/trunk/deployers-impl/src/main/java/org/jboss/deployers/plugins/deployers/DeployersImpl.java
===================================================================
--- projects/jboss-deployers/trunk/deployers-impl/src/main/java/org/jboss/deployers/plugins/deployers/DeployersImpl.java 2009-06-25 08:14:27 UTC (rev 90583)
+++ projects/jboss-deployers/trunk/deployers-impl/src/main/java/org/jboss/deployers/plugins/deployers/DeployersImpl.java 2009-06-25 08:42:36 UTC (rev 90584)
@@ -330,8 +330,8 @@
return;
ControllerState preceeds = null;
- String before = stage.getBefore();
- String after = stage.getAfter();
+ String before = stage.getBefore() != null ? stage.getBefore().getName() : null;
+ String after = stage.getAfter() != null ? stage.getAfter().getName() : null;
if (before != null || after != null)
{
// Determine where to put the stage
@@ -610,13 +610,22 @@
public DeploymentStage getDeploymentStage(DeploymentContext context) throws DeploymentException
{
- DeploymentControllerContext deploymentControllerContext = context.getTransientAttachments().getAttachment(ControllerContext.class.getName(), DeploymentControllerContext.class);
+ DeploymentControllerContext deploymentControllerContext =
+ context.getTransientAttachments().getAttachment(ControllerContext.class.getName(), DeploymentControllerContext.class);
+
if (deploymentControllerContext == null)
+ {
return null;
+ }
ControllerState state = deploymentControllerContext.getState();
if (ControllerState.ERROR.equals(state))
+ {
return DeploymentStages.NOT_INSTALLED;
- return new DeploymentStage(state.getStateString());
+ }
+ else
+ {
+ return DeploymentStages.valueOf( state.getStateString() );
+ }
}
public void change(DeploymentContext context, DeploymentStage stage) throws DeploymentException
More information about the jboss-cvs-commits
mailing list