From dd017897147dae1c7ed49da0670840df7eec38cf Mon Sep 17 00:00:00 2001 From: Samuel Githengi Date: Wed, 21 Feb 2018 17:23:30 +0300 Subject: [PATCH] Fix issue of duplicate server versions Signed-off-by: Samuel Githengi --- .../opensrp/service/formSubmission/EventsListener.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/opensrp-core/src/main/java/org/opensrp/service/formSubmission/EventsListener.java b/opensrp-core/src/main/java/org/opensrp/service/formSubmission/EventsListener.java index 6c0c4f459e..b41d211b4b 100644 --- a/opensrp-core/src/main/java/org/opensrp/service/formSubmission/EventsListener.java +++ b/opensrp-core/src/main/java/org/opensrp/service/formSubmission/EventsListener.java @@ -117,20 +117,22 @@ public void processEvent() { } } - private void addServerVersion() { + private synchronized void addServerVersion() { try { List clients = allClients.findByEmptyServerVersion(); + long currentTimeMillis = getCurrentMilliseconds(); while (clients != null && !clients.isEmpty()) { for (Client client : clients) { try { Thread.sleep(1); - client.setServerVersion(getCurrentMilliseconds()); + client.setServerVersion(currentTimeMillis); allClients.update(client); logger.debug("Add server_version: found new client " + client.getBaseEntityId()); } catch (InterruptedException e) { logger.error("", e); } + currentTimeMillis += 1; } clients = allClients.findByEmptyServerVersion(); } @@ -141,7 +143,7 @@ private void addServerVersion() { try { Thread.sleep(1); event = eventService.processOutOfArea(event); - event.setServerVersion(getCurrentMilliseconds()); + event.setServerVersion(currentTimeMillis); allEvents.update(event); logger.debug("Add server_version: found new event " + event.getBaseEntityId()); @@ -149,6 +151,7 @@ private void addServerVersion() { catch (InterruptedException e) { logger.error("", e); } + currentTimeMillis += 1; } events = allEvents.findByEmptyServerVersion();