summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLudovic Pouzenc <ludovic@pouzenc.fr>2014-10-23 12:20:27 +0200
committerLudovic Pouzenc <ludovic@pouzenc.fr>2015-04-14 07:44:58 +0200
commit2ee579091065829b027c74f14f0442a97da7d797 (patch)
tree6da3be478e59409f71dda3b6a6fef1ef368141f2 /src
parentd6f22a2af48f83d63b5381118d2029797458194e (diff)
downloadsssync-2ee579091065829b027c74f14f0442a97da7d797.tar.gz
sssync-2ee579091065829b027c74f14f0442a97da7d797.tar.bz2
sssync-2ee579091065829b027c74f14f0442a97da7d797.zip
Use Abstraction for SyncTasks and add some cosmetics/docs
Diffstat (limited to 'src')
-rw-r--r--src/main/src/SSSync.java37
1 files 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<BasicSyncTask> tasks = null;
+ List<AbstractSyncTask> 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<BasicSyncTask> list, long timeOutInMinute, boolean dryRun) {
+ private static boolean safeTaskRun(List<AbstractSyncTask> tasks, long timeOutInMinute, boolean dryRun) {
ExecutorService executor = Executors.newSingleThreadExecutor();
List<Future<Boolean>> 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<Boolean> r: results) {
if ( ! r.get() ) {