Skip to content

Commit

Permalink
SYMMETRICDS-146 - Look in CLASSPATH for file to load
Browse files Browse the repository at this point in the history
  • Loading branch information
chenson42 committed Sep 7, 2009
1 parent 921aa33 commit 72072b6
Showing 1 changed file with 31 additions and 43 deletions.
74 changes: 31 additions & 43 deletions symmetric/src/main/java/org/jumpmind/symmetric/SymmetricEngine.java
Expand Up @@ -66,20 +66,16 @@
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
* This is the preferred way to create, configure, start and manage a
* client-only instance of SymmetricDS. The engine will bootstrap the
* symmetric.xml Spring context.
* This is the preferred way to create, configure, start and manage a client-only instance of SymmetricDS. The engine
* will bootstrap the symmetric.xml Spring context.
* <p/>
* The SymmetricDS instance is configured by properties configuration files. By
* default the engine will look for and override existing properties with ones
* found in the properties files. SymmetricDS looks for: symmetric.properties in
* the classpath (it will use the first one it finds), and then for a
* symmetric.properties found in the user.home system property location. Next,
* if provided, in the constructor of the SymmetricEngine, it will locate and
* use the properties file passed to the engine.
* The SymmetricDS instance is configured by properties configuration files. By default the engine will look for and
* override existing properties with ones found in the properties files. SymmetricDS looks for: symmetric.properties in
* the classpath (it will use the first one it finds), and then for a symmetric.properties found in the user.home system
* property location. Next, if provided, in the constructor of the SymmetricEngine, it will locate and use the
* properties file passed to the engine.
* <p/>
* When the engine is ready to be started, the {@link #start()} method should be
* called. It should only be called once.
* When the engine is ready to be started, the {@link #start()} method should be called. It should only be called once.
*/
public class SymmetricEngine {

Expand All @@ -100,7 +96,7 @@ public class SymmetricEngine {
private IClusterService clusterService;

private IPurgeService purgeService;

private ITriggerRouterService triggerService;

private IDataService dataService;
Expand All @@ -124,9 +120,8 @@ public SymmetricEngine(String... overridePropertiesResources) {
}

/**
* Create a SymmetricDS instance using an existing
* {@link ApplicationContext} as the parent. This gives the SymmetricDS
* context access to beans in the parent context.
* Create a SymmetricDS instance using an existing {@link ApplicationContext} as the parent. This gives the
* SymmetricDS context access to beans in the parent context.
*
* @param parentContext
* @param overridePropertiesResources
Expand All @@ -144,16 +139,15 @@ public SymmetricEngine(ApplicationContext parentContext, String... overridePrope
}

/**
* Create a SymmetricDS node. This constructor creates a new
* {@link ApplicationContext} using SymmetricDS's classpath:/symmetric.xml.
* Create a SymmetricDS node. This constructor creates a new {@link ApplicationContext} using SymmetricDS's
* classpath:/symmetric.xml.
*/
public SymmetricEngine() {
init(createContext(null));
}

/**
* Pass in the {@link ApplicationContext} to be used. The context passed in
* needs to load classpath:/symmetric.xml.
* Pass in the {@link ApplicationContext} to be used. The context passed in needs to load classpath:/symmetric.xml.
*
* @param ctx
* A Spring framework context to use for this SymmetricEngine
Expand Down Expand Up @@ -205,11 +199,9 @@ private ApplicationContext createContext(ApplicationContext parentContext) {

/**
* @param overridePropertiesResource1
* Provide a Spring resource path to a properties file to be used
* for configuration
* 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
* Provide a Spring resource path to a properties file to be used for configuration
*/
private void init(ApplicationContext parentContext, String overridePropertiesResource1,
String overridePropertiesResource2) {
Expand Down Expand Up @@ -242,8 +234,7 @@ private void init(ApplicationContext applicationContext) {
}

/**
* Register this instance of the engine so it can be found by other
* processes in the JVM.
* Register this instance of the engine so it can be found by other processes in the JVM.
*
* @see #findEngineByUrl(String)
*/
Expand All @@ -265,8 +256,8 @@ public String getMyUrl() {
}

/**
* This is done dynamically because some application servers do not allow
* the default MBeanServer to be accessed for security reasons (OC4J).
* This is done dynamically because some application servers do not allow the default MBeanServer to be accessed for
* security reasons (OC4J).
*/
private void startDefaultServerJMXExport() {
if (parameterService.is(ParameterConstants.JMX_LEGACY_BEANS_ENABLED)) {
Expand All @@ -288,19 +279,16 @@ public Properties getProperties() {
}

/**
* @return The lower case representation of the engine name as setup in the
* symmetric.properties file. We always use a lower case
* representation because there are times the engine name is used in
* triggers at which point you can lose the original case
* representation.
* @return The lower case representation of the engine name as setup in the symmetric.properties file. We always use
* a lower case representation because there are times the engine name is used in triggers at which point
* you can lose the original case representation.
*/
public String getEngineName() {
return dbDialect.getEngineName();
}

/**
* Will setup the SymmetricDS tables, if not already setup and if the engine
* is configured to do so.
* Will setup the SymmetricDS tables, if not already setup and if the engine is configured to do so.
*/
public synchronized void setup() {
if (!setup) {
Expand Down Expand Up @@ -389,8 +377,7 @@ public boolean pull() {
}

/**
* This can be called to do a purge. It may be called only if the
* {@link PurgeJob} has not been enabled.
* This can be called to do a purge. It may be called only if the {@link PurgeJob} has not been enabled.
*
* @see IPurgeService#purge()
*/
Expand Down Expand Up @@ -430,8 +417,7 @@ protected void setupDatabase(boolean force) {
}

/**
* Simply check and make sure that this node is all configured properly for
* operation.
* Simply check and make sure that this node is all configured properly for operation.
*/
public void validateConfiguration() {
Node node = nodeService.findIdentity();
Expand Down Expand Up @@ -491,8 +477,8 @@ private boolean buildTablesFromDdlUtilXmlIfProvided() {
}

/**
* Give the end user the option to provide a script that will load a
* registration server with an initial SymmetricDS setup.
* Give the end user the option to provide a script that will load a registration server with an initial SymmetricDS
* setup.
*
* Look first on the file system, then in the classpath for the SQL file.
*
Expand All @@ -512,6 +498,9 @@ private boolean loadFromScriptIfProvided() {
}
} else {
fileUrl = getClass().getResource(sqlScript);
if (fileUrl == null) {
fileUrl = Thread.currentThread().getContextClassLoader().getResource(sqlScript);
}
}

if (fileUrl != null) {
Expand All @@ -524,8 +513,7 @@ private boolean loadFromScriptIfProvided() {
}

/**
* Push a copy of the node onto the push queue so the SymmetricDS node
* 'checks' in with it's root node.
* Push a copy of the node onto the push queue so the SymmetricDS node 'checks' in with it's root node.
*
* @see IconfigurationService#heartbeat()
*/
Expand Down

0 comments on commit 72072b6

Please sign in to comment.