[jboss-cvs] JBossAS SVN: r89304 - in projects/bootstrap/trunk: impl-as/src/test/java/org/jboss/bootstrap/impl/as/server and 2 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Sat May 23 11:53:10 EDT 2009
Author: ALRubinger
Date: 2009-05-23 11:53:10 -0400 (Sat, 23 May 2009)
New Revision: 89304
Modified:
projects/bootstrap/trunk/impl-as/src/main/java/org/jboss/bootstrap/impl/as/server/JBossASServerImpl.java
projects/bootstrap/trunk/impl-as/src/test/java/org/jboss/bootstrap/impl/as/server/KernelEventsTestCase.java
projects/bootstrap/trunk/impl-mc/src/main/java/org/jboss/bootstrap/impl/mc/server/AbstractMCServerBase.java
projects/bootstrap/trunk/impl-mc/src/test/java/org/jboss/bootstrap/impl/mc/server/unit/MCServerUnitTestCase.java
Log:
[JBBOOT-74] Support MC Server restart
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-23 10:49:11 UTC (rev 89303)
+++ projects/bootstrap/trunk/impl-as/src/main/java/org/jboss/bootstrap/impl/as/server/JBossASServerImpl.java 2009-05-23 15:53:10 UTC (rev 89304)
@@ -37,6 +37,8 @@
import org.jboss.bootstrap.spi.as.config.JBossASServerConfig;
import org.jboss.bootstrap.spi.as.server.JBossASServer;
import org.jboss.bootstrap.spi.config.ConfigurationValidator;
+import org.jboss.bootstrap.spi.config.InvalidConfigurationException;
+import org.jboss.bootstrap.spi.lifecycle.LifecycleEventException;
import org.jboss.bootstrap.spi.lifecycle.LifecycleEventHandler;
import org.jboss.bootstrap.spi.lifecycle.LifecycleState;
import org.jboss.kernel.plugins.bootstrap.basic.BasicBootstrap;
@@ -144,19 +146,6 @@
this.setServerInitializer(SERVER_INITIALIZER);
this.setConfigInitializer(CONFIG_INITIALIZER);
this.setValidator(VALIDATOR);
-
- // Create and Register handlers
- final BasicBootstrap bootstrap = this.getBootstrap();
- final LifecycleEventHandler startHandler = new KernelStartEventLifecycleEventHandler(bootstrap);
- final LifecycleEventHandler stopHandler = new KernelStopEventLifecycleEventHandler(bootstrap);
- this.registerEventHandler(startHandler, LifecycleState.STARTED);
- this.registerEventHandler(stopHandler, LifecycleState.STOPPED);
-
- // JBBOOT-68
- //TODO Remove once VFS is init'd from something else
- @SuppressWarnings("deprecation")
- final LifecycleEventHandler initVfsHandler = new VfsInitializingLifecycleEventHandler();
- this.registerEventHandler(initVfsHandler, LifecycleState.STARTING);
}
//-------------------------------------------------------------------------------||
@@ -277,6 +266,31 @@
return state.equals(LifecycleState.STARTED);
}
+ /* (non-Javadoc)
+ * @see org.jboss.bootstrap.impl.mc.server.AbstractMCServerBase#initialize()
+ */
+ @Override
+ public synchronized void initialize() throws IllegalStateException, InvalidConfigurationException,
+ LifecycleEventException
+ {
+ // Call Super
+ super.initialize();
+
+ // JBBOOT-68
+ //TODO Remove once VFS is init'd from something else
+ // Register an event handler to init VFS alongside server start
+ @SuppressWarnings("deprecation")
+ final LifecycleEventHandler initVfsHandler = new VfsInitializingLifecycleEventHandler();
+ this.registerEventHandler(initVfsHandler, LifecycleState.STARTING);
+
+ // Create and Register handlers
+ final BasicBootstrap bootstrap = this.getBootstrap();
+ final LifecycleEventHandler startHandler = new KernelStartEventLifecycleEventHandler(bootstrap);
+ final LifecycleEventHandler stopHandler = new KernelStopEventLifecycleEventHandler(bootstrap);
+ this.registerEventHandler(startHandler, LifecycleState.STARTED);
+ this.registerEventHandler(stopHandler, LifecycleState.STOPPED);
+ }
+
//-------------------------------------------------------------------------------||
// Overridden Implementations ---------------------------------------------------||
//-------------------------------------------------------------------------------||
Modified: projects/bootstrap/trunk/impl-as/src/test/java/org/jboss/bootstrap/impl/as/server/KernelEventsTestCase.java
===================================================================
--- projects/bootstrap/trunk/impl-as/src/test/java/org/jboss/bootstrap/impl/as/server/KernelEventsTestCase.java 2009-05-23 10:49:11 UTC (rev 89303)
+++ projects/bootstrap/trunk/impl-as/src/test/java/org/jboss/bootstrap/impl/as/server/KernelEventsTestCase.java 2009-05-23 15:53:10 UTC (rev 89304)
@@ -88,14 +88,6 @@
// Initialize
server.initialize();
-
- // Get the Kernel
- final Kernel kernel = server.getKernel();
-
- // Register event listeners
- final KernelEventManager eventManager = kernel.getEventManager();
- final KernelEventListener eventListener = new TestKernelEventListener();
- eventManager.registerListener(eventListener, null, null);
}
@After
@@ -119,11 +111,17 @@
public void testKernelEvents() throws Throwable
{
// Log
- log.info("testJmxNotifications");
+ log.info("testKernelEvents");
// Get the server
final JBossASServer server = this.server;
+ // Test integrity
+ this.ensureIntegrity();
+
+ // Register event listeners
+ this.registerEventListeners();
+
// Start the server
server.start();
@@ -135,10 +133,77 @@
// Test
TestCase.assertTrue("Did not receive stop notification", this.gotStopEvent);
+ }
+ /**
+ * Ensures that the Kernel Events for start and stop
+ * were fired when the server has been started/shutdown/restarted/stopped
+ */
+ @Test
+ public void testKernelEventsOnServerRestart() throws Throwable
+ {
+ // Log
+ log.info("testKernelEventsOnServerRestart");
+
+ // Get the server
+ final JBossASServer server = this.server;
+
+ // Test integrity
+ this.ensureIntegrity();
+
+ // Start and shutdown the server
+ server.start();
+ server.shutdown();
+
+ // Test integrity again
+ this.ensureIntegrity();
+
+ // Register event listeners
+ this.registerEventListeners();
+
+ // Start the server
+ server.start();
+
+ // Test
+ TestCase.assertTrue("Did not receive start notification", this.gotStartEvent);
+
+ // Stop the server
+ server.shutdown();
+
+ // Test
+ TestCase.assertTrue("Did not receive stop notification", this.gotStopEvent);
}
//-------------------------------------------------------------------------------------||
+ // Internal Helper Methods ------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Ensures that the set setup is intact
+ */
+ private void ensureIntegrity()
+ {
+ TestCase.assertFalse("Should not yet have recieved start notification", this.gotStartEvent);
+ TestCase.assertFalse("Should not yet have recieved stop notification", this.gotStopEvent);
+ }
+
+ /**
+ * Registers the event listeners for the test
+ *
+ * @throws Throwable
+ */
+ private void registerEventListeners() throws Throwable
+ {
+ // Get the Kernel
+ final Kernel kernel = server.getKernel();
+
+ // Register event listeners
+ final KernelEventManager eventManager = kernel.getEventManager();
+ final KernelEventListener eventListener = new TestKernelEventListener();
+ eventManager.registerListener(eventListener, null, null);
+ }
+
+ //-------------------------------------------------------------------------------------||
// Inner Classes ----------------------------------------------------------------------||
//-------------------------------------------------------------------------------------||
@@ -155,7 +220,7 @@
/* (non-Javadoc)
* @see org.jboss.kernel.spi.event.KernelEventListener#onEvent(org.jboss.kernel.spi.event.KernelEvent, java.lang.Object)
*/
- public void onEvent(KernelEvent event, Object handback)
+ public void onEvent(final KernelEvent event, final Object handback)
{
// Log
log.info("Got event: " + event);
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-23 10:49:11 UTC (rev 89303)
+++ projects/bootstrap/trunk/impl-mc/src/main/java/org/jboss/bootstrap/impl/mc/server/AbstractMCServerBase.java 2009-05-23 15:53:10 UTC (rev 89304)
@@ -75,11 +75,6 @@
private BasicBootstrap bootstrap;
/**
- * The MC Kernel
- */
- private Kernel kernel;
-
- /**
* The XML Deployer
*/
private TempBasicXMLDeployer kernelDeployer;
@@ -109,10 +104,6 @@
{
// Invoke super
super(actualClass, config);
-
- // Create Bootstrap and set both it and the kernel
- final BasicBootstrap bootstrap = new BasicBootstrap();
- this.bootstrap = bootstrap;
}
//-------------------------------------------------------------------------------------||
@@ -140,7 +131,7 @@
@ManagementProperty(ignored = true)
public Kernel getKernel()
{
- return this.kernel;
+ return this.getBootstrap().getKernel();
}
/*
@@ -179,27 +170,27 @@
// Shutdown the controller
try
{
- Kernel currentKernel = null;
- if (kernel != null)
+ // Get a reference to the underlying kernel
+ Kernel tempKernelReference = null;
+ if (bootstrap != null)
{
- currentKernel = kernel;
- kernel = null;
+ tempKernelReference = bootstrap.getKernel();
}
- else if (bootstrap != null)
- {
- currentKernel = bootstrap.getKernel();
- }
+
+ // Null out the Bootstrap
bootstrap = null;
- if (currentKernel != null)
+ // If we had a kernel
+ if (tempKernelReference != null)
{
- KernelController controller = currentKernel.getController();
+ // Shut it down
+ KernelController controller = tempKernelReference.getController();
controller.shutdown();
}
}
- catch (Throwable t)
+ catch (final Exception e)
{
- log.warn("Error stopping xml deployer", t);
+ log.warn("Error stopping " + KernelController.class.getName(), e);
}
}
@@ -211,18 +202,40 @@
public synchronized void initialize() throws IllegalStateException, InvalidConfigurationException,
LifecycleEventException
{
+ /*
+ * We need to start the bootstrap here so we can set the kernel
+ * before we fire start kernel events
+ */
+ this.initializeBootstrap();
+
// Call Super implementation
super.initialize();
+ }
+ /* (non-Javadoc)
+ * @see org.jboss.bootstrap.impl.base.server.AbstractServer#start()
+ */
+ @Override
+ public synchronized void start() throws IllegalStateException, Exception
+ {
/*
- * We need to start the bootstrap here so we can set the kernel
- * before we fire start kernel events
+ * In the case that we're re-started, we need to reconstruct
+ * and set a new bootstrap/kernel, because initialize will
+ * is only called once.
*/
+ final BasicBootstrap bootstrap = this.getBootstrap();
+ if (bootstrap == null)
+ {
+ if (log.isTraceEnabled())
+ {
+ log.trace("Re-initializing the underlying bootstrap...");
+ }
+ this.initializeBootstrap();
+ log.debug("Underlying MC Bootstrap re-initialized.");
+ }
- // Run Bootstrap and set the Kernel
- final BasicBootstrap bootstrap = this.getBootstrap();
- bootstrap.run();
- this.kernel = bootstrap.getKernel();
+ // Call Super implementation
+ super.start();
}
/* (non-Javadoc)
@@ -233,6 +246,12 @@
{
// Register the server implementation
final String mcServerBindName = "JBossServer";
+ final Kernel kernel = this.getKernel();
+ if (kernel == null)
+ {
+ throw new IllegalStateException("Server cannot be started without the presence of an underlying "
+ + Kernel.class.getName());
+ }
final KernelController controller = kernel.getController();
final BeanMetaDataBuilder builder = BeanMetaDataBuilder.createBuilder(mcServerBindName, getClass().getName());
builder.addMethodInstallCallback("addBootstrap");
@@ -309,4 +328,23 @@
return bootstrap;
}
+ //-------------------------------------------------------------------------------------||
+ // Internal Helper Methods ------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Creates and runs the bootstrap, setting it upon completion
+ */
+ private void initializeBootstrap()
+ {
+ // Run Bootstrap and set it
+ final BasicBootstrap bootstrap = new BasicBootstrap();
+ bootstrap.run();
+ this.bootstrap = bootstrap;
+ if (log.isTraceEnabled())
+ {
+ log.trace("Created and run: " + bootstrap);
+ }
+ }
+
}
Modified: projects/bootstrap/trunk/impl-mc/src/test/java/org/jboss/bootstrap/impl/mc/server/unit/MCServerUnitTestCase.java
===================================================================
--- projects/bootstrap/trunk/impl-mc/src/test/java/org/jboss/bootstrap/impl/mc/server/unit/MCServerUnitTestCase.java 2009-05-23 10:49:11 UTC (rev 89303)
+++ projects/bootstrap/trunk/impl-mc/src/test/java/org/jboss/bootstrap/impl/mc/server/unit/MCServerUnitTestCase.java 2009-05-23 15:53:10 UTC (rev 89304)
@@ -192,6 +192,44 @@
this.assertPojo();
}
+ /**
+ * Ensures that the MC Server may restart
+ *
+ * JBBOOT-74
+ *
+ * @throws Throwable
+ */
+ @Test
+ public void testRestart() throws Throwable
+ {
+ // Log
+ log.info("testRestart");
+
+ // Initialize
+ final MCServer server = this.server;
+
+ // Start the server
+ server.start();
+
+ // Stop the server
+ server.shutdown();
+
+ // Restart
+ boolean restartedOk = true;
+ try
+ {
+ server.start();
+ }
+ catch (final Exception e)
+ {
+ log.error("Server could not restart, exception was:", e);
+ restartedOk = false;
+ }
+
+ // Test that restart was OK
+ TestCase.assertTrue("The server did not restart as expected", restartedOk);
+ }
+
//-------------------------------------------------------------------------------------||
// Internal Helper Methods ------------------------------------------------------------||
//-------------------------------------------------------------------------------------||
More information about the jboss-cvs-commits
mailing list