[jboss-cvs] JBossAS SVN: r88173 - in projects/bootstrap/trunk: impl-base/src/main/java/org/jboss/bootstrap/impl/base/server and 6 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Mon May 4 18:27:53 EDT 2009
Author: ALRubinger
Date: 2009-05-04 18:27:53 -0400 (Mon, 04 May 2009)
New Revision: 88173
Added:
projects/bootstrap/trunk/spi-as/src/main/java/org/jboss/bootstrap/spi/as/JBossASBootstrap.java
Modified:
projects/bootstrap/trunk/impl-as/src/main/java/org/jboss/bootstrap/impl/as/server/JBossASServerImpl.java
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/TestNoOpServer.java
projects/bootstrap/trunk/impl-mc/src/main/java/org/jboss/bootstrap/impl/mc/server/AbstractMCServerBase.java
projects/bootstrap/trunk/impl-mc/src/main/java/org/jboss/bootstrap/impl/mc/server/MCServerImpl.java
projects/bootstrap/trunk/spi-mc/pom.xml
projects/bootstrap/trunk/spi/src/main/java/org/jboss/bootstrap/spi/Bootstrap.java
projects/bootstrap/trunk/spi/src/main/java/org/jboss/bootstrap/spi/server/Server.java
Log:
[JBBOOT-63] Fixed Generics for org.jboss.bootstrap.spi.Bootstrap and related classes
Modified: projects/bootstrap/trunk/impl-as/src/main/java/org/jboss/bootstrap/impl/as/server/JBossASServerImpl.java
===================================================================
--- projects/bootstrap/trunk/impl-as/src/main/java/org/jboss/bootstrap/impl/as/server/JBossASServerImpl.java 2009-05-04 21:57:03 UTC (rev 88172)
+++ projects/bootstrap/trunk/impl-as/src/main/java/org/jboss/bootstrap/impl/as/server/JBossASServerImpl.java 2009-05-04 22:27:53 UTC (rev 88173)
@@ -131,7 +131,7 @@
public JBossASServerImpl(final JBossASServerConfig config) throws IllegalArgumentException
{
// Invoke super
- super(config);
+ super(JBossASServer.class, config);
// Set properties
this.setServerInitializer(SERVER_INITIALIZER);
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-05-04 21:57:03 UTC (rev 88172)
+++ projects/bootstrap/trunk/impl-base/src/main/java/org/jboss/bootstrap/impl/base/server/AbstractServer.java 2009-05-04 22:27:53 UTC (rev 88173)
@@ -70,6 +70,11 @@
//-------------------------------------------------------------------------------------||
/**
+ * Actual class used in casting to type K
+ */
+ private Class<K> actualClass;
+
+ /**
* Current state of the server. Synchronized on "this".
* Volatile so we can return the current state without blocking.
*/
@@ -104,12 +109,12 @@
/**
* The list of bootstraps to run upon start, requires Thread-safe impl.
*/
- private final List<Bootstrap> bootstraps = new CopyOnWriteArrayList<Bootstrap>();
+ private final List<Bootstrap<K, T>> bootstraps = new CopyOnWriteArrayList<Bootstrap<K, T>>();
/**
* The bootstraps that have been started, requires Thread-safe impl.
*/
- private final List<Bootstrap> startedBootstraps = new CopyOnWriteArrayList<Bootstrap>();
+ private final List<Bootstrap<K, T>> startedBootstraps = new CopyOnWriteArrayList<Bootstrap<K, T>>();
/**
* Event handlers for each lifecycle state change
@@ -126,11 +131,12 @@
* Creates a new Server using an uninitialized, default configuration
* (which is an instance of the Class specified by
* {@link AbstractServer#getDefaultServerConfigClass()}
+ * @throws IllegalArgumentException If the actual class was not supplied
*/
- protected AbstractServer()
+ protected AbstractServer(final Class<K> actualClass) throws IllegalArgumentException
{
// Pass it to the other ctor
- this(null);
+ this(actualClass, null);
}
/**
@@ -141,10 +147,16 @@
* @param configuration The configuration to set. If null a new default
* configuration will be made (which is an instance of the Class specified by
* {@link AbstractServer#getDefaultServerConfigClass()}
- * @throws IllegalArgumentException If the configuration has not been supplied
+ * @throws IllegalArgumentException If the configuration or actual class has not been supplied
*/
- protected AbstractServer(final T configuration) throws IllegalArgumentException
+ protected AbstractServer(final Class<K> actualClass, final T configuration) throws IllegalArgumentException
{
+ // Precondition check
+ if (actualClass == null)
+ {
+ throw new IllegalArgumentException("Actual class must be specified");
+ }
+
// Initialize
T configToSet = configuration;
@@ -176,6 +188,7 @@
}
// Set properties
+ this.setActualClass(actualClass);
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
@@ -332,7 +345,7 @@
/* (non-Javadoc)
* @see org.jboss.bootstrap.spi.server.Server#addBootstrap(org.jboss.bootstrap.spi.Bootstrap)
*/
- public void addBootstrap(final Bootstrap bootstrap) throws IllegalStateException, IllegalArgumentException
+ public void addBootstrap(final Bootstrap<K, T> bootstrap) throws IllegalStateException, IllegalArgumentException
{
// Precondition check
if (bootstrap == null)
@@ -347,7 +360,7 @@
/* (non-Javadoc)
* @see org.jboss.bootstrap.spi.server.Server#removeBootstrap(org.jboss.bootstrap.spi.Bootstrap)
*/
- public void removeBootstrap(final Bootstrap bootstrap) throws IllegalStateException, IllegalArgumentException
+ public void removeBootstrap(final Bootstrap<K, T> bootstrap) throws IllegalStateException, IllegalArgumentException
{
// Remove
boolean removed = bootstraps.remove(bootstrap);
@@ -661,14 +674,17 @@
*/
protected void startBootstraps() throws Exception
{
+ // Get the proper type for this server
+ final K typedServer = this.covarientReturn();
+
// Run the bootstraps
- for (Bootstrap bootstrap : this.getBootstraps())
+ for (Bootstrap<K, T> bootstrap : this.getBootstraps())
{
// Add in reverse order
this.getStartedBootstraps().add(0, bootstrap);
// Start
- bootstrap.start(this);
+ bootstrap.start(typedServer);
}
}
@@ -678,20 +694,23 @@
protected void shutdownBootstraps()
{
// Initialize
- final List<Bootstrap> startedBootstraps = this.getStartedBootstraps();
+ final List<Bootstrap<K, T>> startedBootstraps = this.getStartedBootstraps();
+ // Get the proper type for this server
+ final K typedServer = this.covarientReturn();
+
// Signal
- for (final Bootstrap bootstrap : startedBootstraps)
+ for (final Bootstrap<K, T> bootstrap : startedBootstraps)
{
- bootstrap.prepareShutdown(this);
+ bootstrap.prepareShutdown(typedServer);
}
- // Do the bootstraps in reverse order
- for (final Bootstrap bootstrap : startedBootstraps)
+ // Do the bootstraps in reverse order (they were added in reverse order)
+ for (final Bootstrap<K, T> bootstrap : startedBootstraps)
{
try
{
- bootstrap.shutdown(this);
+ bootstrap.shutdown(typedServer);
}
catch (Throwable t)
{
@@ -705,6 +724,27 @@
//-------------------------------------------------------------------------------------||
/**
+ * Returns this instance as a typed server (as specified by K),
+ * throwing a descriptive error message in case the server is not assignable
+ */
+ protected final K covarientReturn()
+ {
+ // Get the actual class
+ final Class<K> actualClass = this.getActualClass();
+
+ // Cast
+ try
+ {
+ return actualClass.cast(this);
+ }
+ catch (ClassCastException cce)
+ {
+ throw new RuntimeException("Actual class is incorrect and " + actualClass
+ + " was not assignable to this instance: " + this, cce);
+ }
+ }
+
+ /**
* Obtains a list of handlers for a lifecycle event change into the specified state.
* No nulls will be returned, but rather an empty List in the case no events are
* registered. All requests to the event handlers should be proxied through here
@@ -800,7 +840,7 @@
/**
* @return the bootstraps
*/
- private List<Bootstrap> getBootstraps()
+ private List<Bootstrap<K, T>> getBootstraps()
{
return bootstraps;
}
@@ -808,12 +848,28 @@
/**
* @return the startedBootstraps
*/
- private List<Bootstrap> getStartedBootstraps()
+ private List<Bootstrap<K, T>> getStartedBootstraps()
{
return startedBootstraps;
}
/**
+ * @return the actualClass
+ */
+ protected final Class<K> getActualClass()
+ {
+ return actualClass;
+ }
+
+ /**
+ * @param actualClass the actualClass to set
+ */
+ private void setActualClass(final Class<K> actualClass)
+ {
+ this.actualClass = actualClass;
+ }
+
+ /**
* Sets the state of the server, firing the appropriate lifecycle
* events to the registered handlers
*
Modified: projects/bootstrap/trunk/impl-base/src/test/java/org/jboss/bootstrap/impl/base/server/TestNoOpServer.java
===================================================================
--- projects/bootstrap/trunk/impl-base/src/test/java/org/jboss/bootstrap/impl/base/server/TestNoOpServer.java 2009-05-04 21:57:03 UTC (rev 88172)
+++ projects/bootstrap/trunk/impl-base/src/test/java/org/jboss/bootstrap/impl/base/server/TestNoOpServer.java 2009-05-04 22:27:53 UTC (rev 88173)
@@ -47,6 +47,18 @@
private static final Logger log = Logger.getLogger(TestNoOpServer.class);
//-------------------------------------------------------------------------------------||
+ // Constructor ------------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Constructor
+ */
+ public TestNoOpServer()
+ {
+ super(TestNoOpServer.class);
+ }
+
+ //-------------------------------------------------------------------------------------||
// Required Implementations -----------------------------------------------------------||
//-------------------------------------------------------------------------------------||
Modified: projects/bootstrap/trunk/impl-mc/src/main/java/org/jboss/bootstrap/impl/mc/server/AbstractMCServerBase.java
===================================================================
--- projects/bootstrap/trunk/impl-mc/src/main/java/org/jboss/bootstrap/impl/mc/server/AbstractMCServerBase.java 2009-05-04 21:57:03 UTC (rev 88172)
+++ projects/bootstrap/trunk/impl-mc/src/main/java/org/jboss/bootstrap/impl/mc/server/AbstractMCServerBase.java 2009-05-04 22:27:53 UTC (rev 88173)
@@ -93,9 +93,9 @@
*
* Creates the server with no default configuration
*/
- protected AbstractMCServerBase()
+ protected AbstractMCServerBase(final Class<K> actualClass)
{
- this(null);
+ this(actualClass, null);
}
/**
@@ -105,10 +105,10 @@
*
* @param config
*/
- protected AbstractMCServerBase(final T config)
+ protected AbstractMCServerBase(final Class<K> actualClass, final T config)
{
// Invoke super
- super(config);
+ super(actualClass, config);
// Create Bootstrap and set both it and the kernel
final BasicBootstrap bootstrap = new BasicBootstrap();
Modified: projects/bootstrap/trunk/impl-mc/src/main/java/org/jboss/bootstrap/impl/mc/server/MCServerImpl.java
===================================================================
--- projects/bootstrap/trunk/impl-mc/src/main/java/org/jboss/bootstrap/impl/mc/server/MCServerImpl.java 2009-05-04 21:57:03 UTC (rev 88172)
+++ projects/bootstrap/trunk/impl-mc/src/main/java/org/jboss/bootstrap/impl/mc/server/MCServerImpl.java 2009-05-04 22:27:53 UTC (rev 88173)
@@ -98,7 +98,7 @@
*/
public MCServerImpl(final MCServerConfig config, boolean defaultInit)
{
- super(config);
+ super(MCServer.class, config);
if (defaultInit)
{
Modified: projects/bootstrap/trunk/spi/src/main/java/org/jboss/bootstrap/spi/Bootstrap.java
===================================================================
--- projects/bootstrap/trunk/spi/src/main/java/org/jboss/bootstrap/spi/Bootstrap.java 2009-05-04 21:57:03 UTC (rev 88172)
+++ projects/bootstrap/trunk/spi/src/main/java/org/jboss/bootstrap/spi/Bootstrap.java 2009-05-04 22:27:53 UTC (rev 88173)
@@ -30,7 +30,7 @@
* @author <a href="adrian at jboss.com">Adrian Brock</a>
* @version $Revision: 1.1 $
*/
-public interface Bootstrap
+public interface Bootstrap<K extends Server<K, T>, T extends ServerConfig<T>>
{
/**
* Invoked at startup
@@ -38,19 +38,19 @@
* @param server the server instance
* @throws Exception for any error
*/
- <K extends Server<K, T>, T extends ServerConfig<T>> void start(Server<K, T> server) throws Exception;
+ void start(K server) throws Exception;
/**
* Invoked to say we are preparing shutdown
*
* @param server the server
*/
- <K extends Server<K, T>, T extends ServerConfig<T>> void prepareShutdown(Server<K, T> server);
+ void prepareShutdown(K server);
/**
* Invoked at shutdown
*
* @param server the server instance
*/
- <K extends Server<K, T>, T extends ServerConfig<T>> void shutdown(Server<K, T> server);
+ void shutdown(K server);
}
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-05-04 21:57:03 UTC (rev 88172)
+++ projects/bootstrap/trunk/spi/src/main/java/org/jboss/bootstrap/spi/server/Server.java 2009-05-04 22:27:53 UTC (rev 88173)
@@ -238,7 +238,7 @@
* @param bootstrap
* @throws IllegalArgumentException If the specified bootstrap is null
*/
- void addBootstrap(Bootstrap bootstrap) throws IllegalArgumentException;
+ void addBootstrap(Bootstrap<K, T> bootstrap) throws IllegalArgumentException;
/**
* Removes the specified bootstrap from those to be run on {@link Server#start()}
@@ -247,5 +247,5 @@
* @throws IllegalArgumentException If the specified bootstrap is not currently
* designated as to be run
*/
- void removeBootstrap(Bootstrap bootstrap) throws IllegalArgumentException;
+ void removeBootstrap(Bootstrap<K, T> bootstrap) throws IllegalArgumentException;
}
Added: projects/bootstrap/trunk/spi-as/src/main/java/org/jboss/bootstrap/spi/as/JBossASBootstrap.java
===================================================================
--- projects/bootstrap/trunk/spi-as/src/main/java/org/jboss/bootstrap/spi/as/JBossASBootstrap.java (rev 0)
+++ projects/bootstrap/trunk/spi-as/src/main/java/org/jboss/bootstrap/spi/as/JBossASBootstrap.java 2009-05-04 22:27:53 UTC (rev 88173)
@@ -0,0 +1,40 @@
+/*
+ * 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.as;
+
+import org.jboss.bootstrap.spi.Bootstrap;
+import org.jboss.bootstrap.spi.as.config.JBossASServerConfig;
+import org.jboss.bootstrap.spi.as.server.JBossASServer;
+
+/**
+ * JBossASBootstrap
+ *
+ * Represents a JBoss AS Bootstrap
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+public interface JBossASBootstrap extends Bootstrap<JBossASServer, JBossASServerConfig>
+{
+ // Contracts in superinterface, here we define type safety
+}
Modified: projects/bootstrap/trunk/spi-mc/pom.xml
===================================================================
--- projects/bootstrap/trunk/spi-mc/pom.xml 2009-05-04 21:57:03 UTC (rev 88172)
+++ projects/bootstrap/trunk/spi-mc/pom.xml 2009-05-04 22:27:53 UTC (rev 88173)
@@ -25,7 +25,7 @@
<!-- Properties -->
<properties>
- <version.org.jboss.bootstrap_jboss.bootstrap.spi>0.1.1</version.org.jboss.bootstrap_jboss.bootstrap.spi>
+ <version.org.jboss.bootstrap_jboss.bootstrap.spi>0.1.2-SNAPSHOT</version.org.jboss.bootstrap_jboss.bootstrap.spi>
</properties>
More information about the jboss-cvs-commits
mailing list