mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
#283 - SPI change: Rename BootupEbeanManager to SpiContainer ... with a view to future exposing cluster specific methods
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
package com.avaje.ebean;
|
||||
|
||||
import com.avaje.ebean.common.BootupEbeanManager;
|
||||
import com.avaje.ebean.common.SpiContainer;
|
||||
import com.avaje.ebean.config.ContainerConfig;
|
||||
import com.avaje.ebean.config.ServerConfig;
|
||||
|
||||
@@ -29,7 +29,9 @@ import java.util.Properties;
|
||||
public class EbeanServerFactory {
|
||||
|
||||
|
||||
private static BootupEbeanManager bootupEbeanManager;
|
||||
private static final String DEFAULT_CONTAINER = "com.avaje.ebeaninternal.server.core.DefaultContainer";
|
||||
|
||||
private static SpiContainer container;
|
||||
|
||||
/**
|
||||
* Initialise the container with clustering configuration.
|
||||
@@ -38,7 +40,7 @@ public class EbeanServerFactory {
|
||||
* ContainerConfig on the ServerConfig when creating the first EbeanServer instance.
|
||||
*/
|
||||
public static synchronized void initialiseContainer(ContainerConfig containerConfig) {
|
||||
getServerFactory(containerConfig);
|
||||
getContainer(containerConfig);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -48,7 +50,7 @@ public class EbeanServerFactory {
|
||||
|
||||
// construct based on loading properties files
|
||||
// and if invoked by Ebean then it handles registration
|
||||
BootupEbeanManager serverFactory = getServerFactory(null);
|
||||
SpiContainer serverFactory = getContainer(null);
|
||||
return serverFactory.createServer(name);
|
||||
}
|
||||
|
||||
@@ -76,18 +78,19 @@ public class EbeanServerFactory {
|
||||
|
||||
private static EbeanServer createInternal(ServerConfig config) {
|
||||
|
||||
return getServerFactory(config.getContainerConfig()).createServer(config);
|
||||
return getContainer(config.getContainerConfig()).createServer(config);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the BootupEbeanManager initialising it if necessary.
|
||||
* Get the EbeanContainer initialising it if necessary.
|
||||
*
|
||||
* @param containerConfig the configuration controlling clustering communication
|
||||
*/
|
||||
private static BootupEbeanManager getServerFactory(ContainerConfig containerConfig) {
|
||||
private static SpiContainer getContainer(ContainerConfig containerConfig) {
|
||||
|
||||
if (bootupEbeanManager != null) {
|
||||
return bootupEbeanManager;
|
||||
// thread safe in that all calling methods are synchronized
|
||||
if (container != null) {
|
||||
return container;
|
||||
}
|
||||
|
||||
if (containerConfig == null) {
|
||||
@@ -96,22 +99,21 @@ public class EbeanServerFactory {
|
||||
containerConfig = new ContainerConfig();
|
||||
containerConfig.loadFromProperties(properties);
|
||||
}
|
||||
bootupEbeanManager = createServerFactory(containerConfig);
|
||||
return bootupEbeanManager;
|
||||
container = createContainer(containerConfig);
|
||||
return container;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the container instance using the configuration.
|
||||
*/
|
||||
private static BootupEbeanManager createServerFactory(ContainerConfig containerConfig) {
|
||||
private static SpiContainer createContainer(ContainerConfig containerConfig) {
|
||||
|
||||
String dflt = "com.avaje.ebeaninternal.server.core.DefaultServerFactory";
|
||||
String implClassName = System.getProperty("ebean.serverfactory", dflt);
|
||||
String implClassName = System.getProperty("ebean.container", DEFAULT_CONTAINER);
|
||||
|
||||
try {
|
||||
Class<?> cls = Class.forName(implClassName);
|
||||
Constructor<?> constructor = cls.getConstructor(ContainerConfig.class);
|
||||
return (BootupEbeanManager) constructor.newInstance(containerConfig);
|
||||
return (SpiContainer) constructor.newInstance(containerConfig);
|
||||
} catch (Exception ex) {
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
|
||||
@@ -1,38 +0,0 @@
|
||||
package com.avaje.ebean.common;
|
||||
|
||||
import com.avaje.ebean.EbeanServer;
|
||||
import com.avaje.ebean.config.ServerConfig;
|
||||
|
||||
/**
|
||||
* Creates the EbeanServer implementations. This is used by the Ebean singleton
|
||||
* to determine the implementation for each server name.
|
||||
* <p>
|
||||
* Note that on a remote client it is expected that this factory will return
|
||||
* EbeanServers that behave as a proxy using http or tcp sockets etc to talk to
|
||||
* the EbeanServer on the application server.
|
||||
* </p>
|
||||
*/
|
||||
public interface BootupEbeanManager {
|
||||
|
||||
/**
|
||||
* Create the EbeanServer for a given configuration.
|
||||
*
|
||||
* @param configuration
|
||||
* The configuration information for this server.
|
||||
*/
|
||||
public EbeanServer createServer(ServerConfig configuration);
|
||||
|
||||
/**
|
||||
* Create an EbeanServer just using the name.
|
||||
* <p>
|
||||
* In this case the dataSource parameters etc will be defined on the global
|
||||
* avaje.properties file.
|
||||
* </p>
|
||||
*/
|
||||
public EbeanServer createServer(String name);
|
||||
|
||||
/**
|
||||
* Shutdown any Ebean wide resources such as clustering.
|
||||
*/
|
||||
public void shutdown();
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package com.avaje.ebean.common;
|
||||
|
||||
import com.avaje.ebean.EbeanServer;
|
||||
import com.avaje.ebean.config.ServerConfig;
|
||||
|
||||
/**
|
||||
* Creates the EbeanServer implementations. This is used internally by the EbeanServerFactory and is not currently
|
||||
* exposed as public API.
|
||||
*/
|
||||
public interface SpiContainer {
|
||||
|
||||
/**
|
||||
* Create the EbeanServer for a given configuration.
|
||||
*
|
||||
* @param configuration
|
||||
* The configuration information for this server.
|
||||
*/
|
||||
EbeanServer createServer(ServerConfig configuration);
|
||||
|
||||
/**
|
||||
* Create an EbeanServer just using the name.
|
||||
* <p>
|
||||
* In this case the dataSource parameters etc will be defined on the global
|
||||
* avaje.properties file.
|
||||
* </p>
|
||||
*/
|
||||
EbeanServer createServer(String name);
|
||||
|
||||
/**
|
||||
* Shutdown any Ebean wide resources such as clustering.
|
||||
*/
|
||||
void shutdown();
|
||||
}
|
||||
+5
-5
@@ -18,7 +18,7 @@ import com.avaje.ebean.EbeanServer;
|
||||
import com.avaje.ebean.cache.ServerCacheFactory;
|
||||
import com.avaje.ebean.cache.ServerCacheManager;
|
||||
import com.avaje.ebean.cache.ServerCacheOptions;
|
||||
import com.avaje.ebean.common.BootupEbeanManager;
|
||||
import com.avaje.ebean.common.SpiContainer;
|
||||
import com.avaje.ebean.config.dbplatform.DatabasePlatform;
|
||||
import com.avaje.ebeaninternal.api.SpiBackgroundExecutor;
|
||||
import com.avaje.ebeaninternal.api.SpiEbeanServer;
|
||||
@@ -35,9 +35,9 @@ import com.avaje.ebeaninternal.server.lib.sql.SimpleDataSourceAlert;
|
||||
/**
|
||||
* Default Server side implementation of ServerFactory.
|
||||
*/
|
||||
public class DefaultServerFactory implements BootupEbeanManager {
|
||||
public class DefaultContainer implements SpiContainer {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(DefaultServerFactory.class);
|
||||
private static final Logger logger = LoggerFactory.getLogger(DefaultContainer.class);
|
||||
|
||||
private final ClusterManager clusterManager;
|
||||
|
||||
@@ -45,14 +45,14 @@ public class DefaultServerFactory implements BootupEbeanManager {
|
||||
|
||||
private final AtomicInteger serverId = new AtomicInteger(1);
|
||||
|
||||
public DefaultServerFactory(ContainerConfig containerConfig) {
|
||||
public DefaultContainer(ContainerConfig containerConfig) {
|
||||
|
||||
this.clusterManager = new ClusterManager(containerConfig);
|
||||
this.jndiDataSourceFactory = new JndiDataSourceLookup();
|
||||
|
||||
// register so that we can shutdown any Ebean wide
|
||||
// resources such as clustering
|
||||
ShutdownManager.registerServerFactory(this);
|
||||
ShutdownManager.registerContainer(this);
|
||||
}
|
||||
|
||||
public void shutdown() {
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.avaje.ebeaninternal.server.lib;
|
||||
|
||||
import com.avaje.ebean.common.BootupEbeanManager;
|
||||
import com.avaje.ebean.common.SpiContainer;
|
||||
import com.avaje.ebeaninternal.api.ClassUtil;
|
||||
import com.avaje.ebeaninternal.api.SpiEbeanServer;
|
||||
import org.slf4j.Logger;
|
||||
@@ -29,7 +29,7 @@ public final class ShutdownManager {
|
||||
|
||||
static boolean stopping;
|
||||
|
||||
static BootupEbeanManager serverFactory;
|
||||
static SpiContainer container;
|
||||
|
||||
static {
|
||||
// Register the Shutdown hook
|
||||
@@ -42,8 +42,8 @@ public final class ShutdownManager {
|
||||
private ShutdownManager() {
|
||||
}
|
||||
|
||||
public static void registerServerFactory(BootupEbeanManager factory){
|
||||
serverFactory = factory;
|
||||
public static void registerContainer(SpiContainer ebeanContainer){
|
||||
container = ebeanContainer;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -128,9 +128,9 @@ public final class ShutdownManager {
|
||||
}
|
||||
}
|
||||
|
||||
if (serverFactory != null) {
|
||||
if (container != null) {
|
||||
// shutdown cluster networking if active
|
||||
serverFactory.shutdown();
|
||||
container.shutdown();
|
||||
}
|
||||
|
||||
// shutdown any registered servers that have not
|
||||
|
||||
Reference in New Issue
Block a user