[jboss-cvs] JBossAS SVN: r87174 - in projects/bootstrap/trunk/spi/src: main/java/org/jboss/bootstrap/spi/server and 3 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Sun Apr 12 04:00:17 EDT 2009
Author: ALRubinger
Date: 2009-04-12 04:00:17 -0400 (Sun, 12 Apr 2009)
New Revision: 87174
Added:
projects/bootstrap/trunk/spi/src/main/java/org/jboss/bootstrap/spi/config/AbstractBasicConfigurationInitializer.java
projects/bootstrap/trunk/spi/src/main/java/org/jboss/bootstrap/spi/config/ConfigurationInitializer.java
projects/bootstrap/trunk/spi/src/test/java/org/jboss/bootstrap/spi/config/TestConfigurationInitializer.java
projects/bootstrap/trunk/spi/src/test/java/org/jboss/bootstrap/spi/server/unit/ServerInitializationTestCase.java
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/AbstractBasicServerInitializer.java
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/Server.java
projects/bootstrap/trunk/spi/src/test/java/org/jboss/bootstrap/spi/config/unit/ConfigInitializationTestCase.java
projects/bootstrap/trunk/spi/src/test/java/org/jboss/bootstrap/spi/server/unit/ServerLifecycleTestCase.java
Log:
[JBBOOT-29] Separate config init from server init
Added: projects/bootstrap/trunk/spi/src/main/java/org/jboss/bootstrap/spi/config/AbstractBasicConfigurationInitializer.java
===================================================================
--- projects/bootstrap/trunk/spi/src/main/java/org/jboss/bootstrap/spi/config/AbstractBasicConfigurationInitializer.java (rev 0)
+++ projects/bootstrap/trunk/spi/src/main/java/org/jboss/bootstrap/spi/config/AbstractBasicConfigurationInitializer.java 2009-04-12 08:00:17 UTC (rev 87174)
@@ -0,0 +1,156 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.bootstrap.spi.config;
+
+import java.net.MalformedURLException;
+import java.net.URL;
+
+import org.jboss.logging.Logger;
+
+/**
+ * AbstractBasicConfigurationInitializer
+ *
+ * Base for initializing a configuration before
+ * its validated and used to run a server
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+public abstract class AbstractBasicConfigurationInitializer<T extends ServerConfig<T>>
+ implements
+ ConfigurationInitializer<T>
+{
+
+ //-------------------------------------------------------------------------------------||
+ // Class Members ----------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ private static final Logger log = Logger.getLogger(AbstractBasicConfigurationInitializer.class);
+
+ //-------------------------------------------------------------------------------------||
+ // Required Implementations -----------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /* (non-Javadoc)
+ * @see org.jboss.bootstrap.spi.config.ConfigurationInitializer#initialize(org.jboss.bootstrap.spi.config.ServerConfig)
+ */
+ public void initialize(T config) throws InvalidConfigurationException, IllegalArgumentException,
+ IllegalStateException
+ {
+ // Log
+ if (log.isTraceEnabled())
+ {
+ log.trace("Initializing: " + config);
+ }
+ /*
+ * Default the config
+ */
+
+ final URL bootstrapUrl = config.getBootstrapUrl();
+ final URL home = config.getBootstrapHome();
+ final URL conf = config.getBootstrapConfLocation();
+ final String name = config.getBootstrapName();
+
+ /*
+ * If bootstrapURL is not directly defined, construct it from
+ * home+name
+ */
+
+ if (bootstrapUrl == null)
+ {
+ // Log
+ if (log.isTraceEnabled())
+ {
+ log.trace("No bootstrap URL defined, constructing it from home and name...");
+ }
+
+ // Construct
+ assert home != null : "Bootstrap home should not be null, and should have failed validation if so";
+ assert name != null : "Bootstrap name should not be null, and should have failed validation if so";
+ URL newBootstrapUrl = null;
+ try
+ {
+ newBootstrapUrl = new URL(home, name);
+ }
+ catch (MalformedURLException e)
+ {
+ throw new IllegalArgumentException(new InvalidConfigurationException(
+ "Cannot construct bootstrapURL from home and name", e));
+ }
+
+ // Log
+ log.debug("New bootstrap URL: " + newBootstrapUrl.toExternalForm());
+
+ // Set
+ config.bootstrapUrl(newBootstrapUrl);
+ }
+
+ /*
+ * If bootstrapConf was not initialized, set it from either home or URL base
+ */
+
+ if (conf == null)
+ {
+ // Make a new conf
+ URL newConf = null;
+
+ // If we've got a home
+ if (home != null)
+ {
+ try
+ {
+ String homeExternal = home.toExternalForm();
+ newConf = new URL(homeExternal);
+ log.debug("Defaulted bootstrapConf from bootstrap home: " + homeExternal);
+ }
+ catch (MalformedURLException e)
+ {
+ throw new RuntimeException("Could not default the conf from home", e);
+ }
+ }
+ // If we've got a bootstrapURL
+ else if (bootstrapUrl != null)
+ {
+ try
+ {
+ String bootstrapUrlString = bootstrapUrl.toExternalForm();
+ String bootstrapUrlBase = bootstrapUrlString.substring(0, bootstrapUrlString.lastIndexOf("/") + 1);
+ newConf = new URL(bootstrapUrlBase);
+ log.debug("Defaulted bootstrapConf from bootstrapURL's base: " + bootstrapUrlBase);
+ }
+ catch (MalformedURLException e)
+ {
+ throw new RuntimeException("Could not default the conf from bootstrapURL base", e);
+ }
+ }
+
+ // Set
+ if (newConf != null)
+ {
+ config.bootstrapConfLocation(newConf);
+ }
+ }
+
+ }
+
+}
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-12 07:36:38 UTC (rev 87173)
+++ projects/bootstrap/trunk/spi/src/main/java/org/jboss/bootstrap/spi/config/AbstractBasicServerConfig.java 2009-04-12 08:00:17 UTC (rev 87174)
@@ -35,7 +35,7 @@
import org.jboss.logging.Logger;
/**
- * AbstractBasicServerConfig
+ * BasicServerConfig
*
* Base for simple Object-backed implementations of a Server
* Configuration. As this is exported from the Server, this
@@ -125,10 +125,8 @@
* 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
@@ -156,7 +154,10 @@
* Set properties
*/
this.properties = properties;
- this.setActualClass(actualClass);
+ synchronized (this)
+ {
+ this.actualClass = actualClass;
+ }
this.frozen = new AtomicBoolean(false);
}
@@ -380,26 +381,6 @@
}
/**
- * 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
Added: projects/bootstrap/trunk/spi/src/main/java/org/jboss/bootstrap/spi/config/ConfigurationInitializer.java
===================================================================
--- projects/bootstrap/trunk/spi/src/main/java/org/jboss/bootstrap/spi/config/ConfigurationInitializer.java (rev 0)
+++ projects/bootstrap/trunk/spi/src/main/java/org/jboss/bootstrap/spi/config/ConfigurationInitializer.java 2009-04-12 08:00:17 UTC (rev 87174)
@@ -0,0 +1,47 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.bootstrap.spi.config;
+
+/**
+ * ConfigurationInitializer
+ *
+ * Contract for initializers of a supplied ServerConfig.
+ * May be responsible for setting default values
+ * where unspecified, etc.
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+public interface ConfigurationInitializer<T extends ServerConfig<?>>
+{
+ /**
+ * Initializes the specified configuration
+ *
+ * @param config
+ * @throws InvalidConfigurationException If the configuration was invalid
+ * and initialization was unable to proceed
+ * @throws IllegalArgumentException If the config was not specified
+ * @throws IllegalStateException If the config has been frozen (immutable)
+ */
+ void initialize(T config) throws InvalidConfigurationException, IllegalArgumentException, IllegalStateException;
+}
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-12 07:36:38 UTC (rev 87173)
+++ projects/bootstrap/trunk/spi/src/main/java/org/jboss/bootstrap/spi/config/ServerConfig.java 2009-04-12 08:00:17 UTC (rev 87174)
@@ -33,7 +33,7 @@
* @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
* @version $Revision: $
*/
-public interface ServerConfig<T extends ServerConfig<T>>
+public interface ServerConfig<T extends ServerConfig<?>>
{
//-------------------------------------------------------------------------------------||
// Properties -------------------------------------------------------------------------||
Modified: projects/bootstrap/trunk/spi/src/main/java/org/jboss/bootstrap/spi/server/AbstractBasicServerInitializer.java
===================================================================
--- projects/bootstrap/trunk/spi/src/main/java/org/jboss/bootstrap/spi/server/AbstractBasicServerInitializer.java 2009-04-12 07:36:38 UTC (rev 87173)
+++ projects/bootstrap/trunk/spi/src/main/java/org/jboss/bootstrap/spi/server/AbstractBasicServerInitializer.java 2009-04-12 08:00:17 UTC (rev 87174)
@@ -22,10 +22,8 @@
package org.jboss.bootstrap.spi.server;
-import java.net.MalformedURLException;
import java.net.URL;
-import org.jboss.bootstrap.spi.config.InvalidConfigurationException;
import org.jboss.bootstrap.spi.config.ServerConfig;
import org.jboss.bootstrap.spi.lifecycle.LifecycleState;
import org.jboss.logging.Logger;
@@ -80,96 +78,11 @@
// Obtain config
final T config = server.getConfiguration();
- /*
- * Default the config
- */
-
- final URL bootstrapUrl = config.getBootstrapUrl();
- final URL home = config.getBootstrapHome();
- final URL conf = config.getBootstrapConfLocation();
- final String name = config.getBootstrapName();
-
- /*
- * If bootstrapURL is not directly defined, construct it from
- * home+name
- */
-
- if (bootstrapUrl == null)
+ // Set System Properties
+ if (log.isTraceEnabled())
{
- // Log
- if (log.isTraceEnabled())
- {
- log.trace("No bootstrap URL defined, constructing it from home and name...");
- }
-
- // Construct
- assert home != null : "Bootstrap home should not be null, and should have failed validation if so";
- assert name != null : "Bootstrap name should not be null, and should have failed validation if so";
- URL newBootstrapUrl = null;
- try
- {
- newBootstrapUrl = new URL(home, name);
- }
- catch (MalformedURLException e)
- {
- throw new IllegalArgumentException(new InvalidConfigurationException(
- "Cannot construct bootstrapURL from home and name", e));
- }
-
- // Log
- log.debug("New bootstrap URL: " + newBootstrapUrl.toExternalForm());
-
- // Set
- config.bootstrapUrl(newBootstrapUrl);
+ log.trace("Setting system properties for " + server);
}
-
- /*
- * If bootstrapConf was not initialized, set it from either home or URL base
- */
-
- if (conf == null)
- {
- // Make a new conf
- URL newConf = null;
-
- // If we've got a home
- if (home != null)
- {
- try
- {
- String homeExternal = home.toExternalForm();
- newConf = new URL(homeExternal);
- log.debug("Defaulted bootstrapConf from bootstrap home: " + homeExternal);
- }
- catch (MalformedURLException e)
- {
- throw new RuntimeException("Could not default the conf from home", e);
- }
- }
- // If we've got a bootstrapURL
- else if (bootstrapUrl != null)
- {
- try
- {
- String bootstrapUrlString = bootstrapUrl.toExternalForm();
- String bootstrapUrlBase = bootstrapUrlString.substring(0, bootstrapUrlString.lastIndexOf("/") + 1);
- newConf = new URL(bootstrapUrlBase);
- log.debug("Defaulted bootstrapConf from bootstrapURL's base: " + bootstrapUrlBase);
- }
- catch (MalformedURLException e)
- {
- throw new RuntimeException("Could not default the conf from bootstrapURL base", e);
- }
- }
-
- // Set
- if (newConf != null)
- {
- config.bootstrapConfLocation(newConf);
- }
- }
-
- // Set System Properties
this.setSystemProperties(config);
// Log
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-12 07:36:38 UTC (rev 87173)
+++ projects/bootstrap/trunk/spi/src/main/java/org/jboss/bootstrap/spi/server/AbstractServer.java 2009-04-12 08:00:17 UTC (rev 87174)
@@ -26,6 +26,7 @@
import java.util.concurrent.CopyOnWriteArrayList;
import org.jboss.bootstrap.spi.Bootstrap;
+import org.jboss.bootstrap.spi.config.ConfigurationInitializer;
import org.jboss.bootstrap.spi.config.ConfigurationValidator;
import org.jboss.bootstrap.spi.config.InvalidConfigurationException;
import org.jboss.bootstrap.spi.config.ServerConfig;
@@ -35,7 +36,7 @@
/**
* AbstractServer
*
- * Generic support for implementations of a Server
+ * Generic support for
*
* @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
* @version $Revision: $
@@ -66,15 +67,21 @@
/**
* Validator for the configuration. Synchronized on "this". Requires
- * Thread-safe imple (as it's exported)
+ * Thread-safe impl (as it's exported)
*/
private ConfigurationValidator<T> validator;
/**
+ * Initializer for the configuration. Synchronized on "this". Requires
+ * Thread-safe impl (as it's exported)
+ */
+ private ConfigurationInitializer<T> configInitializer;
+
+ /**
* Server initializer. Synchronized on "this". Requires
- * Thread-safe imple (as it's exported)
+ * Thread-safe impl (as it's exported)
*/
- private ServerInitializer<K, T> initializer;
+ private ServerInitializer<K, T> serverInitializer;
/**
* The list of bootstraps to run upon start, requires Thread-safe impl.
@@ -103,7 +110,7 @@
*
* @param configuration The configuration to set
*/
- protected AbstractServer(final T configuration) throws IllegalArgumentException
+ protected AbstractServer(final T configuration)
{
// Check for valid config and set
this.setConfiguration(configuration);
@@ -119,7 +126,7 @@
/* (non-Javadoc)
* @see org.jboss.bootstrap.spi.server.Server#getConfiguration()
*/
- public synchronized final T getConfiguration()
+ public final T getConfiguration()
{
return this.configuration;
}
@@ -127,7 +134,7 @@
/* (non-Javadoc)
* @see org.jboss.bootstrap.spi.server.Server#setConfiguration(org.jboss.bootstrap.spi.config.ServerConfig)
*/
- public synchronized final void setConfiguration(final T configuration)
+ public void setConfiguration(final T configuration)
{
// Log and set
if (log.isTraceEnabled())
@@ -140,9 +147,9 @@
/* (non-Javadoc)
* @see org.jboss.bootstrap.spi.server.Server#getState()
*/
- public synchronized final LifecycleState getState()
+ public final synchronized LifecycleState getState()
{
- final LifecycleState state = this.state;
+ LifecycleState state = this.state;
if (state == null)
{
throw new IllegalStateException("null state");
@@ -153,7 +160,7 @@
/* (non-Javadoc)
* @see org.jboss.bootstrap.spi.server.Server#shutdown()
*/
- public synchronized void shutdown() throws IllegalStateException, Exception
+ public void shutdown() throws IllegalStateException, Exception
{
// Log
if (log.isTraceEnabled())
@@ -162,8 +169,8 @@
}
// Ensure running
- final LifecycleState required = LifecycleState.STARTED;
- final LifecycleState actual = this.getState();
+ LifecycleState required = LifecycleState.STARTED;
+ LifecycleState actual = this.getState();
this.checkState(required, actual);
// Initiate shutdown sequence
@@ -192,7 +199,7 @@
/* (non-Javadoc)
* @see org.jboss.bootstrap.spi.server.Server#start()
*/
- public synchronized void start() throws IllegalStateException, Exception
+ public void start() throws IllegalStateException, Exception
{
// Log
if (log.isTraceEnabled())
@@ -269,15 +276,15 @@
/* (non-Javadoc)
* @see org.jboss.bootstrap.spi.server.Server#getValidator()
*/
- public synchronized final ConfigurationValidator<T> getValidator()
+ public ConfigurationValidator<T> getValidator()
{
return this.validator;
}
/* (non-Javadoc)
- * @see org.jboss.bootstrap.spi.server.Server#init()
+ * @see org.jboss.bootstrap.spi.server.Server#initialize()
*/
- public void initialize() throws IllegalStateException, InvalidConfigurationException
+ public synchronized void initialize() throws IllegalStateException, InvalidConfigurationException
{
// Log
log.debug("Initializing server: " + this);
@@ -300,16 +307,38 @@
throw new IllegalStateException("Configuration must be supplied before server is initialized");
}
+ // If there's a configuration initializer, use it
+ final ConfigurationInitializer<T> configInitializer = this.getConfigInitializer();
+ if (configInitializer != null)
+ {
+ if (log.isTraceEnabled())
+ {
+ log.trace("Performing configuration initialization...");
+ }
+ configInitializer.initialize(config);
+ }
+ else
+ {
+ if (log.isTraceEnabled())
+ {
+ log.trace("No configuration initializer supplied, skipping");
+ }
+ }
+
// Validate
+ if (log.isTraceEnabled())
+ {
+ log.trace("Validating config...");
+ }
this.validate(config);
/*
* If there's an initializer, use it
*/
- final ServerInitializer<K, T> initializer = this.getInitializer();
- if (initializer != null)
+ final ServerInitializer<K, T> serverInitializer = this.getServerInitializer();
+ if (serverInitializer != null)
{
- initializer.initialize(this);
+ serverInitializer.initialize(this);
}
else
{
@@ -326,22 +355,39 @@
/* (non-Javadoc)
* @see org.jboss.bootstrap.spi.server.Server#getInitializer()
*/
- public synchronized final ServerInitializer<K, T> getInitializer()
+ public synchronized final ServerInitializer<K, T> getServerInitializer()
{
- return this.initializer;
+ return this.serverInitializer;
}
/* (non-Javadoc)
* @see org.jboss.bootstrap.spi.server.Server#setInitializer(org.jboss.bootstrap.spi.server.ServerInitializer)
*/
- public synchronized final void setInitializer(final ServerInitializer<K, T> initializer)
+ public synchronized final void setServerInitializer(final ServerInitializer<K, T> serverInitializer)
throws IllegalStateException
{
- this.initializer = initializer;
- log.debug("Set initializer to " + initializer);
+ this.serverInitializer = serverInitializer;
+ log.debug("Set server initializer to " + serverInitializer);
}
/* (non-Javadoc)
+ * @see org.jboss.bootstrap.spi.server.Server#getConfigInitializer()
+ */
+ public synchronized final ConfigurationInitializer<T> getConfigInitializer()
+ {
+ return this.configInitializer;
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.bootstrap.spi.server.Server#setConfigInitializer(org.jboss.bootstrap.spi.config.ConfigurationInitializer)
+ */
+ public synchronized final void setConfigInitializer(ConfigurationInitializer<T> configInitializer)
+ {
+ this.configInitializer = configInitializer;
+ log.debug("Set config initializer to " + configInitializer);
+ }
+
+ /* (non-Javadoc)
* @see org.jboss.bootstrap.spi.server.Server#setConfigurationValidator(org.jboss.bootstrap.spi.config.ConfigurationValidator)
*/
public synchronized final void setValidator(final ConfigurationValidator<T> validator)
@@ -353,36 +399,10 @@
/* (non-Javadoc)
* @see org.jboss.bootstrap.spi.server.Server#validate()
*/
- public void validate(final T configuration) throws InvalidConfigurationException, IllegalArgumentException
- {
- // Precondition check
- if (configuration == null)
- {
- throw new IllegalArgumentException("Configuration was not specified");
- }
- // Get the validator
- final ConfigurationValidator<T> validator = this.getValidator();
-
- // Is specified, validate
- if (validator != null)
- {
- log.debug("Validating configuration using: " + validator);
- validator.validate(this.getConfiguration());
- }
- else
- {
- if (log.isTraceEnabled())
- {
- log.trace("No validator defined, skipping validation upon configuration");
- }
- }
- }
-
//-------------------------------------------------------------------------------------||
// Contracts --------------------------------------------------------------------------||
//-------------------------------------------------------------------------------------||
-
/**
* Implementation-specific start hook
*
@@ -467,6 +487,41 @@
}
}
+ /**
+ * If {@link Server#getValidator()} is non-null, will
+ * assert the configuration is valid using the supplied
+ * validator
+ *
+ * @param configuration
+ * @throws InvalidConfigurationException If the configuration is invalid
+ * @throws IllegalArgumentException If the confirguation has not been set
+ */
+ private void validate(T configuration) throws InvalidConfigurationException, IllegalArgumentException
+ {
+ // Precondition check
+ if (configuration == null)
+ {
+ throw new IllegalArgumentException("Configuration was not specified");
+ }
+
+ // Get the validator
+ ConfigurationValidator<T> validator = this.getValidator();
+
+ // Is specified, validate
+ if (validator != null)
+ {
+ log.debug("Validating configuration using: " + validator);
+ validator.validate(this.getConfiguration());
+ }
+ else
+ {
+ if (log.isTraceEnabled())
+ {
+ log.trace("No validator defined, skipping validation upon configuration");
+ }
+ }
+ }
+
//-------------------------------------------------------------------------------------||
// Accessors / Mutators ---------------------------------------------------------------||
//-------------------------------------------------------------------------------------||
Modified: projects/bootstrap/trunk/spi/src/main/java/org/jboss/bootstrap/spi/server/Server.java
===================================================================
--- projects/bootstrap/trunk/spi/src/main/java/org/jboss/bootstrap/spi/server/Server.java 2009-04-12 07:36:38 UTC (rev 87173)
+++ projects/bootstrap/trunk/spi/src/main/java/org/jboss/bootstrap/spi/server/Server.java 2009-04-12 08:00:17 UTC (rev 87174)
@@ -23,6 +23,7 @@
package org.jboss.bootstrap.spi.server;
import org.jboss.bootstrap.spi.Bootstrap;
+import org.jboss.bootstrap.spi.config.ConfigurationInitializer;
import org.jboss.bootstrap.spi.config.ConfigurationValidator;
import org.jboss.bootstrap.spi.config.InvalidConfigurationException;
import org.jboss.bootstrap.spi.config.ServerConfig;
@@ -44,7 +45,7 @@
//-------------------------------------------------------------------------------------||
/**
- * Prepares the server for startup. If {@link Server#getInitializer()} is not
+ * Prepares the server for startup. If {@link Server#getServerInitializer()} is not
* null, will invoke {@link ServerInitializer#initialize(Server)}.
* Freezes the configuration from further
* mutable actions by invoking {@link ServerConfig#freeze()}. Finally
@@ -62,19 +63,36 @@
*
* @return
*/
- ServerInitializer<K, T> getInitializer();
+ ServerInitializer<K, T> getServerInitializer();
/**
* Initializer to use in server initialization. Pass
* null to disable further initialization.
*
- * @param initializer
+ * @param serverInitializer
+ * @return This server
* @throws IllegalStateException If the server state is anything aside from
* {@link LifecycleState#PRE_INIT}
*/
- void setInitializer(ServerInitializer<K, T> initializer) throws IllegalStateException;
+ void setServerInitializer(ServerInitializer<K, T> serverInitializer) throws IllegalStateException;
/**
+ * Returns the initializer for the underlying {@link ServerConfig}
+ *
+ * @return
+ */
+ ConfigurationInitializer<T> getConfigInitializer();
+
+ /**
+ * Sets the initializer to be used upon the configuration. Pass
+ * <code>null</code> to remove the initializer.
+ *
+ * @param configInitializer
+ * @return This server
+ */
+ void setConfigInitializer(ConfigurationInitializer<T> configInitializer);
+
+ /**
* Start lifecycle of the Server, optionally invoking upon
* {@link Server#initialize()} if the state is {@link LifecycleState#PRE_INIT}.
* During execution the state will be {@link LifecycleState#STARTING}, and upon
@@ -116,22 +134,11 @@
* Sets the configuration
*
* @param config
+ * @return This server
*/
void setConfiguration(T config);
/**
- * If {@link Server#getValidator()} is non-null, will
- * assert the configuration is valid using the supplied
- * validator
- *
- * @param config
- * @throws InvalidConfigurationException If the config is not valid as
- * determined by the rules of the validator
- * @throws IllegalArgumentException If the configuration was not specified
- */
- void validate(T config) throws InvalidConfigurationException, IllegalArgumentException;
-
- /**
* Returns the (possibly null) validator
* to be used in asserting the validity of a supplied configuration
*
@@ -145,6 +152,7 @@
* May be null to remove validation.
*
* @param validator
+ * @return This server
*/
void setValidator(ConfigurationValidator<T> validator);
Added: projects/bootstrap/trunk/spi/src/test/java/org/jboss/bootstrap/spi/config/TestConfigurationInitializer.java
===================================================================
--- projects/bootstrap/trunk/spi/src/test/java/org/jboss/bootstrap/spi/config/TestConfigurationInitializer.java (rev 0)
+++ projects/bootstrap/trunk/spi/src/test/java/org/jboss/bootstrap/spi/config/TestConfigurationInitializer.java 2009-04-12 08:00:17 UTC (rev 87174)
@@ -0,0 +1,36 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.bootstrap.spi.config;
+
+/**
+ * TestConfigurationInitializer
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+public class TestConfigurationInitializer extends AbstractBasicConfigurationInitializer<TestServerConfig>
+ implements
+ ConfigurationInitializer<TestServerConfig>
+{
+ // Impl in superclass
+}
Modified: projects/bootstrap/trunk/spi/src/test/java/org/jboss/bootstrap/spi/config/unit/ConfigInitializationTestCase.java
===================================================================
--- projects/bootstrap/trunk/spi/src/test/java/org/jboss/bootstrap/spi/config/unit/ConfigInitializationTestCase.java 2009-04-12 07:36:38 UTC (rev 87173)
+++ projects/bootstrap/trunk/spi/src/test/java/org/jboss/bootstrap/spi/config/unit/ConfigInitializationTestCase.java 2009-04-12 08:00:17 UTC (rev 87174)
@@ -26,15 +26,10 @@
import junit.framework.TestCase;
-import org.jboss.bootstrap.spi.config.CountingServerInitializer;
-import org.jboss.bootstrap.spi.config.ServerConfig;
import org.jboss.bootstrap.spi.config.TestConfigFactory;
+import org.jboss.bootstrap.spi.config.TestConfigurationInitializer;
import org.jboss.bootstrap.spi.config.TestServerConfig;
-import org.jboss.bootstrap.spi.config.TestServerInitializer;
-import org.jboss.bootstrap.spi.server.TestNoOpServer;
import org.jboss.logging.Logger;
-import org.junit.After;
-import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
@@ -54,14 +49,12 @@
private static final Logger log = Logger.getLogger(ConfigValidationTestCase.class);
- private static CountingServerInitializer initializer;
+ private static TestConfigurationInitializer configurationInitializer;
//-------------------------------------------------------------------------------------||
// Instance Members -------------------------------------------------------------------||
//-------------------------------------------------------------------------------------||
- private TestNoOpServer server;
-
//-------------------------------------------------------------------------------------||
// Lifecycle --------------------------------------------------------------------------||
//-------------------------------------------------------------------------------------||
@@ -69,24 +62,10 @@
@BeforeClass
public static void createInitializer() throws Throwable
{
- initializer = new TestServerInitializer();
- log.info("Created: " + initializer);
+ configurationInitializer = new TestConfigurationInitializer();
+ log.info("Created: " + configurationInitializer);
}
- @Before
- public void createServer()
- {
- this.server = new TestNoOpServer();
- log.info("Created: " + this.server);
- }
-
- @After
- public void resetServer()
- {
- this.server = null;
- log.info("Cleaned up server to null");
- }
-
//-------------------------------------------------------------------------------------||
// Tests ------------------------------------------------------------------------------||
//-------------------------------------------------------------------------------------||
@@ -104,14 +83,12 @@
// Get a populated config and server
final TestServerConfig configuration = TestConfigFactory.createConfiguration();
- final TestNoOpServer server = this.server;
// Remove conf and set on server
configuration.bootstrapConfLocation(null);
- server.setConfiguration(configuration);
// Initialize
- initializer.initialize(server);
+ configurationInitializer.initialize(configuration);
// Create the expected URL
final URL expectedConfigurationURL = configuration.getBootstrapHome();
@@ -135,14 +112,12 @@
{
// Get a populated config and server
final TestServerConfig configuration = TestConfigFactory.createConfiguration();
- final TestNoOpServer server = this.server;
// Remove conf and home
configuration.bootstrapHome(null).bootstrapConfLocation(null);
- server.setConfiguration(configuration);
// Initialize
- initializer.initialize(server);
+ configurationInitializer.initialize(configuration);
// Create the expected URL
final URL expectedConfigurationURL = TestConfigFactory.getResourcesBase();
@@ -166,14 +141,12 @@
{
// Get a populated config and server
final TestServerConfig configuration = TestConfigFactory.createConfiguration();
- final TestNoOpServer server = this.server;
// Remove bootstrapURL
configuration.bootstrapUrl(null);
- server.setConfiguration(configuration);
// Initialize
- initializer.initialize(server);
+ configurationInitializer.initialize(configuration);
// Create the expected URL
final URL home = configuration.getBootstrapHome();
@@ -187,52 +160,4 @@
TestCase.assertNotNull("Bootstrap URL was not initialized", bootstrapUrl);
TestCase.assertEquals("Initialized bootstrap is to incorrect location", expectedBootstrapURL, bootstrapUrl);
}
-
- /**
- * Ensures that the properties backing the configuration are set
- * both on the configuration itself and in the System props
- *
- * @throws Throwable
- */
- @Test
- public void testPropertiesSetInInitialization() throws Throwable
- {
- // Get a populated config and server
- TestServerConfig configuration = TestConfigFactory.createConfiguration();
- final TestNoOpServer server = this.server;
- server.setConfiguration(configuration);
-
- // Initialize
- initializer.initialize(server);
-
- // Get Properties from Configuration
- final String homeFromConfigProp = configuration.getProperties().get(ServerConfig.PROP_KEY_BOOTSTRAP_HOME_URL);
- final String bootstrapURLFromConfigProp = configuration.getProperties().get(ServerConfig.PROP_KEY_BOOTSTRAP_URL);
- final String confFromConfigProp = configuration.getProperties().get(ServerConfig.PROP_KEY_BOOTSTRAP_CONF_URL);
- final String nameFromConfigProp = configuration.getProperties().get(ServerConfig.PROP_KEY_BOOTSTRAP_NAME);
-
- // Get Properties from System
- final String homeFromSystem = System.getProperty(ServerConfig.PROP_KEY_BOOTSTRAP_HOME_URL);
- final String bootstrapURLFromSystem = System.getProperty(ServerConfig.PROP_KEY_BOOTSTRAP_URL);
- final String confFromSystem = System.getProperty(ServerConfig.PROP_KEY_BOOTSTRAP_CONF_URL);
- final String nameFromSystem = System.getProperty(ServerConfig.PROP_KEY_BOOTSTRAP_NAME);
-
- // Get Expected Values
- final String home = configuration.getBootstrapHome().toExternalForm();
- final String bootstrapURL = configuration.getBootstrapUrl().toExternalForm();
- final String conf = configuration.getBootstrapConfLocation().toExternalForm();
- final String name = configuration.getBootstrapName();
-
- // Ensure all equal
- TestCase.assertEquals("home in configuration must match the config property", home, homeFromConfigProp);
- TestCase.assertEquals("home in configuration must match the system property", home, homeFromSystem);
- TestCase.assertEquals("bootstrapURL in configuration must match the config property", bootstrapURL,
- bootstrapURLFromConfigProp);
- TestCase.assertEquals("bootstrapURL in configuration must match the system property", bootstrapURL,
- bootstrapURLFromSystem);
- TestCase.assertEquals("conf in configuration must match the config property", conf, confFromConfigProp);
- TestCase.assertEquals("conf in configuration must match the system property", conf, confFromSystem);
- TestCase.assertEquals("name in configuration must match the config property", name, nameFromConfigProp);
- TestCase.assertEquals("name in configuration must match the system property", name, nameFromSystem);
- }
}
Added: projects/bootstrap/trunk/spi/src/test/java/org/jboss/bootstrap/spi/server/unit/ServerInitializationTestCase.java
===================================================================
--- projects/bootstrap/trunk/spi/src/test/java/org/jboss/bootstrap/spi/server/unit/ServerInitializationTestCase.java (rev 0)
+++ projects/bootstrap/trunk/spi/src/test/java/org/jboss/bootstrap/spi/server/unit/ServerInitializationTestCase.java 2009-04-12 08:00:17 UTC (rev 87174)
@@ -0,0 +1,140 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.bootstrap.spi.server.unit;
+
+import junit.framework.TestCase;
+
+import org.jboss.bootstrap.spi.config.CountingServerInitializer;
+import org.jboss.bootstrap.spi.config.ServerConfig;
+import org.jboss.bootstrap.spi.config.TestConfigFactory;
+import org.jboss.bootstrap.spi.config.TestServerConfig;
+import org.jboss.bootstrap.spi.config.TestServerInitializer;
+import org.jboss.bootstrap.spi.config.unit.ConfigValidationTestCase;
+import org.jboss.bootstrap.spi.server.TestNoOpServer;
+import org.jboss.logging.Logger;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+/**
+ * ConfigInitializationTestCase
+ *
+ * Ensures that the base server initialization is correct
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+public class ServerInitializationTestCase
+{
+ //-------------------------------------------------------------------------------------||
+ // Class Members ----------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ private static final Logger log = Logger.getLogger(ConfigValidationTestCase.class);
+
+ private static CountingServerInitializer serverInitializer;
+
+ //-------------------------------------------------------------------------------------||
+ // Instance Members -------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ private TestNoOpServer server;
+
+ //-------------------------------------------------------------------------------------||
+ // Lifecycle --------------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ @BeforeClass
+ public static void createInitializer() throws Throwable
+ {
+ serverInitializer = new TestServerInitializer();
+ log.info("Created: " + serverInitializer);
+ }
+
+ @Before
+ public void createServer()
+ {
+ this.server = new TestNoOpServer();
+ log.info("Created: " + this.server);
+ }
+
+ @After
+ public void resetServer()
+ {
+ this.server = null;
+ log.info("Cleaned up server to null");
+ }
+
+ //-------------------------------------------------------------------------------------||
+ // Tests ------------------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Ensures that the properties backing the configuration are set
+ * both on the configuration itself and in the System props
+ *
+ * @throws Throwable
+ */
+ @Test
+ public void testPropertiesSetInInitialization() throws Throwable
+ {
+ // Get a populated config and server
+ TestServerConfig configuration = TestConfigFactory.createConfiguration();
+ final TestNoOpServer server = this.server;
+ server.setConfiguration(configuration);
+
+ // Initialize
+ serverInitializer.initialize(server);
+
+ // Get Properties from Configuration
+ final String homeFromConfigProp = configuration.getProperties().get(ServerConfig.PROP_KEY_BOOTSTRAP_HOME_URL);
+ final String bootstrapURLFromConfigProp = configuration.getProperties().get(ServerConfig.PROP_KEY_BOOTSTRAP_URL);
+ final String confFromConfigProp = configuration.getProperties().get(ServerConfig.PROP_KEY_BOOTSTRAP_CONF_URL);
+ final String nameFromConfigProp = configuration.getProperties().get(ServerConfig.PROP_KEY_BOOTSTRAP_NAME);
+
+ // Get Properties from System
+ final String homeFromSystem = System.getProperty(ServerConfig.PROP_KEY_BOOTSTRAP_HOME_URL);
+ final String bootstrapURLFromSystem = System.getProperty(ServerConfig.PROP_KEY_BOOTSTRAP_URL);
+ final String confFromSystem = System.getProperty(ServerConfig.PROP_KEY_BOOTSTRAP_CONF_URL);
+ final String nameFromSystem = System.getProperty(ServerConfig.PROP_KEY_BOOTSTRAP_NAME);
+
+ // Get Expected Values
+ final String home = configuration.getBootstrapHome().toExternalForm();
+ final String bootstrapURL = configuration.getBootstrapUrl().toExternalForm();
+ final String conf = configuration.getBootstrapConfLocation().toExternalForm();
+ final String name = configuration.getBootstrapName();
+
+ // Ensure all equal
+ TestCase.assertEquals("home in configuration must match the config property", home, homeFromConfigProp);
+ TestCase.assertEquals("home in configuration must match the system property", home, homeFromSystem);
+ TestCase.assertEquals("bootstrapURL in configuration must match the config property", bootstrapURL,
+ bootstrapURLFromConfigProp);
+ TestCase.assertEquals("bootstrapURL in configuration must match the system property", bootstrapURL,
+ bootstrapURLFromSystem);
+ TestCase.assertEquals("conf in configuration must match the config property", conf, confFromConfigProp);
+ TestCase.assertEquals("conf in configuration must match the system property", conf, confFromSystem);
+ TestCase.assertEquals("name in configuration must match the config property", name, nameFromConfigProp);
+ TestCase.assertEquals("name in configuration must match the system property", name, nameFromSystem);
+ }
+}
Modified: projects/bootstrap/trunk/spi/src/test/java/org/jboss/bootstrap/spi/server/unit/ServerLifecycleTestCase.java
===================================================================
--- projects/bootstrap/trunk/spi/src/test/java/org/jboss/bootstrap/spi/server/unit/ServerLifecycleTestCase.java 2009-04-12 07:36:38 UTC (rev 87173)
+++ projects/bootstrap/trunk/spi/src/test/java/org/jboss/bootstrap/spi/server/unit/ServerLifecycleTestCase.java 2009-04-12 08:00:17 UTC (rev 87174)
@@ -27,6 +27,7 @@
import org.jboss.bootstrap.spi.config.CountingConfigurationValidator;
import org.jboss.bootstrap.spi.config.CountingServerInitializer;
import org.jboss.bootstrap.spi.config.TestConfigFactory;
+import org.jboss.bootstrap.spi.config.TestConfigurationInitializer;
import org.jboss.bootstrap.spi.config.TestConfigurationValidator;
import org.jboss.bootstrap.spi.config.TestServerConfig;
import org.jboss.bootstrap.spi.config.TestServerInitializer;
@@ -55,10 +56,12 @@
private static final Logger log = Logger.getLogger(ConfigValidationTestCase.class);
- private static CountingServerInitializer initializer;
+ private static CountingServerInitializer serverInitializer;
private static CountingConfigurationValidator<TestServerConfig> validator;
+ private static TestConfigurationInitializer configInitializer;
+
//-------------------------------------------------------------------------------------||
// Instance Members -------------------------------------------------------------------||
//-------------------------------------------------------------------------------------||
@@ -72,8 +75,9 @@
@BeforeClass
public static void createInitializerAndValidator()
{
- initializer = new TestServerInitializer();
+ serverInitializer = new TestServerInitializer();
validator = new TestConfigurationValidator();
+ configInitializer = new TestConfigurationInitializer();
}
/**
@@ -83,8 +87,9 @@
public void createServer()
{
TestNoOpServer server = new TestNoOpServer();
- server.setInitializer(initializer);
+ server.setServerInitializer(serverInitializer);
server.setValidator(validator);
+ server.setConfigInitializer(configInitializer);
TestServerConfig config = TestConfigFactory.createConfiguration();
server.setConfiguration(config);
this.server = server;
@@ -112,14 +117,14 @@
log.info("testInitializationRunOnStart");
// Initialize
- final int countBefore = initializer.getUsedCount();
+ final int countBefore = serverInitializer.getUsedCount();
// Get the server and start
final TestNoOpServer server = this.server;
server.start();
// Get the new count
- final int countAfter = initializer.getUsedCount();
+ final int countAfter = serverInitializer.getUsedCount();
// Ensure incremented by 1
TestCase.assertTrue("Initialization was not run on server start", countAfter == countBefore + 1);
More information about the jboss-cvs-commits
mailing list