From a794bd3af4335e9360b86d1ed6d18d6e77e86074 Mon Sep 17 00:00:00 2001 From: wangxuxin Date: Sat, 8 Jul 2023 15:34:43 +0800 Subject: [PATCH] feat: fix sync var --- .../org/bdware/sc/crdt/SharableVarManager.java | 3 ++- .../java/org/bdware/sc/crdt/proxy/SharableVar.java | 14 +++++++------- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/main/java/org/bdware/sc/crdt/SharableVarManager.java b/src/main/java/org/bdware/sc/crdt/SharableVarManager.java index 763db2d..de43f8b 100644 --- a/src/main/java/org/bdware/sc/crdt/SharableVarManager.java +++ b/src/main/java/org/bdware/sc/crdt/SharableVarManager.java @@ -55,11 +55,12 @@ public class SharableVarManager { String type = message.header.parameters.attributes.get("type").getAsString(); SharableVar var = allVars.get(varId); if (var != null) { - JoinableCRDT delta = JsonUtil.fromJson(content, JoinableCRDT.class); if (Objects.equals(type, "r2r") || Objects.equals(type, "w2r")) { + JoinableCRDT delta = JsonUtil.fromJson(content, var.readerVar.getClass()); var.readerVar.join(delta); var.readerVarDeltaQueue.add(delta); } else if (Objects.equals(type, "w2w")) { + JoinableCRDT delta = JsonUtil.fromJson(content, var.writerVar.getClass()); var.writerVar.join(delta); var.writerVarDeltaQueue.add(delta); } diff --git a/src/main/java/org/bdware/sc/crdt/proxy/SharableVar.java b/src/main/java/org/bdware/sc/crdt/proxy/SharableVar.java index 0845200..ad3fac5 100644 --- a/src/main/java/org/bdware/sc/crdt/proxy/SharableVar.java +++ b/src/main/java/org/bdware/sc/crdt/proxy/SharableVar.java @@ -49,8 +49,8 @@ public abstract class SharableVar { this.readerTimer.newTimeout(timeout -> { readerSyncTimerTask = new ReaderSyncTimerTask(); readerTimer.newTimeout(readerSyncTimerTask, sharableVarState.getReaderInterval(), - TimeUnit.MILLISECONDS); - }, 0, TimeUnit.MILLISECONDS); + TimeUnit.SECONDS); + }, this.sharableVarState.getReaderInterval(), TimeUnit.SECONDS); } } if (this.sharableVarState.isWriterFlag()) { @@ -65,8 +65,8 @@ public abstract class SharableVar { this.writerTimer.newTimeout(timeout -> { writerSyncTimerTask = new WriterSyncTimerTask(); writerTimer.newTimeout(writerSyncTimerTask, sharableVarState.getWriteInterval(), - TimeUnit.MILLISECONDS); - }, 0, TimeUnit.MILLISECONDS); + TimeUnit.SECONDS); + }, this.sharableVarState.getWriteInterval(), TimeUnit.SECONDS); } } } @@ -119,7 +119,7 @@ public abstract class SharableVar { e.printStackTrace(); } finally { readerTimer.newTimeout(readerSyncTimerTask, sharableVarState.getReaderInterval(), - TimeUnit.MILLISECONDS); + TimeUnit.SECONDS); } } } @@ -132,8 +132,8 @@ public abstract class SharableVar { } catch (Exception e) { e.printStackTrace(); } finally { - readerTimer.newTimeout(writerSyncTimerTask, sharableVarState.getWriteInterval(), - TimeUnit.MILLISECONDS); + writerTimer.newTimeout(writerSyncTimerTask, sharableVarState.getWriteInterval(), + TimeUnit.SECONDS); } } }