[jboss-cvs] JBossAS SVN: r90901 - in projects/bootstrap/trunk: impl-base/src/main/java/org/jboss/bootstrap/impl/base/server and 2 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Tue Jul 7 17:01:25 EDT 2009


Author: ALRubinger
Date: 2009-07-07 17:01:25 -0400 (Tue, 07 Jul 2009)
New Revision: 90901

Modified:
   projects/bootstrap/trunk/impl-base/pom.xml
   projects/bootstrap/trunk/impl-base/src/main/java/org/jboss/bootstrap/impl/base/server/AbstractServer.java
   projects/bootstrap/trunk/impl-base/src/test/java/org/jboss/bootstrap/impl/base/server/unit/ServerInitializationTestCase.java
   projects/bootstrap/trunk/impl-base/src/test/java/org/jboss/bootstrap/impl/base/server/unit/ServerLifecycleEventCallbackTestCase.java
   projects/bootstrap/trunk/impl-base/src/test/java/org/jboss/bootstrap/impl/base/server/unit/ServerLifecycleTestCase.java
   projects/bootstrap/trunk/spi/src/main/java/org/jboss/bootstrap/spi/lifecycle/LifecycleState.java
Log:
[JBBOOT-95] Create server states INITIALIZED and INSTANCIATED, updating the appropriate lifecycle callback sequence

Modified: projects/bootstrap/trunk/impl-base/pom.xml
===================================================================
--- projects/bootstrap/trunk/impl-base/pom.xml	2009-07-07 19:29:42 UTC (rev 90900)
+++ projects/bootstrap/trunk/impl-base/pom.xml	2009-07-07 21:01:25 UTC (rev 90901)
@@ -26,7 +26,7 @@
   <properties>
   
     <!-- Versioning -->
-    <version.org.jboss.bootstrap_jboss.bootstrap.spi>2.0.0-alpha-1</version.org.jboss.bootstrap_jboss.bootstrap.spi>
+    <version.org.jboss.bootstrap_jboss.bootstrap.spi>2.0.0-SNAPSHOT</version.org.jboss.bootstrap_jboss.bootstrap.spi>
 
   </properties>
 

Modified: projects/bootstrap/trunk/impl-base/src/main/java/org/jboss/bootstrap/impl/base/server/AbstractServer.java
===================================================================
--- projects/bootstrap/trunk/impl-base/src/main/java/org/jboss/bootstrap/impl/base/server/AbstractServer.java	2009-07-07 19:29:42 UTC (rev 90900)
+++ projects/bootstrap/trunk/impl-base/src/main/java/org/jboss/bootstrap/impl/base/server/AbstractServer.java	2009-07-07 21:01:25 UTC (rev 90901)
@@ -22,6 +22,7 @@
 
 package org.jboss.bootstrap.impl.base.server;
 
+import java.util.Arrays;
 import java.util.EnumSet;
 import java.util.List;
 import java.util.Map;
@@ -200,7 +201,7 @@
       this.setConfiguration(configToSet);
       // Set the state directly (ie. bypass callback contract of setState()), 
       // this isn't *really* a state change so much as an initialization
-      this.state = LifecycleState.PRE_INIT;
+      this.state = LifecycleState.INSTANCIATED;
    }
 
    //-------------------------------------------------------------------------------------||
@@ -337,7 +338,7 @@
       }
 
       // Invoke init() if necessary
-      if (getState().equals(LifecycleState.PRE_INIT))
+      if (getState().equals(LifecycleState.INSTANCIATED))
       {
          log.debug("Invoking implicit initialization from start()");
          AbstractServer.this.initialize();
@@ -510,16 +511,13 @@
    public synchronized void initialize() throws IllegalStateException, InvalidConfigurationException,
          LifecycleEventException
    {
-      // Log
-      log.debug("Initializing server: " + this);
-
       /*
        * Precondition checks
        */
 
-      // State must be pre-initialized
+      // State must be instanciated
       final LifecycleState state = this.getState();
-      if (!state.equals(LifecycleState.PRE_INIT))
+      if (!state.equals(LifecycleState.INSTANCIATED))
       {
          throw new IllegalStateException("Cannot initialize an already initialized server, state is: " + state);
       }
@@ -531,6 +529,12 @@
          throw new IllegalStateException("Configuration must be supplied before server is initialized");
       }
 
+      // Log
+      log.debug("Initializing server: " + this);
+
+      // Set state to pre-init to fire lifecycle callbacks
+      this.setState(LifecycleState.PRE_INIT);
+
       // If there's a configuration initializer, use it
       final ConfigurationInitializer<T> configInitializer = this.getConfigInitializer();
       if (configInitializer != null)
@@ -572,7 +576,8 @@
       // Freeze config
       config.freeze();
 
-      // Set state
+      // Set state (firing lifecycle callbacks along the way)
+      this.setState(LifecycleState.INITIALIZED);
       this.setState(LifecycleState.IDLE);
    }
 
