Skip to content

Commit

Permalink
make the constructor ofSymmetricEngine a bit nicer by using the Strin…
Browse files Browse the repository at this point in the history
…g... notation. Also expose the SymmetricEngine for use if you have a handle on the SymmetricWebServer
  • Loading branch information
chenson42 committed Jul 9, 2008
1 parent 8ba1091 commit 8e4dbfa
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 22 deletions.
50 changes: 31 additions & 19 deletions symmetric/src/main/java/org/jumpmind/symmetric/SymmetricEngine.java
Expand Up @@ -93,26 +93,16 @@ public class SymmetricEngine {

private static Map<String, SymmetricEngine> registeredEnginesByName = new HashMap<String, SymmetricEngine>();

/**
* @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);
}

/**
Expand Down Expand Up @@ -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);
Expand Down
Expand Up @@ -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) {
Expand All @@ -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();
}

Expand Down Expand Up @@ -102,4 +104,8 @@ protected WebApplicationContext createWebApplicationContext(ServletContext servl
};
}

public SymmetricEngine getEngine() {
return engine;
}

}
Expand Up @@ -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();
Expand Down

0 comments on commit 8e4dbfa

Please sign in to comment.