[jboss-cvs] JBossAS SVN: r87836 - in projects/bootstrap/trunk: impl-base/src/test/java/org/jboss/bootstrap/impl/base/server and 3 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Fri Apr 24 23:22:30 EDT 2009
Author: ALRubinger
Date: 2009-04-24 23:22:30 -0400 (Fri, 24 Apr 2009)
New Revision: 87836
Added:
projects/bootstrap/trunk/impl-base/src/test/java/org/jboss/bootstrap/impl/base/server/LifecycleStateTracker.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/ServerLifecycleEventCallbackTestCase.java
projects/bootstrap/trunk/spi/src/main/java/org/jboss/bootstrap/spi/lifecycle/LifecycleEventException.java
projects/bootstrap/trunk/spi/src/main/java/org/jboss/bootstrap/spi/lifecycle/LifecycleEventHandler.java
Modified:
projects/bootstrap/trunk/impl-base/src/main/java/org/jboss/bootstrap/impl/base/server/AbstractServer.java
projects/bootstrap/trunk/spi/src/main/java/org/jboss/bootstrap/spi/server/Server.java
Log:
[JBBOOT-32] Implement server LifecycleState event callbacks, and test
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-25 01:25:30 UTC (rev 87835)
+++ projects/bootstrap/trunk/impl-base/src/main/java/org/jboss/bootstrap/impl/base/server/AbstractServer.java 2009-04-25 03:22:30 UTC (rev 87836)
@@ -22,7 +22,10 @@
package org.jboss.bootstrap.impl.base.server;
+import java.util.ArrayList;
import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArrayList;
import org.jboss.bootstrap.spi.Bootstrap;
@@ -30,6 +33,8 @@
import org.jboss.bootstrap.spi.config.ConfigurationValidator;
import org.jboss.bootstrap.spi.config.InvalidConfigurationException;
import org.jboss.bootstrap.spi.config.ServerConfig;
+import org.jboss.bootstrap.spi.lifecycle.LifecycleEventException;
+import org.jboss.bootstrap.spi.lifecycle.LifecycleEventHandler;
import org.jboss.bootstrap.spi.lifecycle.LifecycleState;
import org.jboss.bootstrap.spi.server.Server;
import org.jboss.bootstrap.spi.server.ServerInitializer;
@@ -58,8 +63,9 @@
/**
* Current state of the server. Synchronized on "this".
+ * Volatile so we can return the current state without blocking.
*/
- private LifecycleState state;
+ private volatile LifecycleState state;
/**
* Underlying configuration. Must be a Thread-safe implementation
@@ -95,6 +101,11 @@
*/
private final List<Bootstrap> startedBootstraps = new CopyOnWriteArrayList<Bootstrap>();
+ /**
+ * Event handlers for each lifecycle state change
+ */
+ private final Map<LifecycleState, List<LifecycleEventHandler<K, T>>> eventHandlers = new ConcurrentHashMap<LifecycleState, List<LifecycleEventHandler<K, T>>>();
+
//-------------------------------------------------------------------------------------||
// Constructors -----------------------------------------------------------------------||
//-------------------------------------------------------------------------------------||
@@ -145,7 +156,7 @@
newConfiguration = SecurityActions.newInstance(configClass);
log.debug("Created new default configuration: " + newConfiguration);
}
- catch (Throwable t)
+ catch (final Throwable t)
{
throw new RuntimeException("Could not create default configuration of type " + configClass, t);
}
@@ -156,7 +167,15 @@
// Set properties
this.setConfiguration(configToSet);
- this.setState(LifecycleState.PRE_INIT);
+ try
+ {
+ this.setState(LifecycleState.PRE_INIT);
+ }
+ catch (final LifecycleEventException e)
+ {
+ // No handlers can be registered yet (this is still construction),
+ // so we can safely ignore lifecycle event problems
+ }
}
//-------------------------------------------------------------------------------------||
@@ -187,9 +206,9 @@
/* (non-Javadoc)
* @see org.jboss.bootstrap.spi.server.Server#getState()
*/
- public final synchronized LifecycleState getState()
+ public final LifecycleState getState()
{
- LifecycleState state = this.state;
+ final LifecycleState state = this.state;
if (state == null)
{
throw new IllegalStateException("null state");
@@ -200,7 +219,7 @@
/* (non-Javadoc)
* @see org.jboss.bootstrap.spi.server.Server#shutdown()
*/
- public void shutdown() throws IllegalStateException, Exception
+ public synchronized void shutdown() throws IllegalStateException, Exception
{
// Log
if (log.isTraceEnabled())
@@ -250,7 +269,7 @@
/* (non-Javadoc)
* @see org.jboss.bootstrap.spi.server.Server#start()
*/
- public void start() throws IllegalStateException, Exception
+ public synchronized void start() throws IllegalStateException, Exception
{
// Log
if (log.isTraceEnabled())
@@ -335,7 +354,8 @@
/* (non-Javadoc)
* @see org.jboss.bootstrap.spi.server.Server#initialize()
*/
- public synchronized void initialize() throws IllegalStateException, InvalidConfigurationException
+ public synchronized void initialize() throws IllegalStateException, InvalidConfigurationException,
+ LifecycleEventException
{
// Log
log.debug("Initializing server: " + this);
@@ -456,6 +476,35 @@
this.validator = validator;
}
+ /* (non-Javadoc)
+ * @see org.jboss.bootstrap.spi.server.Server#registerEventHandler(org.jboss.bootstrap.spi.lifecycle.LifecycleState, org.jboss.bootstrap.spi.lifecycle.LifecycleEventHandler)
+ */
+ public void registerEventHandler(final LifecycleState state, final LifecycleEventHandler<K, T> handler)
+ throws IllegalArgumentException
+ {
+ // Get existing handlers for this state change
+ final List<LifecycleEventHandler<K, T>> handlers = this.getHandlersForEvent(state);
+
+ // Add the state change
+ handlers.add(handler);
+ log.debug("Added lifecycle handler " + handler + " to fire upon state change to " + state + " for " + this);
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.bootstrap.spi.server.Server#unregisterEventHandler(org.jboss.bootstrap.spi.lifecycle.LifecycleState, org.jboss.bootstrap.spi.lifecycle.LifecycleEventHandler)
+ */
+ public boolean unregisterEventHandler(final LifecycleState state, final LifecycleEventHandler<K, T> handler)
+ throws IllegalArgumentException
+ {
+ // Get all handlers for this state change
+ final List<LifecycleEventHandler<K, T>> handlers = this.getHandlersForEvent(state);
+
+ // Remove and return
+ final boolean removed = handlers.remove(handler);
+ log.debug("Removed lifecycle handler " + handler + " from firing upon state change to " + state + " for " + this);
+ return removed;
+ }
+
//-------------------------------------------------------------------------------------||
// Contracts --------------------------------------------------------------------------||
//-------------------------------------------------------------------------------------||
@@ -537,6 +586,40 @@
//-------------------------------------------------------------------------------------||
/**
+ * 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
+ * to prevent encountering a null backing List.
+ *
+ * @param state The target state change for the event
+ * @return
+ * @throws IllegalArgumentException If the state was not specified
+ */
+ private List<LifecycleEventHandler<K, T>> getHandlersForEvent(final LifecycleState state)
+ throws IllegalArgumentException
+ {
+
+ // Initialize
+ List<LifecycleEventHandler<K, T>> handlers = this.eventHandlers.get(state);
+
+ // Adjust to empty List if null
+ if (handlers == null)
+ {
+ handlers = new ArrayList<LifecycleEventHandler<K, T>>();
+ // Put this new list into the backing Map to prevent null access
+ this.eventHandlers.put(state, handlers);
+ if (log.isTraceEnabled())
+ {
+ log.trace("Placed empty backing map for lifecycle event handers upon state change into " + state + " for: "
+ + this);
+ }
+ }
+
+ // Return
+ return handlers;
+ }
+
+ /**
* Ensures the actual state matches the required, throwing {@link IllegalStateException}
* if not
*
@@ -608,16 +691,52 @@
}
/**
+ * Sets the state of the server, firing the appropriate lifecycle
+ * events to the registered handlers
+ *
* @param state the state to set
+ * @throws Exception If some error was encountered while firing the handlers
+ * @throws IllegalArgumentException If no state was specified
*/
- private synchronized final void setState(final LifecycleState state)
+ private synchronized final void setState(final LifecycleState state) throws LifecycleEventException,
+ IllegalArgumentException
{
+ // Precondition check
+ if (state == null)
+ {
+ throw new IllegalArgumentException("State was not specified");
+ }
+
// Log and set
if (log.isTraceEnabled())
{
log.trace("Setting " + LifecycleState.class.getSimpleName() + " to: " + state);
}
this.state = state;
+
+ // Fire handlers registered for event changes to this state
+ final List<LifecycleEventHandler<K, T>> handlers = this.getHandlersForEvent(state);
+ for (final LifecycleEventHandler<K, T> handler : handlers)
+ {
+ try
+ {
+ // Log
+ if (log.isTraceEnabled())
+ {
+ log.trace("Firing event handler for state change to " + state + ": " + handler);
+ }
+
+ // Fire
+ handler.handleEvent(this, state);
+ }
+ catch (final LifecycleEventException t)
+ {
+ // Log and rethrow
+ log.error("Encountered problem in firing event handler " + handler + " for state change to " + state
+ + " in " + this, t);
+ throw t;
+ }
+ }
}
}
Added: projects/bootstrap/trunk/impl-base/src/test/java/org/jboss/bootstrap/impl/base/server/LifecycleStateTracker.java
===================================================================
--- projects/bootstrap/trunk/impl-base/src/test/java/org/jboss/bootstrap/impl/base/server/LifecycleStateTracker.java (rev 0)
+++ projects/bootstrap/trunk/impl-base/src/test/java/org/jboss/bootstrap/impl/base/server/LifecycleStateTracker.java 2009-04-25 03:22:30 UTC (rev 87836)
@@ -0,0 +1,63 @@
+/*
+ * 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.base.server;
+
+import org.jboss.bootstrap.spi.lifecycle.LifecycleState;
+
+/**
+ * LifecycleStateTracker
+ *
+ * Simple Bean to hold and provide access to some {@link LifecycleState}
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+public class LifecycleStateTracker
+{
+ //-------------------------------------------------------------------------------------||
+ // Instance Members -------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ private LifecycleState state;
+
+ //-------------------------------------------------------------------------------------||
+ // Accessors / Mutators ---------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * @return the state
+ */
+ public LifecycleState getState()
+ {
+ return state;
+ }
+
+ /**
+ * @param state the state to set
+ */
+ public void setState(LifecycleState state)
+ {
+ this.state = state;
+ }
+
+}
Added: 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 (rev 0)
+++ projects/bootstrap/trunk/impl-base/src/test/java/org/jboss/bootstrap/impl/base/server/LifecycleStateUpdatingEventHander.java 2009-04-25 03:22:30 UTC (rev 87836)
@@ -0,0 +1,81 @@
+/*
+ * 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.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;
+import org.jboss.bootstrap.spi.server.Server;
+import org.jboss.logging.Logger;
+
+/**
+ * LifecycleStateUpdatingEventHander
+ *
+ * Updates a backing value object upon server event changes
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+public class LifecycleStateUpdatingEventHander implements LifecycleEventHandler<TestNoOpServer, TestServerConfig>
+{
+ //-------------------------------------------------------------------------------------||
+ // Class Members ----------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ private static final Logger log = Logger.getLogger(LifecycleStateUpdatingEventHander.class);
+
+ //-------------------------------------------------------------------------------------||
+ // Instance Members -------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Value object
+ */
+ private LifecycleStateTracker tracker;
+
+ //-------------------------------------------------------------------------------------||
+ // Constructor ------------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ public LifecycleStateUpdatingEventHander(final LifecycleStateTracker tracker)
+ {
+ this.tracker = tracker;
+ }
+
+ //-------------------------------------------------------------------------------------||
+ // Required Implementations -----------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /* (non-Javadoc)
+ * @see org.jboss.bootstrap.spi.lifecycle.LifecycleEventHandler#handleEvent(org.jboss.bootstrap.spi.server.Server, org.jboss.bootstrap.spi.lifecycle.LifecycleState)
+ */
+ public void handleEvent(Server<TestNoOpServer, TestServerConfig> server, LifecycleState state)
+ throws LifecycleEventException
+ {
+ // Set state
+ log.info("Setting state: " + state);
+ this.tracker.setState(state);
+ }
+
+}
Added: 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 (rev 0)
+++ projects/bootstrap/trunk/impl-base/src/test/java/org/jboss/bootstrap/impl/base/server/unit/ServerLifecycleEventCallbackTestCase.java 2009-04-25 03:22:30 UTC (rev 87836)
@@ -0,0 +1,154 @@
+/*
+ * 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.base.server.unit;
+
+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;
+import org.jboss.bootstrap.spi.lifecycle.LifecycleEventHandler;
+import org.jboss.bootstrap.spi.lifecycle.LifecycleState;
+import org.jboss.logging.Logger;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * ServerLifecycleEventCallbackTestCase
+ *
+ * Tests to ensure that lifecycle callbacks are invoked
+ * by the server
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+public class ServerLifecycleEventCallbackTestCase
+{
+ //-------------------------------------------------------------------------------------||
+ // Class Members ----------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ private static final Logger log = Logger.getLogger(ServerLifecycleEventCallbackTestCase.class);
+
+ /**
+ * Message used in test failures
+ */
+ private static final String FAIL_MESSAGE = "Callback was not handled";
+
+ /**
+ * The Idle State
+ */
+ private static final LifecycleState IDLE = LifecycleState.IDLE;
+
+ /**
+ * The Started State
+ */
+ private static final LifecycleState STARTED = LifecycleState.STARTED;
+
+ //-------------------------------------------------------------------------------------||
+ // Instance Members -------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * POJO used to track state changes via the callback handlers
+ */
+ private LifecycleStateTracker tracker;
+
+ /**
+ * Server used to test callbacks
+ */
+ private TestNoOpServer server;
+
+ /**
+ * Event handler
+ */
+ private LifecycleEventHandler<TestNoOpServer, TestServerConfig> handler;
+
+ //-------------------------------------------------------------------------------------||
+ // Lifecycle --------------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Sets up the server, event handler, and tracker
+ */
+ @Before
+ public void init()
+ {
+ tracker = new LifecycleStateTracker();
+ server = new TestNoOpServer();
+ handler = new LifecycleStateUpdatingEventHander(tracker);
+ }
+
+ /**
+ * Cleans up resources before the next test is run
+ */
+ @After
+ public void cleanup()
+ {
+ // Null out
+ tracker = null;
+ server = null;
+ }
+
+ //-------------------------------------------------------------------------------------||
+ // Tests ------------------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Ensures that the callback is handled for startup/shutdown
+ */
+ @Test
+ public void testLifecycleCallbacks() throws Throwable
+ {
+ // Log
+ log.info("testIdleCallback");
+
+ // Register the handler with events
+ server.registerEventHandler(IDLE, handler);
+ server.registerEventHandler(STARTED, handler);
+
+ // Test no initial state
+ TestCase.assertNull(tracker.getState());
+
+ // Init the server
+ server.initialize();
+
+ // Test for idle
+ TestCase.assertEquals(FAIL_MESSAGE, IDLE, tracker.getState());
+
+ // Start server
+ server.start();
+
+ // Test for started
+ TestCase.assertEquals(FAIL_MESSAGE, STARTED, tracker.getState());
+
+ // Shutdown server
+ server.shutdown();
+
+ // Test for idle
+ TestCase.assertEquals(FAIL_MESSAGE, IDLE, tracker.getState());
+ }
+
+}
Added: projects/bootstrap/trunk/spi/src/main/java/org/jboss/bootstrap/spi/lifecycle/LifecycleEventException.java
===================================================================
--- projects/bootstrap/trunk/spi/src/main/java/org/jboss/bootstrap/spi/lifecycle/LifecycleEventException.java (rev 0)
+++ projects/bootstrap/trunk/spi/src/main/java/org/jboss/bootstrap/spi/lifecycle/LifecycleEventException.java 2009-04-25 03:22:30 UTC (rev 87836)
@@ -0,0 +1,80 @@
+/*
+ * 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.lifecycle;
+
+/**
+ * LifecycleEventException
+ *
+ * Thrown by a lifecycle event handler if an error was encountered
+ * in processing
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+public class LifecycleEventException extends Exception
+{
+
+ //-------------------------------------------------------------------------------------||
+ // Class Members ----------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ private static final long serialVersionUID = 1L;
+
+ //-------------------------------------------------------------------------------------||
+ // Constructors -----------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ *
+ */
+ public LifecycleEventException()
+ {
+ super();
+ }
+
+ /**
+ * @param message
+ * @param cause
+ */
+ public LifecycleEventException(String message, Throwable cause)
+ {
+ super(message, cause);
+ }
+
+ /**
+ * @param message
+ */
+ public LifecycleEventException(String message)
+ {
+ super(message);
+ }
+
+ /**
+ * @param cause
+ */
+ public LifecycleEventException(Throwable cause)
+ {
+ super(cause);
+ }
+
+}
Added: 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 (rev 0)
+++ projects/bootstrap/trunk/spi/src/main/java/org/jboss/bootstrap/spi/lifecycle/LifecycleEventHandler.java 2009-04-25 03:22:30 UTC (rev 87836)
@@ -0,0 +1,52 @@
+/*
+ * 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.lifecycle;
+
+import org.jboss.bootstrap.spi.config.ServerConfig;
+import org.jboss.bootstrap.spi.server.Server;
+
+/**
+ * LifecycleEventHandler
+ *
+ * A callback to handle some lifecycle state change. Registered
+ * with the server, and fired immediately after the state change has
+ * taken place.
+ *
+ * @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>>
+{
+ //-------------------------------------------------------------------------------------||
+ // Contracts --------------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Fired upon the event change with which it was registered to handle
+ *
+ * @param server The server
+ * @param state The new state
+ * @throws LifecycleEventException If an error was encounterd in processing
+ */
+ void handleEvent(Server<K, T> server, LifecycleState state) throws LifecycleEventException;
+}
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-25 01:25:30 UTC (rev 87835)
+++ projects/bootstrap/trunk/spi/src/main/java/org/jboss/bootstrap/spi/server/Server.java 2009-04-25 03:22:30 UTC (rev 87836)
@@ -27,6 +27,8 @@
import org.jboss.bootstrap.spi.config.ConfigurationValidator;
import org.jboss.bootstrap.spi.config.InvalidConfigurationException;
import org.jboss.bootstrap.spi.config.ServerConfig;
+import org.jboss.bootstrap.spi.lifecycle.LifecycleEventException;
+import org.jboss.bootstrap.spi.lifecycle.LifecycleEventHandler;
import org.jboss.bootstrap.spi.lifecycle.LifecycleState;
/**
@@ -54,8 +56,9 @@
* @throws IllegalStateException If the server is not in state {@link LifecycleState#PRE_INIT},
* or if the configuration has not been defined
* @throws InvalidConfigurationException
+ * @throws LifecycleEventException If an error was encountered in the lifecycle handlers for this event
*/
- void initialize() throws IllegalStateException, InvalidConfigurationException;
+ void initialize() throws IllegalStateException, InvalidConfigurationException, LifecycleEventException;
/**
* Returns the initializer to be used in initialization, or null
@@ -125,6 +128,28 @@
LifecycleState getState();
/**
+ * Registers the specified handler to fire when
+ * the server's state enters that of the specified state
+ *
+ * @param state
+ * @param handler
+ * @throws IllegalArgumentException If either the state or the handler are unspecified
+ */
+ void registerEventHandler(LifecycleState state, LifecycleEventHandler<K, T> handler) throws IllegalArgumentException;
+
+ /**
+ * Unregisters one instance of the specified event handler from firing
+ * when the server state changes to the specified state.
+ *
+ * @param state
+ * @param handler
+ * @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(LifecycleState state, LifecycleEventHandler<K, T> handler)
+ throws IllegalArgumentException;
+
+ /**
* Returns the underlying server configuration. If
* the server state is anything aside from
* {@link LifecycleState#PRE_INIT}, the configuration
More information about the jboss-cvs-commits
mailing list