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 8636440c05c1d3d2fede0057a58b21582e29a0c9 Author: servantie <servantie.c@gmail.com> Date: Fri Jun 3 17:24:03 2016 +0200 minor typos corrected, set autosyncdelay to every two hours --- src/main/java/org/chorem/jtimer/JTimerConfig.java | 2 +- .../chorem/jtimer/io/TimerTaskSynchronizer.java | 129 +++++++++++---------- 2 files changed, 70 insertions(+), 61 deletions(-) diff --git a/src/main/java/org/chorem/jtimer/JTimerConfig.java b/src/main/java/org/chorem/jtimer/JTimerConfig.java index 499eac9..5d52f63 100644 --- a/src/main/java/org/chorem/jtimer/JTimerConfig.java +++ b/src/main/java/org/chorem/jtimer/JTimerConfig.java @@ -293,7 +293,7 @@ public class JTimerConfig { IO_SAVER_AUTOSAVEDELAY("jtimer.io.saver.autosavedelay", "300"), IO_SYNC_CLASS("jtimer.io.synchronizer.class", "org.chorem.jtimer.io.TimerTaskSynchronizer"), - IO_SYNC_AUTOSYNCDELAY("jtimer.io.synchronizer.autosyncdelay", "10"), + IO_SYNC_AUTOSYNCDELAY("jtimer.io.synchronizer.autosyncdelay", "3600"), UI_IDLE_TIME("jtimer.ui.idletime", "300"), UI_SHOW_CLOSED("jtimer.ui.showclosed", "false"), diff --git a/src/main/java/org/chorem/jtimer/io/TimerTaskSynchronizer.java b/src/main/java/org/chorem/jtimer/io/TimerTaskSynchronizer.java index 6cabf41..a15f05f 100644 --- a/src/main/java/org/chorem/jtimer/io/TimerTaskSynchronizer.java +++ b/src/main/java/org/chorem/jtimer/io/TimerTaskSynchronizer.java @@ -26,7 +26,7 @@ public class TimerTaskSynchronizer implements DataEventListener { private static Log log = LogFactory.getLog(TimerTaskSynchronizer.class); /** auto sync delay */ - protected long autoSyncDelay = 1000 * 10 ; //every 2 hours, check for modifications to sync + protected long autoSyncDelay = 1000 * 60 * 60 * 2 ; //every 2 hours, check for modifications to sync /** timer to schedule syncs */ protected Timer timer; @@ -103,66 +103,68 @@ public class TimerTaskSynchronizer implements DataEventListener { */ public boolean synchronizeSingleTask(TimerTask task) { String updateJsonString = TimerTaskHelper.taskToJSONFormat(task, false).toString(); - String syncURl = task.getSynchronisingURL(); + String syncURL = task.getSynchronisingURL(); String charset = "UTF-8"; HttpURLConnection connection = null; URL url = null; - try { - url = new URL(syncURl); - } catch (MalformedURLException e) { - e.printStackTrace(); - //abort synchronization of this task if the url is wrong - return false; - } - try { - connection = (HttpURLConnection) url.openConnection(); - } catch (IOException e) { - e.printStackTrace(); - //abort synchronization of this task if connection impossible - return false; - } - 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"); - } catch (UnsupportedEncodingException e) { - e.printStackTrace(); - } - try { - connection.getOutputStream().write(postDataBytes); - } catch (IOException e) { - e.printStackTrace(); - } - //get the header fields - Map<String, List<String>> map = connection.getHeaderFields(); - boolean hasUpdated = false; - //check for answer from server - for (Map.Entry<String, List<String>> entry : map.entrySet()) { - for (String s : entry.getValue()) { - //positive answer, synchronization accepted - if (s.equals("HTTP/1.1 200 OK")) { - hasUpdated = true; + if (syncURL != null) { + try { + url = new URL(syncURL); + } catch (MalformedURLException e) { + e.printStackTrace(); + //abort synchronization of this task if the url is wrong + return false; + } + try { + connection = (HttpURLConnection) url.openConnection(); + } catch (IOException e) { + e.printStackTrace(); + //abort synchronization of this task if connection impossible + return false; + } + 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"); + } catch (UnsupportedEncodingException e) { + e.printStackTrace(); + } + try { + connection.getOutputStream().write(postDataBytes); + } catch (IOException e) { + e.printStackTrace(); + } + //get the header fields + Map<String, List<String>> map = connection.getHeaderFields(); + boolean hasUpdated = false; + //check for answer from server + for (Map.Entry<String, List<String>> entry : map.entrySet()) { + for (String s : entry.getValue()) { + //positive answer, synchronization accepted + if (s.equals("HTTP/1.1 200 OK")) { + hasUpdated = true; + } } } + if (hasUpdated) { + task.setLastSync(LocalDateTime.now()); + return true; + } else { + log.error("Sync error"); + return false; + } } - if (hasUpdated) { - task.setLastSync(LocalDateTime.now()); - return true; - } - else { - log.error("Sync error"); - return false; - } + return false; } @Override @@ -185,9 +187,12 @@ public class TimerTaskSynchronizer implements DataEventListener { */ @Override public void modifyTask(TimerTask task) { - //when a task is modified, add it to the to sync list (if it isn't already there= + //when a task is modified, add it to the to sync list (if it isn't already there) if(!tasksToSync.contains(task)) { + //add it only if the URL is not empty + if (!(task.getSynchronisingURL().isEmpty())) { tasksToSync.add(task); + } } } @@ -250,8 +255,10 @@ public class TimerTaskSynchronizer implements DataEventListener { @Override public void stopTask(TimerTask task) { if(!tasksToSync.contains(task)) { + //add it only if the URL is not empty + if (!(task.getSynchronisingURL().isEmpty())) { tasksToSync.add(task); - } + } } } @Override @@ -266,9 +273,11 @@ public class TimerTaskSynchronizer implements DataEventListener { */ @Override public void modifyTaskURL(TimerTask task, String newURL) { - if(!tasksToSync.contains(task) && (!task.getSynchronisingURL().equals(null))) { - tasksToSync.add(task); - } + if(!tasksToSync.contains(task)) { + //add it only if the URL is not empty + if (!(task.getSynchronisingURL().isEmpty())) { + tasksToSync.add(task); + } } } @Override -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.