From 2ee579091065829b027c74f14f0442a97da7d797 Mon Sep 17 00:00:00 2001 From: Ludovic Pouzenc Date: Thu, 23 Oct 2014 12:20:27 +0200 Subject: Use Abstraction for SyncTasks and add some cosmetics/docs --- src/main/src/SSSync.java | 37 +++++++++++++++++++------------------ 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/src/main/src/SSSync.java b/src/main/src/SSSync.java index 422c31e..fbf41cb 100644 --- a/src/main/src/SSSync.java +++ b/src/main/src/SSSync.java @@ -35,11 +35,11 @@ import conf.ConfigConnectionsBean; import conf.ConfigGlobalsBean; import conf.ConfigRootBean; import conf.SSSyncConfParser; -import conf.SSSyncConnectionsFactory; -import conf.SSSyncTasksFactory; import data.io.ConnectionsHolder; +import data.io.SSSyncConnectionsFactory; -import sync.BasicSyncTask; +import sync.AbstractSyncTask; +import sync.SSSyncTasksFactory; import utils.JVMStatsDumper; /** @@ -50,9 +50,10 @@ import utils.JVMStatsDumper; public class SSSync { private static final Logger logger = Logger.getLogger(SSSync.class.getName()); - private static final String LOG_PROPERTIES_FILE = "conf/log4j.properties"; - private static final String CONFIG_MAIN_FILE = "conf/sssync.yaml"; - private static final String CONFIG_CONN_FILE = "conf/connections.yaml"; + //XXX migrate to SLF4J ? + private static final String LOG_PROPERTIES_FILE = "./conf/log4j.properties"; + private static final String DEFAULT_CONFIG_MAIN_FILE = "./conf/sssync.yaml"; + private static final String DEFAULT_CONFIG_CONN_FILE = "./conf/connections.yaml"; private static final int ERR_SUCCESS = 0; private static final int ERR_CONFIG_PARSE_ERROR = 1; @@ -68,6 +69,7 @@ public class SSSync { * * @param args */ + /* No OO-style here, only plain old static sequences using local vars */ public static void main(String[] args) { // log4j setup (first thing to do) PropertyConfigurator.configure(LOG_PROPERTIES_FILE); @@ -75,8 +77,8 @@ public class SSSync { "', cwd: '" + System.getProperty("user.dir") + "')"); //TODO use cmdline args for config file path - String mainConfigFile = CONFIG_MAIN_FILE; - String connConfigFile = CONFIG_CONN_FILE; + String mainConfigFile = DEFAULT_CONFIG_MAIN_FILE; + String connConfigFile = DEFAULT_CONFIG_CONN_FILE; // Config parsing ConfigRootBean confMain = null; @@ -107,6 +109,7 @@ public class SSSync { } // Suggest garbage collector to forget our passwords since we are connected + ///XXX If YaML parser is OK with a mutable String type, overwrite maybe is a good idea confConn=null; System.gc(); JVMStatsDumper.logMemoryUsage(); @@ -114,7 +117,7 @@ public class SSSync { // Tasks init logger.info("Tasks initialization"); - List tasks = null; + List tasks = null; try { tasks = SSSyncTasksFactory.setupTasks(connections, confMain); } catch (Exception e) { @@ -151,27 +154,25 @@ public class SSSync { /** * Method to run safely a sequence of tasks within a given time period. - * In a separate thread, it runs all the tasks sequentially. + * Uses a separate thread, runs all tasks sequentially. * - * @param list - * @param timeOutInMinute - * @return - * @throws ExecutionException - * @throws InterruptedException + * @param tasks : The list of tasks to run + * @param timeOutInMinute : Max execution time of the whole sequence of tasks + * @return true if the task has ran successfully, false otherwise */ - private static boolean safeTaskRun(List list, long timeOutInMinute, boolean dryRun) { + private static boolean safeTaskRun(List tasks, long timeOutInMinute, boolean dryRun) { ExecutorService executor = Executors.newSingleThreadExecutor(); List> results; boolean aborted = false; logger.info("Starting " + (dryRun?"dry-run":"real-run") + " synchronization pass"); - for ( BasicSyncTask t : list ) { + for ( AbstractSyncTask t : tasks ) { t.setDryRun(dryRun); } try { - results = executor.invokeAll(list, timeOutInMinute, TimeUnit.MINUTES); + results = executor.invokeAll(tasks, timeOutInMinute, TimeUnit.MINUTES); // Join all tasks, seeking for an unsuccessful execution for (Future r: results) { if ( ! r.get() ) { -- cgit v1.2.3