Skip to content

Commit

Permalink
when in multi server mode then start each server in the background
Browse files Browse the repository at this point in the history
  • Loading branch information
chenson42 committed Nov 1, 2011
1 parent c16e93b commit cf7bd05
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 29 deletions.
Expand Up @@ -82,39 +82,39 @@ public void start() {
for (int i = 0; i < files.length; i++) {
File file = files[i];
if (file.getName().endsWith(".properties")) {
start(file.getAbsolutePath(), false);
create(file.getAbsolutePath());
}
}

if (engines != null) {
for (ISymmetricEngine engine : engines.values()) {
if (engine.isStarted()) {
engine.getJobManager().startJobs();
if (!engine.isStarted()) {
new EngineStarter(engine).start();
}
}
}

} else {
start(null, true);
ISymmetricEngine engine = create(null);
engine.start();
}
}

public ISymmetricEngine start(String propertiesFile, boolean startJobs) {
protected ISymmetricEngine create(String propertiesFile) {
ISymmetricEngine engine = null;
try {
final String filePrefix = "file:///";
if (StringUtils.isNotBlank(propertiesFile) && !propertiesFile.startsWith(filePrefix)) {
propertiesFile = filePrefix + propertiesFile;
}
engine = new StandaloneSymmetricEngine(null, propertiesFile);
engine.start(startJobs);
if (engine != null) {
engines.put(engine.getEngineName(), engine);
}
return engine;
} catch (Exception e) {
log.error(e, e);
return null;
} finally {
if (engine != null) {
engines.put(engine.getEngineName(), engine);
}
}
}

Expand Down Expand Up @@ -159,7 +159,9 @@ public ISymmetricEngine install(Properties properties) throws Exception {
}
}

return start(symmetricProperties.getAbsolutePath(), true);
ISymmetricEngine engine = create(symmetricProperties.getAbsolutePath());
engine.start();
return engine;

}

Expand Down Expand Up @@ -221,4 +223,23 @@ public String validateRequiredProperties(Properties properties) {
return engineName;
}

class EngineStarter extends Thread {

ISymmetricEngine engine;

public EngineStarter(ISymmetricEngine engine) {
super("startup-thread-" + engine.getEngineName().toLowerCase());
this.engine = engine;
}

@Override
public void run() {
if (engine != null) {
if (!engine.isStarted()) {
engine.start();
}
}
}
}

}
Expand Up @@ -51,6 +51,8 @@
* General application utility methods
*/
public class AppUtils {

private static boolean alreadyCleaned = false;

private static String UNKNOWN = "unknown";

Expand Down Expand Up @@ -196,25 +198,28 @@ public static File createTempFile(String token) throws IOException {
* called while the engine is not synchronizing!
*/
@SuppressWarnings("unchecked")
public static void cleanupTempFiles() {
try {
File tmp = File.createTempFile("temp.", "." + SYM_TEMP_SUFFIX);
Iterator<File> it = FileUtils.iterateFiles(tmp.getParentFile(),
new String[] { SYM_TEMP_SUFFIX }, true);
int deletedCount = 0;
while (it.hasNext()) {
try {
FileUtils.forceDelete(it.next());
deletedCount++;
} catch (Exception ex) {
log.error(ex.getMessage());
public synchronized static void cleanupTempFiles() {
if (!alreadyCleaned) {
alreadyCleaned = true;
try {
File tmp = File.createTempFile("temp.", "." + SYM_TEMP_SUFFIX);
Iterator<File> it = FileUtils.iterateFiles(tmp.getParentFile(),
new String[] { SYM_TEMP_SUFFIX }, true);
int deletedCount = 0;
while (it.hasNext()) {
try {
FileUtils.forceDelete(it.next());
deletedCount++;
} catch (Exception ex) {
log.error("Message", ex.getMessage());
}
}
if (deletedCount > 1) {
log.warn("CleanStrandedTempFiles", deletedCount);
}
} catch (Exception ex) {
log.error(ex);
}
if (deletedCount > 1) {
log.warn("CleanStrandedTempFiles", deletedCount);
}
} catch (Exception ex) {
log.error(ex);
}
}

Expand Down

0 comments on commit cf7bd05

Please sign in to comment.