Refactor EbeanServerFactory internals - use SpiContainerShutdown interface for container shutdown mechanism

This commit is contained in:
rob bygrave
2017-10-05 00:57:40 +13:00
parent 0bf4c84bc8
commit 3471f6d206
5 changed files with 34 additions and 4 deletions
@@ -3,11 +3,12 @@ package io.ebean;
import io.ebean.common.SpiContainer;
import io.ebean.config.ContainerConfig;
import io.ebean.config.ServerConfig;
import io.ebeaninternal.server.lib.ShutdownManager;
import io.ebean.service.SpiContainerShutdown;
import javax.persistence.PersistenceException;
import java.lang.reflect.Constructor;
import java.util.Properties;
import java.util.ServiceLoader;
/**
* Creates EbeanServer instances.
@@ -99,7 +100,9 @@ public class EbeanServerFactory {
* </p>
*/
public static synchronized void shutdown() {
ShutdownManager.shutdown();
for (SpiContainerShutdown shutdown : ServiceLoader.load(SpiContainerShutdown.class)) {
shutdown.shutdown();
}
}
@@ -0,0 +1,12 @@
package io.ebean.service;
/**
* Provides shutdown of the entire container.
*/
public interface SpiContainerShutdown {
/**
* Shutdown the entire container - all EbeanServer instances.
*/
void shutdown();
}
@@ -0,0 +1,14 @@
package io.ebeaninternal.server.lib;
import io.ebean.service.SpiContainerShutdown;
/**
* Default container shutdown implementation.
*/
public class DContainerShutdown implements SpiContainerShutdown {
@Override
public void shutdown() {
ShutdownManager.shutdown();
}
}