[jboss-cvs] JBossAS SVN: r87976 - in projects/bootstrap/trunk: impl-as/src/main/java/org/jboss/bootstrap/impl/as/lifecycle and 8 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Wed Apr 29 01:37:43 EDT 2009
Author: ALRubinger
Date: 2009-04-29 01:37:43 -0400 (Wed, 29 Apr 2009)
New Revision: 87976
Added:
projects/bootstrap/trunk/impl-as/src/main/java/org/jboss/bootstrap/impl/as/lifecycle/
projects/bootstrap/trunk/impl-as/src/main/java/org/jboss/bootstrap/impl/as/lifecycle/AbstractKernelEventLifecycleEventHandler.java
projects/bootstrap/trunk/impl-as/src/main/java/org/jboss/bootstrap/impl/as/lifecycle/KernelStartEventLifecycleEventHandler.java
projects/bootstrap/trunk/impl-as/src/main/java/org/jboss/bootstrap/impl/as/lifecycle/KernelStopEventLifecycleEventHandler.java
projects/bootstrap/trunk/impl-as/src/test/java/org/jboss/bootstrap/impl/as/server/KernelEventsTestCase.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/LifecycleStateUpdatingEventHander.java
projects/bootstrap/trunk/impl-base/src/test/java/org/jboss/bootstrap/impl/base/server/unit/JmxNotificationsTestCase.java
projects/bootstrap/trunk/impl-base/src/test/java/org/jboss/bootstrap/impl/base/server/unit/ServerLifecycleEventCallbackTestCase.java
projects/bootstrap/trunk/impl-mc/src/main/java/org/jboss/bootstrap/impl/mc/server/AbstractMCServerBase.java
projects/bootstrap/trunk/spi/src/main/java/org/jboss/bootstrap/spi/lifecycle/LifecycleEventHandler.java
projects/bootstrap/trunk/spi/src/main/java/org/jboss/bootstrap/spi/server/Server.java
Log:
[JBBOOT-54] Fire KernelEvents for start/stop
Added: projects/bootstrap/trunk/impl-as/src/main/java/org/jboss/bootstrap/impl/as/lifecycle/AbstractKernelEventLifecycleEventHandler.java
===================================================================
--- projects/bootstrap/trunk/impl-as/src/main/java/org/jboss/bootstrap/impl/as/lifecycle/AbstractKernelEventLifecycleEventHandler.java (rev 0)
+++ projects/bootstrap/trunk/impl-as/src/main/java/org/jboss/bootstrap/impl/as/lifecycle/AbstractKernelEventLifecycleEventHandler.java 2009-04-29 05:37:43 UTC (rev 87976)
@@ -0,0 +1,141 @@
+/*
+ * 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.impl.as.lifecycle;
+
+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.Kernel;
+import org.jboss.kernel.plugins.bootstrap.basic.BasicBootstrap;
+import org.jboss.kernel.plugins.event.AbstractEvent;
+import org.jboss.kernel.spi.event.KernelEvent;
+import org.jboss.kernel.spi.event.KernelEventManager;
+import org.jboss.logging.Logger;
+
+/**
+ * AbstractKernelEventLifecycleEventHandler
+ *
+ * Base class for firing Kernel events in response to
+ * server lifecycle state changes
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+public abstract class AbstractKernelEventLifecycleEventHandler implements LifecycleEventHandler
+{
+
+ //-------------------------------------------------------------------------------------||
+ // Class Members ----------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ private static final Logger log = Logger.getLogger(AbstractKernelEventLifecycleEventHandler.class);
+
+ //-------------------------------------------------------------------------------------||
+ // Instance Members -------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * The bootstrap, whose kernel we'll use to fire events
+ */
+ private BasicBootstrap bootstrap;
+
+ //-------------------------------------------------------------------------------------||
+ // Constructor ------------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Constructor
+ *
+ * @throws IllegalArgumentException If the bootstrap was not specified
+ */
+ public AbstractKernelEventLifecycleEventHandler(final BasicBootstrap bootstrap) throws IllegalArgumentException
+ {
+ // Precondition check
+ if (bootstrap == null)
+ {
+ throw new IllegalArgumentException("Bootstrap is required");
+ }
+
+ // Set
+ this.setBootstrap(bootstrap);
+ }
+
+ //-------------------------------------------------------------------------------------||
+ // Required Implementations -----------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /* (non-Javadoc)
+ * @see org.jboss.bootstrap.spi.lifecycle.LifecycleEventHandler#handleEvent(org.jboss.bootstrap.spi.lifecycle.LifecycleState)
+ */
+ public final void handleEvent(final LifecycleState state) throws LifecycleEventException
+ {
+ // Log
+ if (log.isTraceEnabled())
+ {
+ log.trace("Handling server state change to: " + state);
+ }
+
+ // Get the Kernel
+ final Kernel kernel = this.getBootstrap().getKernel();
+
+ // Send a notification that the startup is complete
+ final KernelEventManager eventMgr = kernel.getEventManager();
+ final long currentTime = System.currentTimeMillis();
+ final String type = this.getNotificationType();
+ final KernelEvent event = new AbstractEvent(eventMgr, type, 0, currentTime, new Long(currentTime));
+ eventMgr.fireKernelEvent(event);
+
+ // Log
+ log.debug("Fired: " + event);
+ }
+
+ //-------------------------------------------------------------------------------------||
+ // Contracts --------------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Returns the notification type to be used for the Kernel event
+ */
+ protected abstract String getNotificationType();
+
+ //-------------------------------------------------------------------------------------||
+ // Internal Helper Methods ------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * @return the bootstrap
+ */
+ private BasicBootstrap getBootstrap()
+ {
+ return bootstrap;
+ }
+
+ /**
+ * @param bootstrap the bootstrap to set
+ */
+ private void setBootstrap(BasicBootstrap bootstrap)
+ {
+ this.bootstrap = bootstrap;
+ }
+
+}
Added: projects/bootstrap/trunk/impl-as/src/main/java/org/jboss/bootstrap/impl/as/lifecycle/KernelStartEventLifecycleEventHandler.java
===================================================================
--- projects/bootstrap/trunk/impl-as/src/main/java/org/jboss/bootstrap/impl/as/lifecycle/KernelStartEventLifecycleEventHandler.java (rev 0)
+++ projects/bootstrap/trunk/impl-as/src/main/java/org/jboss/bootstrap/impl/as/lifecycle/KernelStartEventLifecycleEventHandler.java 2009-04-29 05:37:43 UTC (rev 87976)
@@ -0,0 +1,61 @@
+/*
+ * 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.impl.as.lifecycle;
+
+import org.jboss.bootstrap.spi.server.Server;
+import org.jboss.kernel.plugins.bootstrap.basic.BasicBootstrap;
+
+/**
+ * KernelStartEventLifecycleEventHandler
+ *
+ * Fires the Kernel event for start in the Server lifecycle
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+public class KernelStartEventLifecycleEventHandler extends AbstractKernelEventLifecycleEventHandler
+{
+
+ //-------------------------------------------------------------------------------------||
+ // Constructor ------------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ public KernelStartEventLifecycleEventHandler(final BasicBootstrap bootstrap)
+ {
+ super(bootstrap);
+ }
+
+ //-------------------------------------------------------------------------------------||
+ // Required Implementations -----------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /* (non-Javadoc)
+ * @see org.jboss.bootstrap.impl.as.lifecycle.AbstractKernelEventLifecycleEventHandler#getNotificationType()
+ */
+ @Override
+ protected String getNotificationType()
+ {
+ return Server.START_NOTIFICATION_TYPE;
+ }
+
+}
Added: projects/bootstrap/trunk/impl-as/src/main/java/org/jboss/bootstrap/impl/as/lifecycle/KernelStopEventLifecycleEventHandler.java
===================================================================
--- projects/bootstrap/trunk/impl-as/src/main/java/org/jboss/bootstrap/impl/as/lifecycle/KernelStopEventLifecycleEventHandler.java (rev 0)
+++ projects/bootstrap/trunk/impl-as/src/main/java/org/jboss/bootstrap/impl/as/lifecycle/KernelStopEventLifecycleEventHandler.java 2009-04-29 05:37:43 UTC (rev 87976)
@@ -0,0 +1,61 @@
+/*
+ * 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.impl.as.lifecycle;
+
+import org.jboss.bootstrap.spi.server.Server;
+import org.jboss.kernel.plugins.bootstrap.basic.BasicBootstrap;
+
+/**
+ * KernelStopEventLifecycleEventHandler
+ *
+ * Fires the Kernel event for stop in the Server lifecycle
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+public class KernelStopEventLifecycleEventHandler extends AbstractKernelEventLifecycleEventHandler
+{
+
+ //-------------------------------------------------------------------------------------||
+ // Constructor ------------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ public KernelStopEventLifecycleEventHandler(final BasicBootstrap bootstrap)
+ {
+ super(bootstrap);
+ }
+
+ //-------------------------------------------------------------------------------------||
+ // Required Implementations -----------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /* (non-Javadoc)
+ * @see org.jboss.bootstrap.impl.as.lifecycle.AbstractKernelEventLifecycleEventHandler#getNotificationType()
+ */
+ @Override
+ protected String getNotificationType()
+ {
+ return Server.STOP_NOTIFICATION_TYPE;
+ }
+
+}
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-04-29 05:23:38 UTC (rev 87975)
+++ projects/bootstrap/trunk/impl-as/src/main/java/org/jboss/bootstrap/impl/as/server/JBossASServerImpl.java 2009-04-29 05:37:43 UTC (rev 87976)
@@ -29,8 +29,13 @@
import org.jboss.bootstrap.impl.as.config.JBossASConfigurationInitializerImpl;
import org.jboss.bootstrap.impl.as.config.JBossASConfigurationValidator;
import org.jboss.bootstrap.impl.as.config.JBossASServerConfig;
+import org.jboss.bootstrap.impl.as.lifecycle.KernelStartEventLifecycleEventHandler;
+import org.jboss.bootstrap.impl.as.lifecycle.KernelStopEventLifecycleEventHandler;
import org.jboss.bootstrap.impl.mc.server.AbstractMCServerBase;
import org.jboss.bootstrap.spi.config.ConfigurationValidator;
+import org.jboss.bootstrap.spi.lifecycle.LifecycleEventHandler;
+import org.jboss.bootstrap.spi.lifecycle.LifecycleState;
+import org.jboss.kernel.plugins.bootstrap.basic.BasicBootstrap;
import org.jboss.managed.api.annotation.ManagementProperty;
/**
@@ -122,6 +127,13 @@
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);
}
//-------------------------------------------------------------------------------||
Added: 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 (rev 0)
+++ projects/bootstrap/trunk/impl-as/src/test/java/org/jboss/bootstrap/impl/as/server/KernelEventsTestCase.java 2009-04-29 05:37:43 UTC (rev 87976)
@@ -0,0 +1,179 @@
+/*
+ * 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.impl.as.server;
+
+import junit.framework.TestCase;
+
+import org.jboss.bootstrap.spi.server.Server;
+import org.jboss.kernel.Kernel;
+import org.jboss.kernel.spi.event.KernelEvent;
+import org.jboss.kernel.spi.event.KernelEventListener;
+import org.jboss.kernel.spi.event.KernelEventManager;
+import org.jboss.logging.Logger;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * KernelEventsTestCase
+ *
+ * Tests to ensure that the Kernel Events for
+ * start/stop are received
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+public class KernelEventsTestCase
+{
+ //-------------------------------------------------------------------------------------||
+ // Class Members ----------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ private static final Logger log = Logger.getLogger(KernelEventsTestCase.class);
+
+ //-------------------------------------------------------------------------------------||
+ // Instance Members -------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * The Server
+ */
+ private JBossASServer server;
+
+ /**
+ * Whether or not we got the start event
+ */
+ private boolean gotStartEvent;
+
+ /**
+ * Whether or not we got the stop event
+ */
+ private boolean gotStopEvent;
+
+ //-------------------------------------------------------------------------------------||
+ // Lifecycle --------------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Initializes the test server and registers listeners
+ *
+ */
+ @Before
+ public void init() throws Throwable
+ {
+ // Make and set the test server
+ final JBossASServer server = new NoOpJBossASServer();
+ this.server = server;
+
+ // 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
+ public void cleanup() throws Throwable
+ {
+ // Reset everything
+ this.gotStartEvent = false;
+ this.gotStopEvent = false;
+ this.server = null;
+ }
+
+ //-------------------------------------------------------------------------------------||
+ // Tests ------------------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Ensures that the Kernel Events for start and stop
+ * were fired
+ */
+ @Test
+ public void testKernelEvents() throws Throwable
+ {
+ // Log
+ log.info("testJmxNotifications");
+
+ // Get the server
+ final JBossASServer server = this.server;
+
+ // 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);
+
+ }
+
+ //-------------------------------------------------------------------------------------||
+ // Inner Classes ----------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Listens for Kernel Events, setting flags as appropriate
+ * based upon the received type
+ */
+ private class TestKernelEventListener implements KernelEventListener
+ {
+ //-------------------------------------------------------------------------------------||
+ // Required Implementations -----------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /* (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)
+ {
+ // Log
+ log.info("Got event: " + event);
+
+ // Figure out the notification received
+ final String type = event.getType();
+
+ // Take appropriate action
+ if (Server.START_NOTIFICATION_TYPE.equals(type))
+ {
+ // Set received
+ gotStartEvent = true;
+ }
+ else if (Server.STOP_NOTIFICATION_TYPE.equals(type))
+ {
+ // Set received
+ gotStopEvent = true;
+ }
+ }
+ }
+
+}
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-04-29 05:23:38 UTC (rev 87975)
+++ projects/bootstrap/trunk/impl-base/src/main/java/org/jboss/bootstrap/impl/base/server/AbstractServer.java 2009-04-29 05:37:43 UTC (rev 87976)
@@ -114,7 +114,7 @@
/**
* Event handlers for each lifecycle state change
*/
- private final Map<LifecycleState, Set<LifecycleEventHandler<K, T>>> eventHandlers = new ConcurrentHashMap<LifecycleState, Set<LifecycleEventHandler<K, T>>>();
+ private final Map<LifecycleState, Set<LifecycleEventHandler>> eventHandlers = new ConcurrentHashMap<LifecycleState, Set<LifecycleEventHandler>>();
//-------------------------------------------------------------------------------------||
// Constructors -----------------------------------------------------------------------||
@@ -497,8 +497,7 @@
/* (non-Javadoc)
* @see org.jboss.bootstrap.spi.server.Server#registerEventHandlers(org.jboss.bootstrap.spi.lifecycle.LifecycleState, org.jboss.bootstrap.spi.lifecycle.LifecycleEventHandler)
*/
- @SuppressWarnings("unchecked")
- public void registerEventHandler(final LifecycleState state, final LifecycleEventHandler<K, T> handler)
+ public void registerEventHandler(final LifecycleState state, final LifecycleEventHandler handler)
throws IllegalArgumentException
{
// Delegate
@@ -508,7 +507,7 @@
/* (non-Javadoc)
* @see org.jboss.bootstrap.spi.server.Server#registerEventHandler(org.jboss.bootstrap.spi.lifecycle.LifecycleEventHandler, java.util.EnumSet)
*/
- public void registerEventHandler(final LifecycleEventHandler<K, T> handler, final EnumSet<LifecycleState> states)
+ public void registerEventHandler(final LifecycleEventHandler handler, final EnumSet<LifecycleState> states)
throws IllegalArgumentException
{
// Precondition checks
@@ -531,7 +530,7 @@
/* (non-Javadoc)
* @see org.jboss.bootstrap.spi.server.Server#registerEventHandler(org.jboss.bootstrap.spi.lifecycle.LifecycleEventHandler, org.jboss.bootstrap.spi.lifecycle.LifecycleState[])
*/
- public void registerEventHandler(final LifecycleEventHandler<K, T> handler, final LifecycleState... states)
+ public void registerEventHandler(final LifecycleEventHandler handler, final LifecycleState... states)
throws IllegalArgumentException
{
// Precondition checks
@@ -554,7 +553,7 @@
/* (non-Javadoc)
* @see org.jboss.bootstrap.spi.server.Server#registerEventHandler(org.jboss.bootstrap.spi.lifecycle.LifecycleState, org.jboss.bootstrap.spi.lifecycle.LifecycleEventHandler)
*/
- public void registerEventHandlers(final LifecycleState state, final LifecycleEventHandler<K, T>... handlers)
+ public void registerEventHandlers(final LifecycleState state, final LifecycleEventHandler... handlers)
throws IllegalArgumentException
{
// Precondition checks
@@ -568,10 +567,10 @@
}
// Get existing handlers for this state change
- final Set<LifecycleEventHandler<K, T>> handlersForEvent = this.getHandlersForEvent(state);
+ final Set<LifecycleEventHandler> handlersForEvent = this.getHandlersForEvent(state);
// Add the state change
- for (final LifecycleEventHandler<K, T> handler : handlers)
+ for (final LifecycleEventHandler handler : handlers)
{
handlersForEvent.add(handler);
log.debug("Added lifecycle handler " + handler + " to fire upon state change to " + state + " for " + this);
@@ -581,11 +580,11 @@
/* (non-Javadoc)
* @see org.jboss.bootstrap.spi.server.Server#unregisterEventHandler(org.jboss.bootstrap.spi.lifecycle.LifecycleEventHandler,org.jboss.bootstrap.spi.lifecycle.LifecycleState)
*/
- public boolean unregisterEventHandler(final LifecycleEventHandler<K, T> handler, final LifecycleState state)
+ public boolean unregisterEventHandler(final LifecycleEventHandler handler, final LifecycleState state)
throws IllegalArgumentException
{
// Get all handlers for this state change
- final Set<LifecycleEventHandler<K, T>> handlers = this.getHandlersForEvent(state);
+ final Set<LifecycleEventHandler> handlers = this.getHandlersForEvent(state);
// Remove and return
final boolean removed = handlers.remove(handler);
@@ -715,8 +714,7 @@
* @return
* @throws IllegalArgumentException If the state was not specified
*/
- private Set<LifecycleEventHandler<K, T>> getHandlersForEvent(final LifecycleState state)
- throws IllegalArgumentException
+ private Set<LifecycleEventHandler> getHandlersForEvent(final LifecycleState state) throws IllegalArgumentException
{
// Precondition check
if (state == null)
@@ -725,12 +723,12 @@
}
// Initialize
- Set<LifecycleEventHandler<K, T>> handlers = this.eventHandlers.get(state);
+ Set<LifecycleEventHandler> handlers = this.eventHandlers.get(state);
// Adjust to empty List if null
if (handlers == null)
{
- handlers = new CopyOnWriteArraySet<LifecycleEventHandler<K, T>>();
+ handlers = new CopyOnWriteArraySet<LifecycleEventHandler>();
// Put this new list into the backing Map to prevent null access
this.eventHandlers.put(state, handlers);
if (log.isTraceEnabled())
@@ -840,8 +838,8 @@
this.state = state;
// Fire handlers registered for event changes to this state
- final Set<LifecycleEventHandler<K, T>> handlers = this.getHandlersForEvent(state);
- for (final LifecycleEventHandler<K, T> handler : handlers)
+ final Set<LifecycleEventHandler> handlers = this.getHandlersForEvent(state);
+ for (final LifecycleEventHandler handler : handlers)
{
try
{
Modified: projects/bootstrap/trunk/impl-base/src/test/java/org/jboss/bootstrap/impl/base/server/LifecycleStateUpdatingEventHander.java
===================================================================
--- projects/bootstrap/trunk/impl-base/src/test/java/org/jboss/bootstrap/impl/base/server/LifecycleStateUpdatingEventHander.java 2009-04-29 05:23:38 UTC (rev 87975)
+++ projects/bootstrap/trunk/impl-base/src/test/java/org/jboss/bootstrap/impl/base/server/LifecycleStateUpdatingEventHander.java 2009-04-29 05:37:43 UTC (rev 87976)
@@ -22,7 +22,6 @@
package org.jboss.bootstrap.impl.base.server;
-import org.jboss.bootstrap.impl.base.config.TestServerConfig;
import org.jboss.bootstrap.spi.lifecycle.LifecycleEventException;
import org.jboss.bootstrap.spi.lifecycle.LifecycleEventHandler;
import org.jboss.bootstrap.spi.lifecycle.LifecycleState;
@@ -36,7 +35,7 @@
* @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
* @version $Revision: $
*/
-public class LifecycleStateUpdatingEventHander implements LifecycleEventHandler<TestNoOpServer, TestServerConfig>
+public class LifecycleStateUpdatingEventHander implements LifecycleEventHandler
{
//-------------------------------------------------------------------------------------||
// Class Members ----------------------------------------------------------------------||
Modified: projects/bootstrap/trunk/impl-base/src/test/java/org/jboss/bootstrap/impl/base/server/unit/JmxNotificationsTestCase.java
===================================================================
--- projects/bootstrap/trunk/impl-base/src/test/java/org/jboss/bootstrap/impl/base/server/unit/JmxNotificationsTestCase.java 2009-04-29 05:23:38 UTC (rev 87975)
+++ projects/bootstrap/trunk/impl-base/src/test/java/org/jboss/bootstrap/impl/base/server/unit/JmxNotificationsTestCase.java 2009-04-29 05:37:43 UTC (rev 87976)
@@ -111,6 +111,7 @@
{
// Reset everything
this.gotStartNotification = false;
+ this.gotStopNotification = false;
this.server = null;
}
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-04-29 05:23:38 UTC (rev 87975)
+++ projects/bootstrap/trunk/impl-base/src/test/java/org/jboss/bootstrap/impl/base/server/unit/ServerLifecycleEventCallbackTestCase.java 2009-04-29 05:37:43 UTC (rev 87976)
@@ -24,7 +24,6 @@
import junit.framework.TestCase;
-import org.jboss.bootstrap.impl.base.config.TestServerConfig;
import org.jboss.bootstrap.impl.base.server.LifecycleStateTracker;
import org.jboss.bootstrap.impl.base.server.LifecycleStateUpdatingEventHander;
import org.jboss.bootstrap.impl.base.server.TestNoOpServer;
@@ -84,7 +83,7 @@
/**
* Event handler
*/
- private LifecycleEventHandler<TestNoOpServer, TestServerConfig> handler;
+ private LifecycleEventHandler handler;
//-------------------------------------------------------------------------------------||
// Lifecycle --------------------------------------------------------------------------||
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-04-29 05:23:38 UTC (rev 87975)
+++ projects/bootstrap/trunk/impl-mc/src/main/java/org/jboss/bootstrap/impl/mc/server/AbstractMCServerBase.java 2009-04-29 05:37:43 UTC (rev 87976)
@@ -30,6 +30,8 @@
import org.jboss.bootstrap.impl.base.server.AbstractServer;
import org.jboss.bootstrap.impl.base.xml.BootstrapParser;
import org.jboss.bootstrap.impl.mc.deployer.TempBasicXMLDeployer;
+import org.jboss.bootstrap.spi.config.InvalidConfigurationException;
+import org.jboss.bootstrap.spi.lifecycle.LifecycleEventException;
import org.jboss.bootstrap.spi.mc.config.MCBasedServerConfig;
import org.jboss.bootstrap.spi.mc.server.MCBasedServer;
import org.jboss.bootstrap.spi.metadata.BootstrapMetaData;
@@ -104,6 +106,10 @@
{
// Invoke super
super(config);
+
+ // Create Bootstrap and set both it and the kernel
+ final BasicBootstrap bootstrap = new BasicBootstrap();
+ this.bootstrap = bootstrap;
}
//-------------------------------------------------------------------------------------||
@@ -167,17 +173,32 @@
}
/* (non-Javadoc)
+ * @see org.jboss.bootstrap.impl.base.server.AbstractServer#initialize()
+ */
+ @Override
+ public synchronized void initialize() throws IllegalStateException, InvalidConfigurationException,
+ LifecycleEventException
+ {
+ // Call Super implementation
+ super.initialize();
+
+ /*
+ * We need to start the bootstrap here so we can set the kernel
+ * before we fire start kernel events
+ */
+
+ // Run Bootstrap and set the Kernel
+ final BasicBootstrap bootstrap = this.getBootstrap();
+ bootstrap.run();
+ this.kernel = bootstrap.getKernel();
+ }
+
+ /* (non-Javadoc)
* @see org.jboss.bootstrap.spi.server.AbstractServer#doStart()
*/
@Override
protected void doStart() throws Exception
{
- // Bootstrap and set the kernel
- final BasicBootstrap bootstrap = new BasicBootstrap();
- bootstrap.run();
- kernel = bootstrap.getKernel();
- this.bootstrap = bootstrap;
-
// Register the server implementation
final String mcServerBindName = "JBossServer";
final KernelController controller = kernel.getController();
@@ -246,7 +267,15 @@
}
//-------------------------------------------------------------------------------------||
- // Internal Helper Methods ------------------------------------------------------------||
+ // Functional Methods -----------------------------------------------------------------||
//-------------------------------------------------------------------------------------||
+ /**
+ * @return the bootstrap
+ */
+ protected final BasicBootstrap getBootstrap()
+ {
+ return bootstrap;
+ }
+
}
Modified: projects/bootstrap/trunk/spi/src/main/java/org/jboss/bootstrap/spi/lifecycle/LifecycleEventHandler.java
===================================================================
--- projects/bootstrap/trunk/spi/src/main/java/org/jboss/bootstrap/spi/lifecycle/LifecycleEventHandler.java 2009-04-29 05:23:38 UTC (rev 87975)
+++ projects/bootstrap/trunk/spi/src/main/java/org/jboss/bootstrap/spi/lifecycle/LifecycleEventHandler.java 2009-04-29 05:37:43 UTC (rev 87976)
@@ -22,9 +22,6 @@
package org.jboss.bootstrap.spi.lifecycle;
-import org.jboss.bootstrap.spi.config.ServerConfig;
-import org.jboss.bootstrap.spi.server.Server;
-
/**
* LifecycleEventHandler
*
@@ -35,7 +32,7 @@
* @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
* @version $Revision: $
*/
-public interface LifecycleEventHandler<K extends Server<K, T>, T extends ServerConfig<T>>
+public interface LifecycleEventHandler
{
//-------------------------------------------------------------------------------------||
// Contracts --------------------------------------------------------------------------||
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-29 05:23:38 UTC (rev 87975)
+++ projects/bootstrap/trunk/spi/src/main/java/org/jboss/bootstrap/spi/server/Server.java 2009-04-29 05:37:43 UTC (rev 87976)
@@ -150,7 +150,7 @@
* @param handler
* @throws IllegalArgumentException If either the state or the handler are unspecified
*/
- void registerEventHandler(LifecycleState state, LifecycleEventHandler<K, T> handler) throws IllegalArgumentException;
+ void registerEventHandler(LifecycleState state, LifecycleEventHandler handler) throws IllegalArgumentException;
/**
* Registers the specified handler to fire when
@@ -160,7 +160,7 @@
* @param states
* @throws IllegalArgumentException If either the states or the handler are unspecified
*/
- void registerEventHandler(LifecycleEventHandler<K, T> handler, EnumSet<LifecycleState> states)
+ void registerEventHandler(LifecycleEventHandler handler, EnumSet<LifecycleState> states)
throws IllegalArgumentException;
/**
@@ -171,8 +171,7 @@
* @param states
* @throws IllegalArgumentException If either the states or the handler are unspecified
*/
- void registerEventHandler(LifecycleEventHandler<K, T> handler, LifecycleState... states)
- throws IllegalArgumentException;
+ void registerEventHandler(LifecycleEventHandler handler, LifecycleState... states) throws IllegalArgumentException;
/**
* Registers the specified handlers to fire when
@@ -182,8 +181,7 @@
* @param handlers
* @throws IllegalArgumentException If either the state or the handlers are unspecified
*/
- void registerEventHandlers(LifecycleState state, LifecycleEventHandler<K, T>... handlers)
- throws IllegalArgumentException;
+ void registerEventHandlers(LifecycleState state, LifecycleEventHandler... handlers) throws IllegalArgumentException;
/**
* Unregisters the specified event handler from firing
@@ -194,8 +192,7 @@
* @return Whether or not the handler was removed (ie. false if not registered)
* @throws IllegalArgumentException If either the state or handler are unspecified
*/
- boolean unregisterEventHandler(LifecycleEventHandler<K, T> handler, LifecycleState state)
- throws IllegalArgumentException;
+ boolean unregisterEventHandler(LifecycleEventHandler handler, LifecycleState state) throws IllegalArgumentException;
/**
* Returns the underlying server configuration. If
More information about the jboss-cvs-commits
mailing list