@@ -591,7 +596,7 @@
          throws IllegalStateException
    {
       // Precondition check
-      this.checkState(LifecycleState.PRE_INIT, this.getState());
+      this.checkMutable(this.getState());
 
       this.serverInitializer = serverInitializer;
       log.debug("Set server initializer to " + serverInitializer);
@@ -611,7 +616,7 @@
    public synchronized final void setConfigInitializer(ConfigurationInitializer<T> configInitializer)
    {
       // Precondition check
-      this.checkState(LifecycleState.PRE_INIT, this.getState());
+      this.checkMutable(this.getState());
 
       this.configInitializer = configInitializer;
       log.debug("Set config initializer to " + configInitializer);
@@ -623,7 +628,7 @@
    public synchronized final void setValidator(final ConfigurationValidator<T> validator)
    {
       // Precondition check
-      this.checkState(LifecycleState.PRE_INIT, this.getState());
+      this.checkMutable(this.getState());
 
       log.debug("Setting validator to: " + validator);
       this.validator = validator;
@@ -929,6 +934,8 @@
     * Ensures the actual state matches the required, throwing {@link IllegalStateException} 
     * if not
     * 
+    * @param required
+    * @param actual
     * @throws IllegalStateException If the actual state does not match required
     */
    private void checkState(final LifecycleState required, final LifecycleState actual) throws IllegalStateException
@@ -942,6 +949,41 @@
    }
 
    /**
+    * Ensures the actual state matches at least one of the required, throwing {@link IllegalStateException} 
+    * if not
+    * 
+    * @param required
+    * @param actual
+    * @throws IllegalStateException If the actual state does not match one of those required
+    */
+   private void checkState(final LifecycleState[] required, final LifecycleState actual) throws IllegalStateException
+   {
+      for (final LifecycleState current : required)
+      {
+         if (current.equals(actual))
+         {
+            // Match, so return OK
+            return;
+         }
+      }
+      // No match found
+      throw new IllegalStateException("Server state must be in one of " + Arrays.asList(required) + "; is instead: "
+            + actual);
+   }
+
+   /**
+    * Ensures the server state is mutable, defined by being either in {@link LifecycleState#INSTANCIATED}
+    * or {@link LifecycleState#PRE_INIT}
+    * 
+    * @throws IllegalStateException If the specified state does not allow for mutable operations
+    */
+   private void checkMutable(final LifecycleState state)
+   {
+      this.checkState(new LifecycleState[]
+      {LifecycleState.INSTANCIATED, LifecycleState.PRE_INIT}, state);
+   }
+
+   /**
     * If {@link Server#getValidator()} is non-null, will
     * assert the configuration is valid using the supplied
     * validator

Modified: projects/bootstrap/trunk/impl-base/src/test/java/org/jboss/bootstrap/impl/base/server/unit/ServerInitializationTestCase.java
===================================================================
--- projects/bootstrap/trunk/impl-base/src/test/java/org/jboss/bootstrap/impl/base/server/unit/ServerInitializationTestCase.java	2009-07-07 19:29:42 UTC (rev 90900)
+++ projects/bootstrap/trunk/impl-base/src/test/java/org/jboss/bootstrap/impl/base/server/unit/ServerInitializationTestCase.java	2009-07-07 21:01:25 UTC (rev 90901)
@@ -103,9 +103,10 @@
       TestServerConfig configuration = TestConfigFactory.createConfiguration();
       final TestNoOpServer server = this.server;
       server.setConfiguration(configuration);
-
+      server.setServerInitializer(serverInitializer);
+      
       // Initialize
-      serverInitializer.initialize(server);
+      server.initialize();
 
       // Get Properties from Configuration
       final String homeFromConfigProp = configuration.getProperties().get(ServerConfig.PROP_KEY_BOOTSTRAP_HOME_URL);

Modified: projects/bootstrap/trunk/impl-base/src/test/java/org/jboss/bootstrap/impl/base/server/unit/ServerLifecycleEventCallbackTestCase.java
===================================================================
--- projects/bootstrap/trunk/impl-base/src/test/java/org/jboss/bootstrap/impl/base/server/unit/ServerLifecycleEventCallbackTestCase.java	2009-07-07 19:29:42 UTC (rev 90900)
+++ projects/bootstrap/trunk/impl-base/src/test/java/org/jboss/bootstrap/impl/base/server/unit/ServerLifecycleEventCallbackTestCase.java	2009-07-07 21:01:25 UTC (rev 90901)
@@ -55,25 +55,15 @@
    /**
     * Message used in test failures
     */
-   private static final String FAIL_MESSAGE = "Expected Callbacs(s) not received or in wrong order";
+   private static final String FAIL_MESSAGE = "Expected Callback(s) not received or in wrong order";
 
    /**
-    * The Idle State
-    */
-   private static final LifecycleState IDLE = LifecycleState.IDLE;
-
-   /**
-    * The Started State
-    */
-   private static final LifecycleState STARTED = LifecycleState.STARTED;
-
-   /**
-    * Expected order of states through full lifecycle. Excludes {@link LifecycleState#PRE_INIT}
+    * Expected order of states through full lifecycle. Excludes {@link LifecycleState#INSTANCIATED}
     * because this is not a state *change* but an init value, so we test for it separately.
     */
    private static final LifecycleState[] EXPECTED_FULL_LIFECYCLE_STATES = new LifecycleState[]
-   {LifecycleState.IDLE, LifecycleState.STARTING, LifecycleState.STARTED, LifecycleState.STOPPING,
-         LifecycleState.STOPPED, LifecycleState.IDLE};
+   {LifecycleState.PRE_INIT, LifecycleState.INITIALIZED, LifecycleState.IDLE, LifecycleState.STARTING,
+         LifecycleState.STARTED, LifecycleState.STOPPING, LifecycleState.STOPPED, LifecycleState.IDLE};
 
    //-------------------------------------------------------------------------------------||
    // Instance Members -------------------------------------------------------------------||

Modified: projects/bootstrap/trunk/impl-base/src/test/java/org/jboss/bootstrap/impl/base/server/unit/ServerLifecycleTestCase.java
===================================================================
--- projects/bootstrap/trunk/impl-base/src/test/java/org/jboss/bootstrap/impl/base/server/unit/ServerLifecycleTestCase.java	2009-07-07 19:29:42 UTC (rev 90900)
+++ projects/bootstrap/trunk/impl-base/src/test/java/org/jboss/bootstrap/impl/base/server/unit/ServerLifecycleTestCase.java	2009-07-07 21:01:25 UTC (rev 90901)
@@ -86,11 +86,11 @@
    @Before
    public void createServer()
    {
-      TestNoOpServer server = new TestNoOpServer();
+      final TestNoOpServer server = new TestNoOpServer();
       server.setServerInitializer(serverInitializer);
       server.setValidator(validator);
       server.setConfigInitializer(configInitializer);
-      TestServerConfig config = TestConfigFactory.createConfiguration();
+      final TestServerConfig config = TestConfigFactory.createConfiguration();
       server.setConfiguration(config);
       this.server = server;
       log.info("Created server: " + server);
@@ -165,9 +165,9 @@
       // Get the server
       final TestNoOpServer server = this.server;
 
-      // Ensure reports as pre-init
+      // Ensure reports as instanciated
       LifecycleState state = server.getState();
-      TestCase.assertEquals("Lifecycle should be preinit", LifecycleState.PRE_INIT, state);
+      TestCase.assertEquals("Lifecycle should be instanciated", LifecycleState.INSTANCIATED, state);
 
       // Init
       server.initialize();

Modified: projects/bootstrap/trunk/spi/src/main/java/org/jboss/bootstrap/spi/lifecycle/LifecycleState.java
===================================================================
--- projects/bootstrap/trunk/spi/src/main/java/org/jboss/bootstrap/spi/lifecycle/LifecycleState.java	2009-07-07 19:29:42 UTC (rev 90900)
+++ projects/bootstrap/trunk/spi/src/main/java/org/jboss/bootstrap/spi/lifecycle/LifecycleState.java	2009-07-07 21:01:25 UTC (rev 90901)
@@ -27,7 +27,12 @@
  *
  * Describes current state of the Server lifecycle
  * 
- * PREINIT == Instanciated, open to configuration, mutable operations permitted
+ * INSTANCIATED == Instanciated, the initial state of new servers.  Never re-enters this state 
+ *   (so lifecycle event callbacks will never be made here)
+ * PRE_INIT == Just prior to initialization, open to configuration, mutable operations permitted.
+ *   In this state no more than once.  
+ * INITIALIZED == Initialization completed, mutable operations frozen.  In this state
+ *   no more than once.
  * IDLE == Not yet started, or has previously stopped.  Awaiting start.
  * STARTING == In start lifecycle
  * STARTED == Fully started, in service
@@ -43,5 +48,5 @@
     * Lifecycle States for Servers
     */
 
-   PRE_INIT, IDLE, STARTING, STARTED, STOPPING, STOPPED
+   INSTANCIATED, PRE_INIT, INITIALIZED, IDLE, STARTING, STARTED, STOPPING, STOPPED
 }




More information about the jboss-cvs-commits mailing list