17/75: minor changes (comments)
This is an automated email from the git hooks/post-receive script. New commit to branch feature/sync in repository jtimer. See https://gitlab.nuiton.org/chorem/jtimer.git commit d41d0e1d706fee32c91c73f7778186bc5bb0e99a Author: servantie <servantie.c@gmail.com> Date: Thu Jun 2 17:44:41 2016 +0200 minor changes (comments) --- .../chorem/jtimer/io/TimerTaskSynchronizer.java | 100 ++++++++++++--------- 1 file changed, 56 insertions(+), 44 deletions(-) diff --git a/src/main/java/org/chorem/jtimer/io/TimerTaskSynchronizer.java b/src/main/java/org/chorem/jtimer/io/TimerTaskSynchronizer.java index d254548..05e716a 100644 --- a/src/main/java/org/chorem/jtimer/io/TimerTaskSynchronizer.java +++ b/src/main/java/org/chorem/jtimer/io/TimerTaskSynchronizer.java @@ -28,7 +28,6 @@ public class TimerTaskSynchronizer implements DataEventListener { /** auto sync delay */ protected int autoSyncDelay = 1000 * 60; //1min for testing purposes - /** timer to schedule syncs */ protected Timer timer; @@ -38,7 +37,6 @@ public class TimerTaskSynchronizer implements DataEventListener { /** Tasks to sync */ protected Collection<TimerTask> tasksToSync; - public TimerTaskSynchronizer(TimerCore core) { timer = new Timer(); @@ -47,17 +45,24 @@ public class TimerTaskSynchronizer implements DataEventListener { this.core = core; - tasksToSync = Collections.synchronizedCollection(new ArrayList<>()); } - + /** + * Change the autosync delay + * @param autoSyncDelay + */ public void setAutoSyncDelay(int autoSyncDelay) { if (autoSyncDelay>0) { this.autoSyncDelay = autoSyncDelay; } } + + /** + * Inner Task class to make the automatic sync + */ protected class UpdateTask extends java.util.TimerTask { + public void run() { if (log.isDebugEnabled()) { log.debug("Synchronizer wake up"); @@ -65,7 +70,9 @@ public class TimerTaskSynchronizer implements DataEventListener { synchronizeTasks(); } - + /** + * synchronizes Tasks in remainingTasks + */ public void synchronizeTasks(){ synchronized (tasksToSync) { @@ -95,33 +102,33 @@ public class TimerTaskSynchronizer implements DataEventListener { * * @param task */ - public boolean synchronizeSingleTask(TimerTask task){ - String updateJsonString = TimerTaskHelper.taskToJSONFormat(task, false).toString(); - String syncURl = task.getSynchronisingURL(); - String charset = "UTF-8"; - HttpURLConnection connection = null; - URL url = null; - try { - url = new URL("http://" + syncURl); - } catch (MalformedURLException e) { - e.printStackTrace(); - } - try { - connection = (HttpURLConnection) url.openConnection(); - } catch (IOException e) { - e.printStackTrace(); - } - connection.setUseCaches(false); - connection.setDoInput(true); - connection.setDoOutput(true); - connection.setRequestProperty("Content-Length", "" + updateJsonString.length()); - connection.setRequestProperty("Accept-Charset", charset); - connection.setRequestProperty("Content-Type", "application/json"); - try { - connection.setRequestMethod("POST"); - } catch (ProtocolException e) { - e.printStackTrace(); - } + public boolean synchronizeSingleTask(TimerTask task) { + String updateJsonString = TimerTaskHelper.taskToJSONFormat(task, false).toString(); + String syncURl = task.getSynchronisingURL(); + String charset = "UTF-8"; + HttpURLConnection connection = null; + URL url = null; + try { + url = new URL("http://" + syncURl); + } catch (MalformedURLException e) { + e.printStackTrace(); + } + try { + connection = (HttpURLConnection) url.openConnection(); + } catch (IOException e) { + e.printStackTrace(); + } + connection.setUseCaches(false); + connection.setDoInput(true); + connection.setDoOutput(true); + connection.setRequestProperty("Content-Length", "" + updateJsonString.length()); + connection.setRequestProperty("Accept-Charset", charset); + connection.setRequestProperty("Content-Type", "application/json"); + try { + connection.setRequestMethod("POST"); + } catch (ProtocolException e) { + e.printStackTrace(); + } byte[] postDataBytes = new byte[0]; try { postDataBytes = updateJsonString.toString().getBytes("UTF-8"); @@ -133,7 +140,6 @@ public class TimerTaskSynchronizer implements DataEventListener { } catch (IOException e) { e.printStackTrace(); } - //get the header fields Map<String, List<String>> map = connection.getHeaderFields(); boolean hasUpdated = false; @@ -148,21 +154,13 @@ public class TimerTaskSynchronizer implements DataEventListener { if (hasUpdated) { task.setLastSync(LocalDateTime.now()); return true; - } else { log.error("Sync error, wrong URL?"); return false; - } - - } - - - - @Override public void addProject(TimerProject project) { @@ -177,6 +175,10 @@ public class TimerTaskSynchronizer implements DataEventListener { } + /** + * Tasks are added to synchronization list when modified + * @param task modified task + */ @Override public void modifyTask(TimerTask task) { //when a task is modified, add it to the to sync list (if it isn't already there= @@ -189,12 +191,14 @@ public class TimerTaskSynchronizer implements DataEventListener { public void deleteProject(TimerProject project) { } - + /** + * Tasks deleted are modified from synchronization list if they exist in it + * @param task modified task + */ @Override public void deleteTask(TimerTask task) { if (tasksToSync.contains(task)) { tasksToSync.remove(task); - } } @@ -235,7 +239,10 @@ public class TimerTaskSynchronizer implements DataEventListener { @Override public void startTask(TimerTask task) { } - + /** + * Tasks are added to synchronization list when stopped + * @param task modified task + */ @Override public void stopTask(TimerTask task) { if(!tasksToSync.contains(task)) { @@ -248,6 +255,11 @@ public class TimerTaskSynchronizer implements DataEventListener { } + /** + * Tasks are added to synchronization list when the URL is updated + * + * @param task modified task + */ @Override public void modifyTaskURL(TimerTask task, String newURL) { if(!tasksToSync.contains(task) && (!task.getSynchronisingURL().equals(null))) { -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.
participants (1)
-
chorem.org scm