From 8e4dbfa9da3290166da2e324e59fff2db6791ce6 Mon Sep 17 00:00:00 2001 From: chenson42 Date: Wed, 9 Jul 2008 16:18:09 +0000 Subject: [PATCH] make the constructor ofSymmetricEngine a bit nicer by using the String... notation. Also expose the SymmetricEngine for use if you have a handle on the SymmetricWebServer --- .../jumpmind/symmetric/SymmetricEngine.java | 50 ++++++++++++------- .../SymmetricEngineContextLoaderListener.java | 8 ++- .../symmetric/SymmetricWebServer.java | 12 ++++- 3 files changed, 48 insertions(+), 22 deletions(-) diff --git a/symmetric/src/main/java/org/jumpmind/symmetric/SymmetricEngine.java b/symmetric/src/main/java/org/jumpmind/symmetric/SymmetricEngine.java index f5a7421e0f..11104f3061 100644 --- a/symmetric/src/main/java/org/jumpmind/symmetric/SymmetricEngine.java +++ b/symmetric/src/main/java/org/jumpmind/symmetric/SymmetricEngine.java @@ -93,26 +93,16 @@ public class SymmetricEngine { private static Map registeredEnginesByName = new HashMap(); - /** - * @param overridePropertiesResource1 - * Provide a Spring resource path to a properties file to be - * used for configuration - * @param overridePropertiesResource2 - * Provide a Spring resource path to a properties file to be - * used for configuration - */ - public SymmetricEngine(String overridePropertiesResource1, String overridePropertiesResource2) { - // Setting system properties is probably not the best way to accomplish - // this setup. - // Synchronizing on the class so creating multiple engines is thread - // safe. - synchronized (SymmetricEngine.class) { - System.setProperty(Constants.OVERRIDE_PROPERTIES_FILE_1, overridePropertiesResource1 == null ? "" - : overridePropertiesResource1); - System.setProperty(Constants.OVERRIDE_PROPERTIES_FILE_2, overridePropertiesResource2 == null ? "" - : overridePropertiesResource2); - this.init(createContext()); + public SymmetricEngine(String... overridePropertiesResources) { + String one = null; + String two = null; + if (overridePropertiesResources.length > 0) { + one = overridePropertiesResources[0]; + if (overridePropertiesResources.length > 1) { + two = overridePropertiesResources[1]; + } } + init(one, two); } /** @@ -171,6 +161,28 @@ private ApplicationContext createContext() { return new ClassPathXmlApplicationContext("classpath:/symmetric.xml"); } + /** + * @param overridePropertiesResource1 + * Provide a Spring resource path to a properties file to be + * used for configuration + * @param overridePropertiesResource2 + * Provide a Spring resource path to a properties file to be + * used for configuration + */ + private void init(String overridePropertiesResource1, String overridePropertiesResource2) { + // Setting system properties is probably not the best way to accomplish + // this setup. + // Synchronizing on the class so creating multiple engines is thread + // safe. + synchronized (SymmetricEngine.class) { + System.setProperty(Constants.OVERRIDE_PROPERTIES_FILE_1, overridePropertiesResource1 == null ? "" + : overridePropertiesResource1); + System.setProperty(Constants.OVERRIDE_PROPERTIES_FILE_2, overridePropertiesResource2 == null ? "" + : overridePropertiesResource2); + this.init(createContext()); + } + } + private void init(ApplicationContext applicationContext) { this.applicationContext = applicationContext; bootstrapService = (IBootstrapService) applicationContext.getBean(Constants.BOOTSTRAP_SERVICE); diff --git a/symmetric/src/main/java/org/jumpmind/symmetric/SymmetricEngineContextLoaderListener.java b/symmetric/src/main/java/org/jumpmind/symmetric/SymmetricEngineContextLoaderListener.java index b3e4585e42..74d52be0b6 100644 --- a/symmetric/src/main/java/org/jumpmind/symmetric/SymmetricEngineContextLoaderListener.java +++ b/symmetric/src/main/java/org/jumpmind/symmetric/SymmetricEngineContextLoaderListener.java @@ -48,6 +48,8 @@ public class SymmetricEngineContextLoaderListener extends ContextLoaderListener static final String SYMMETRIC_SPRING_LOCATION = "classpath:/symmetric.xml"; static final Log logger = LogFactory.getLog(SymmetricEngineContextLoaderListener.class); + + SymmetricEngine engine = null; @Override final public void contextInitialized(ServletContextEvent event) { @@ -66,7 +68,7 @@ final public void contextInitialized(ServletContextEvent event) { } protected void createConfigureAndStartEngine(ApplicationContext ctx) { - SymmetricEngine engine = new SymmetricEngine(ctx); + this.engine = new SymmetricEngine(ctx); engine.start(); } @@ -102,4 +104,8 @@ protected WebApplicationContext createWebApplicationContext(ServletContext servl }; } + public SymmetricEngine getEngine() { + return engine; + } + } diff --git a/symmetric/src/main/java/org/jumpmind/symmetric/SymmetricWebServer.java b/symmetric/src/main/java/org/jumpmind/symmetric/SymmetricWebServer.java index 60f1868f35..a507da84a0 100644 --- a/symmetric/src/main/java/org/jumpmind/symmetric/SymmetricWebServer.java +++ b/symmetric/src/main/java/org/jumpmind/symmetric/SymmetricWebServer.java @@ -44,12 +44,20 @@ public class SymmetricWebServer { protected Server server; protected boolean join = true; - + public void start(int port, String propertiesUrl) throws Exception { System.setProperty(Constants.OVERRIDE_PROPERTIES_FILE_1, propertiesUrl); start(port); } - + + public SymmetricEngine getEngine() { + if (contextListener != null) { + return contextListener.getEngine(); + } else { + return null; + } + } + public void start(int port) throws Exception { server = new Server(); Connector connector = new SelectChannelConnector();