#394 - ENH: Add plugin API SpiServer - add shutdown() method to SpiServerPlugin.

This commit is contained in:
Robin Bygrave
2015-08-25 11:52:58 +12:00
parent efad23d482
commit c79231c846
2 changed files with 21 additions and 1 deletions
@@ -14,4 +14,12 @@ public interface SpiServerPlugin {
* Called just before the server starts indicating if it is coming up in online mode.
*/
void online(boolean online);
/**
* Called when the server is shutting down.
* <p>
* Plugins should shutdown any resources they are using cleanly.
* </p>
*/
void shutdown();
}
@@ -438,6 +438,7 @@ public final class DefaultServer implements SpiServer, SpiEbeanServer {
// Already shutdown
return;
}
shutdownPlugins();
try {
if (mbeanServer != null) {
mbeanServer.unregisterMBean(new ObjectName(mbeanName + ",key=AutoFetch"));
@@ -454,7 +455,18 @@ public final class DefaultServer implements SpiServer, SpiEbeanServer {
transactionManager.shutdown(shutdownDataSource, deregisterDriver);
shutdown = true;
}
private void shutdownPlugins() {
for (SpiServerPlugin plugin : serverPlugins) {
try {
plugin.shutdown();
} catch (Throwable e) {
logger.error("Error when shutting down plugin", e);
}
}
}
/**
* Return the server name.
*/