[jboss-cvs] JBossAS SVN: r87172 - in projects/bootstrap/trunk/spi/src/main/java/org/jboss/bootstrap/spi: server and 1 other directory.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Sun Apr 12 03:22:47 EDT 2009


Author: ALRubinger
Date: 2009-04-12 03:22:47 -0400 (Sun, 12 Apr 2009)
New Revision: 87172

Modified:
   projects/bootstrap/trunk/spi/src/main/java/org/jboss/bootstrap/spi/config/AbstractBasicServerConfig.java
   projects/bootstrap/trunk/spi/src/main/java/org/jboss/bootstrap/spi/config/ServerConfig.java
   projects/bootstrap/trunk/spi/src/main/java/org/jboss/bootstrap/spi/server/AbstractServer.java
Log:
[JBBOOT-27] Some scoping, thread safety

Modified: projects/bootstrap/trunk/spi/src/main/java/org/jboss/bootstrap/spi/config/AbstractBasicServerConfig.java
===================================================================
--- projects/bootstrap/trunk/spi/src/main/java/org/jboss/bootstrap/spi/config/AbstractBasicServerConfig.java	2009-04-11 21:13:26 UTC (rev 87171)
+++ projects/bootstrap/trunk/spi/src/main/java/org/jboss/bootstrap/spi/config/AbstractBasicServerConfig.java	2009-04-12 07:22:47 UTC (rev 87172)
@@ -35,7 +35,7 @@
 import org.jboss.logging.Logger;
 
 /**
- * BasicServerConfig
+ * AbstractBasicServerConfig
  * 
  * Base for simple Object-backed implementations of a Server 
  * Configuration.  As this is exported from the Server, this 
@@ -125,8 +125,10 @@
     *       to be used in casting for covarient return types
     * @param overrideProperties A Map of properties to override those found 
     *           in System Properties
+    * @throws IllegalArgumentException If the actual class is not specified
     */
    public AbstractBasicServerConfig(final Class<T> actualClass, final Map<String, String> overrideProperties)
+         throws IllegalArgumentException
    {
       /*
        * Initialize properties
@@ -154,10 +156,7 @@
        * Set properties
        */
       this.properties = properties;
-      synchronized (this)
-      {
-         this.actualClass = actualClass;
-      }
+      this.setActualClass(actualClass);
       this.frozen = new AtomicBoolean(false);
    }
 
@@ -381,6 +380,26 @@
    }
 
    /**
+    * Sets the actual class to be used in casting to covarient return types
+    * 
+    * @param actualClass
+    * @throws IllegalArgumentException
+    */
+   private synchronized void setActualClass(Class<T> actualClass) throws IllegalArgumentException
+   {
+      // Precondition check
+      if (actualClass == null)
+      {
+         throw new IllegalArgumentException("Actual Class must be specified");
+      }
+      if (log.isTraceEnabled())
+      {
+         log.trace("Setting actual class " + actualClass + " for: " + this);
+      }
+      this.actualClass = actualClass;
+   }
+
+   /**
     * Casts this configuration to the requisite type, using 
     * the actual implementation class.  This is in place to
     * avoid unchecked casting (ie. (T)this)) and the resultant compiler 

Modified: projects/bootstrap/trunk/spi/src/main/java/org/jboss/bootstrap/spi/config/ServerConfig.java
===================================================================
--- projects/bootstrap/trunk/spi/src/main/java/org/jboss/bootstrap/spi/config/ServerConfig.java	2009-04-11 21:13:26 UTC (rev 87171)
+++ projects/bootstrap/trunk/spi/src/main/java/org/jboss/bootstrap/spi/config/ServerConfig.java	2009-04-12 07:22:47 UTC (rev 87172)
@@ -33,7 +33,7 @@
  * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
  * @version $Revision: $
  */
