feat: fix sync var

This commit is contained in:
Xuxin Wang 2023-07-08 15:34:43 +08:00
parent c0c580090e
commit a794bd3af4
2 changed files with 9 additions and 8 deletions

View File

@ -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);
}

View File

@ -49,8 +49,8 @@ public abstract class SharableVar<T extends JoinableCRDT> {
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<T extends JoinableCRDT> {
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<T extends JoinableCRDT> {
e.printStackTrace();
} finally {
readerTimer.newTimeout(readerSyncTimerTask, sharableVarState.getReaderInterval(),
TimeUnit.MILLISECONDS);
TimeUnit.SECONDS);
}
}
}
@ -132,8 +132,8 @@ public abstract class SharableVar<T extends JoinableCRDT> {
} catch (Exception e) {
e.printStackTrace();
} finally {
readerTimer.newTimeout(writerSyncTimerTask, sharableVarState.getWriteInterval(),
TimeUnit.MILLISECONDS);
writerTimer.newTimeout(writerSyncTimerTask, sharableVarState.getWriteInterval(),
TimeUnit.SECONDS);
}
}
}