-public interface ServerConfig<T extends ServerConfig<?>>
+public interface ServerConfig<T extends ServerConfig<T>>
 {
    //-------------------------------------------------------------------------------------||
    // Properties -------------------------------------------------------------------------||

Modified: projects/bootstrap/trunk/spi/src/main/java/org/jboss/bootstrap/spi/server/AbstractServer.java
===================================================================
--- projects/bootstrap/trunk/spi/src/main/java/org/jboss/bootstrap/spi/server/AbstractServer.java	2009-04-11 21:13:26 UTC (rev 87171)
+++ projects/bootstrap/trunk/spi/src/main/java/org/jboss/bootstrap/spi/server/AbstractServer.java	2009-04-12 07:22:47 UTC (rev 87172)
@@ -35,7 +35,7 @@
 /**
  * AbstractServer
  * 
- * Generic support for 
+ * Generic support for implementations of a Server
  *
  * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
  * @version $Revision: $
@@ -65,24 +65,26 @@
    private T configuration;
 
    /**
-    * Validator for the configuration
+    * Validator for the configuration.  Synchronized on "this".  Requires
+    * Thread-safe imple (as it's exported)
     */
    private ConfigurationValidator<T> validator;
 
    /**
-    * Server initializer
+    * Server initializer.  Synchronized on "this".  Requires
+    * Thread-safe imple (as it's exported)
     */
    private ServerInitializer<K, T> initializer;
 
    /**
     * The list of bootstraps to run upon start, requires Thread-safe impl.
     */
-   private List<Bootstrap> bootstraps;
+   private final List<Bootstrap> bootstraps = new CopyOnWriteArrayList<Bootstrap>();
 
    /**
     * The bootstraps that have been started, requires Thread-safe impl.
     */
-   private List<Bootstrap> startedBootstraps;
+   private final List<Bootstrap> startedBootstraps = new CopyOnWriteArrayList<Bootstrap>();
 
    //-------------------------------------------------------------------------------------||
    // Constructors -----------------------------------------------------------------------||
@@ -101,14 +103,12 @@
     * 
     * @param configuration The configuration to set
     */
-   protected AbstractServer(final T configuration)
+   protected AbstractServer(final T configuration) throws IllegalArgumentException
    {
       // Check for valid config and set
       this.setConfiguration(configuration);
 
       // Set properties
-      this.setBootstraps(new CopyOnWriteArrayList<Bootstrap>());
-      this.setStartedBootstraps(new CopyOnWriteArrayList<Bootstrap>());
       this.setState(LifecycleState.PRE_INIT);
    }
 
@@ -119,7 +119,7 @@
    /* (non-Javadoc)
     * @see org.jboss.bootstrap.spi.server.Server#getConfiguration()
     */
-   public final T getConfiguration()
+   public synchronized final T getConfiguration()
    {
       return this.configuration;
    }
@@ -127,7 +127,7 @@
    /* (non-Javadoc)
     * @see org.jboss.bootstrap.spi.server.Server#setConfiguration(org.jboss.bootstrap.spi.config.ServerConfig)
     */
-   public void setConfiguration(final T configuration)
+   public synchronized final void setConfiguration(final T configuration)
    {
       // Log and set
       if (log.isTraceEnabled())
@@ -140,9 +140,9 @@
    /* (non-Javadoc)
     * @see org.jboss.bootstrap.spi.server.Server#getState()
     */
-   public final synchronized LifecycleState getState()
+   public synchronized final LifecycleState getState()
    {
-      LifecycleState state = this.state;
+      final LifecycleState state = this.state;
       if (state == null)
       {
          throw new IllegalStateException("null state");
@@ -153,7 +153,7 @@
    /* (non-Javadoc)
     * @see org.jboss.bootstrap.spi.server.Server#shutdown()
     */
-   public void shutdown() throws IllegalStateException, Exception
+   public synchronized void shutdown() throws IllegalStateException, Exception
    {
       // Log
       if (log.isTraceEnabled())
@@ -162,8 +162,8 @@
       }
 
       // Ensure running
-      LifecycleState required = LifecycleState.STARTED;
-      LifecycleState actual = this.getState();
+      final LifecycleState required = LifecycleState.STARTED;
+      final LifecycleState actual = this.getState();
       this.checkState(required, actual);
 
       // Initiate shutdown sequence
@@ -192,7 +192,7 @@
    /* (non-Javadoc)
     * @see org.jboss.bootstrap.spi.server.Server#start()
     */
-   public void start() throws IllegalStateException, Exception
+   public synchronized void start() throws IllegalStateException, Exception
    {
       // Log
       if (log.isTraceEnabled())
@@ -269,7 +269,7 @@
    /* (non-Javadoc)
     * @see org.jboss.bootstrap.spi.server.Server#getValidator()
     */
-   public ConfigurationValidator<T> getValidator()
+   public synchronized final ConfigurationValidator<T> getValidator()
    {
       return this.validator;
    }
@@ -287,14 +287,14 @@
        */
 
       // State must be pre-initialized
-      LifecycleState state = this.getState();
+      final LifecycleState state = this.getState();
       if (!state.equals(LifecycleState.PRE_INIT))
       {
          throw new IllegalStateException("Cannot initialize an already initialized server, state is: " + state);
       }
 
       // Config must be in place
-      T config = this.getConfiguration();
+      final T config = this.getConfiguration();
       if (config == null)
       {
          throw new IllegalStateException("Configuration must be supplied before server is initialized");
@@ -306,7 +306,7 @@
       /*
        * If there's an initializer, use it
        */
-      ServerInitializer<K, T> initializer = this.getInitializer();
+      final ServerInitializer<K, T> initializer = this.getInitializer();
       if (initializer != null)
       {
          initializer.initialize(this);
@@ -326,7 +326,7 @@
    /* (non-Javadoc)
     * @see org.jboss.bootstrap.spi.server.Server#getInitializer()
     */
-   public ServerInitializer<K, T> getInitializer()
+   public synchronized final ServerInitializer<K, T> getInitializer()
    {
       return this.initializer;
    }
@@ -334,7 +334,8 @@
    /* (non-Javadoc)
     * @see org.jboss.bootstrap.spi.server.Server#setInitializer(org.jboss.bootstrap.spi.server.ServerInitializer)
     */
-   public void setInitializer(final ServerInitializer<K, T> initializer) throws IllegalStateException
+   public synchronized final void setInitializer(final ServerInitializer<K, T> initializer)
+         throws IllegalStateException
    {
       this.initializer = initializer;
       log.debug("Set initializer to " + initializer);
@@ -343,7 +344,7 @@
    /* (non-Javadoc)
     * @see org.jboss.bootstrap.spi.server.Server#setConfigurationValidator(org.jboss.bootstrap.spi.config.ConfigurationValidator)
     */
-   public void setValidator(final ConfigurationValidator<T> validator)
+   public synchronized final void setValidator(final ConfigurationValidator<T> validator)
    {
       log.debug("Setting validator to: " + validator);
       this.validator = validator;
@@ -361,7 +362,7 @@
       }
 
       // Get the validator
-      ConfigurationValidator<T> validator = this.getValidator();
+      final ConfigurationValidator<T> validator = this.getValidator();
 
       // Is specified, validate
       if (validator != null)
@@ -479,14 +480,6 @@
    }
 
    /**
-    * @param bootstraps the bootstraps to set
-    */
-   private void setBootstraps(final List<Bootstrap> bootstraps)
-   {
-      this.bootstraps = bootstraps;
-   }
-
-   /**
     * @return the startedBootstraps
     */
    private List<Bootstrap> getStartedBootstraps()
@@ -495,14 +488,6 @@
    }
 
    /**
-    * @param startedBootstraps the startedBootstraps to set
-    */
-   private void setStartedBootstraps(final List<Bootstrap> startedBootstraps)
-   {
-      this.startedBootstraps = startedBootstraps;
-   }
-
-   /**
     * @param state the state to set
     */
    private synchronized final void setState(final LifecycleState state)




More information about the jboss-cvs-commits mailing list