feat: format code

This commit is contained in:
Xuxin Wang 2023-07-16 17:51:15 +08:00
parent 2384f6cc59
commit 2180260a20
7 changed files with 62 additions and 47 deletions

View File

@ -82,7 +82,8 @@ public class SharableVarManager {
} }
} }
private DoipMessage createSyncMessage(String target, String varId, String content, String type) { private DoipMessage createSyncMessage(String target, String varId, String content,
String type) {
DoipMessageFactory.DoipMessageBuilder builder = new DoipMessageFactory.DoipMessageBuilder(); DoipMessageFactory.DoipMessageBuilder builder = new DoipMessageFactory.DoipMessageBuilder();
builder.createRequest(target, SHARABLEOP); builder.createRequest(target, SHARABLEOP);
builder.addAttributes("varId", varId); builder.addAttributes("varId", varId);
@ -91,7 +92,8 @@ public class SharableVarManager {
return builder.create(); return builder.create();
} }
public void broadcastSyncMessage(String varId, List<String> sendTo, String content, String type) { public void broadcastSyncMessage(String varId, List<String> sendTo, String content,
String type) {
for (String target : sendTo) { for (String target : sendTo) {
DoipMessage doipMessage = createSyncMessage(target, varId, content, type); DoipMessage doipMessage = createSyncMessage(target, varId, content, type);
if (target.equals(cpId)) { if (target.equals(cpId)) {

View File

@ -280,17 +280,22 @@ public class SharableVarState {
SharableVarConfiguration sharableVarConfiguration = new SharableVarConfiguration(); SharableVarConfiguration sharableVarConfiguration = new SharableVarConfiguration();
sharableVarConfiguration.setNodeIds(new String[]{"/bdrepo1/var/0", "/bdrepo1/var/1", "/bdrepo1/var/2", "/bdrepo1/var/3"}); sharableVarConfiguration.setNodeIds(new String[] {"/bdrepo1/var/0", "/bdrepo1/var/1",
"/bdrepo1/var/2", "/bdrepo1/var/3"});
sharableVarConfiguration.setWriterParents(new int[] {2, 2, -1, -2}); sharableVarConfiguration.setWriterParents(new int[] {2, 2, -1, -2});
sharableVarConfiguration.setReaderParents(new int[] {-2, -1, -2, 1}); sharableVarConfiguration.setReaderParents(new int[] {-2, -1, -2, 1});
sharableVarConfiguration.setWriterIntervals(new long[] {5, 5, 6, -1}); sharableVarConfiguration.setWriterIntervals(new long[] {5, 5, 6, -1});
sharableVarConfiguration.setReaderIntervals(new long[] {-1, 4, -1, -1}); sharableVarConfiguration.setReaderIntervals(new long[] {-1, 4, -1, -1});
SharableVarState sharableVarState0 = new SharableVarState("/bdrepo1/var/0", sharableVarConfiguration); SharableVarState sharableVarState0 =
SharableVarState sharableVarState1 = new SharableVarState("/bdrepo1/var/1", sharableVarConfiguration); new SharableVarState("/bdrepo1/var/0", sharableVarConfiguration);
SharableVarState sharableVarState2 = new SharableVarState("/bdrepo1/var/2", sharableVarConfiguration); SharableVarState sharableVarState1 =
SharableVarState sharableVarState3 = new SharableVarState("/bdrepo1/var/3", sharableVarConfiguration); new SharableVarState("/bdrepo1/var/1", sharableVarConfiguration);
SharableVarState sharableVarState2 =
new SharableVarState("/bdrepo1/var/2", sharableVarConfiguration);
SharableVarState sharableVarState3 =
new SharableVarState("/bdrepo1/var/3", sharableVarConfiguration);
System.out.println(sharableVarState0); System.out.println(sharableVarState0);
System.out.println(sharableVarState1); System.out.println(sharableVarState1);
System.out.println(sharableVarState2); System.out.println(sharableVarState2);

View File

@ -64,7 +64,7 @@ public class PlanningWith0Expansivity extends SharableNetworkPlanning {
frequencySyncR = rDelay > 0 ? (treeHeightR - 1) / rDelay : 0; frequencySyncR = rDelay > 0 ? (treeHeightR - 1) / rDelay : 0;
frequencySyncWR = w2rDelay > 0 ? (1.0 / w2rDelay) : 0; frequencySyncWR = w2rDelay > 0 ? (1.0 / w2rDelay) : 0;
totalData = (long) (dataSize totalData =
* (frequencySyncW * a + frequencySyncWR * b + frequencySyncR * c)); (long) (dataSize * (frequencySyncW * a + frequencySyncWR * b + frequencySyncR * c));
} }
} }

View File

@ -51,9 +51,10 @@ public class PlanningWith1Expansivity extends SharableNetworkPlanning {
double a = 0; double a = 0;
if (treeHeightW > 1) { if (treeHeightW > 1) {
if (treeDegreeW > 1) { if (treeDegreeW > 1) {
a = (treeHeightW - 1) * a = (treeHeightW - 1)
(treeHeightW * Math.pow(treeDegreeW, treeHeightW) / (treeDegreeW - 1) * (treeHeightW * Math.pow(treeDegreeW, treeHeightW) / (treeDegreeW - 1)
+ (treeDegreeW - Math.pow(treeDegreeW, treeHeightW + 1)) / (treeDegreeW - 1) / (treeDegreeW - 1)) + (treeDegreeW - Math.pow(treeDegreeW, treeHeightW + 1))
/ (treeDegreeW - 1) / (treeDegreeW - 1))
* rootCountW; * rootCountW;
} else { } else {
// treeDegreeW = 1 // treeDegreeW = 1
@ -76,7 +77,7 @@ public class PlanningWith1Expansivity extends SharableNetworkPlanning {
frequencySyncR = rDelay > 0 ? (treeHeightR - 1) / rDelay : 0; frequencySyncR = rDelay > 0 ? (treeHeightR - 1) / rDelay : 0;
frequencySyncWR = w2rDelay > 0 ? (1.0 / w2rDelay) : 0; frequencySyncWR = w2rDelay > 0 ? (1.0 / w2rDelay) : 0;
totalData = (long) (dataSize totalData =
* (frequencySyncW * a + frequencySyncWR * b + frequencySyncR * c)); (long) (dataSize * (frequencySyncW * a + frequencySyncWR * b + frequencySyncR * c));
} }
} }

View File

@ -26,8 +26,8 @@ public class PlanningWithkExpansivity extends SharableNetworkPlanning {
public boolean writerTreeConstraint() { public boolean writerTreeConstraint() {
if (frequencySyncW > 0) { if (frequencySyncW > 0) {
if (treeDegreeW > 1) { if (treeDegreeW > 1) {
double common = frequencySyncW * domainSize double common = frequencySyncW * domainSize * (1 - Math.pow(k,
* (1 - Math.pow(k, (Math.pow(treeDegreeW, treeHeightW - 1) - 1) / (treeDegreeW - 1))); (Math.pow(treeDegreeW, treeHeightW - 1) - 1) / (treeDegreeW - 1)));
// 非叶子节点下载带宽 // 非叶子节点下载带宽
boolean result1 = bandwidthDownload >= common * treeDegreeW; boolean result1 = bandwidthDownload >= common * treeDegreeW;
// 非根节点上行带宽 // 非根节点上行带宽
@ -76,8 +76,7 @@ public class PlanningWithkExpansivity extends SharableNetworkPlanning {
} }
double result = 0; double result = 0;
for (int h = 1; h < H1; ++h) { for (int h = 1; h < H1; ++h) {
result += result += (Math.pow(D1, h) * (1 - Math.pow(k, (Math.pow(D1, H1 - h) - 1) / (D1 - 1))));
(Math.pow(D1, h) * (1 - Math.pow(k, (Math.pow(D1, H1 - h) - 1) / (D1 - 1))));
} }
accumulationsCache.computeIfAbsent(H1, k -> new HashMap<>()).put(D1, result); accumulationsCache.computeIfAbsent(H1, k -> new HashMap<>()).put(D1, result);
return result; return result;
@ -101,7 +100,9 @@ public class PlanningWithkExpansivity extends SharableNetworkPlanning {
} }
double b = rootCountR * rootCountW * (1 - Math.pow(k, treeNodeCountW)); double b = rootCountR * rootCountW * (1 - Math.pow(k, treeNodeCountW));
double c = treeHeightR > 1 ? (treeHeightR - 1) * (totalCountR - rootCountR) * (1 - Math.pow(k, totalCountW)) : 0; double c = treeHeightR > 1
? (treeHeightR - 1) * (totalCountR - rootCountR) * (1 - Math.pow(k, totalCountW))
: 0;
double A = Math.sqrt(a); double A = Math.sqrt(a);
double B = Math.sqrt(b); double B = Math.sqrt(b);

View File

@ -46,7 +46,8 @@ public class SharableNetworkPlanning {
this.treeDegreeW = treeDegreeW; this.treeDegreeW = treeDegreeW;
this.treeNodeCountW = Math.ceil(totalCountW / rootCountW); this.treeNodeCountW = Math.ceil(totalCountW / rootCountW);
if (treeDegreeW > 1) { if (treeDegreeW > 1) {
this.treeHeightW = Math.ceil(logNM(treeDegreeW, treeNodeCountW * (treeDegreeW - 1) + 1)); this.treeHeightW =
Math.ceil(logNM(treeDegreeW, treeNodeCountW * (treeDegreeW - 1) + 1));
} else { } else {
this.treeHeightW = treeNodeCountW; this.treeHeightW = treeNodeCountW;
} }
@ -57,7 +58,8 @@ public class SharableNetworkPlanning {
this.treeDegreeR = treeDegreeR; this.treeDegreeR = treeDegreeR;
this.treeNodeCountR = Math.ceil(totalCountR / rootCountR); this.treeNodeCountR = Math.ceil(totalCountR / rootCountR);
if (treeDegreeR > 1) { if (treeDegreeR > 1) {
this.treeHeightR = Math.ceil(logNM(treeDegreeR, treeNodeCountR * (treeDegreeR - 1) + 1)); this.treeHeightR =
Math.ceil(logNM(treeDegreeR, treeNodeCountR * (treeDegreeR - 1) + 1));
} else { } else {
this.treeHeightR = treeNodeCountR; this.treeHeightR = treeNodeCountR;
} }
@ -100,8 +102,7 @@ public class SharableNetworkPlanning {
System.out.println(result); System.out.println(result);
} }
protected void calcOptimizedResult() { protected void calcOptimizedResult() {}
}
protected boolean writer2ReaderConstraint() { protected boolean writer2ReaderConstraint() {
return true; return true;
@ -188,10 +189,9 @@ public class SharableNetworkPlanning {
@Override @Override
public String toString() { public String toString() {
String result = "[" + wDelay + "," + w2rDelay + "," + rDelay + String result = "[" + wDelay + "," + w2rDelay + "," + rDelay + "]\n"
"]\n" + "writer tree: degree " + treeDegreeW + + "writer tree: degree " + treeDegreeW + ", count " + rootCountW + ",\n"
", count " + rootCountW + ",\n" + "reader tree: degree " + treeDegreeR + ", count " + + "reader tree: degree " + treeDegreeR + ", count " + rootCountR;
rootCountR;
return result; return result;
} }
} }

View File

@ -39,8 +39,10 @@ public abstract class SharableVar<T extends JoinableCRDT> {
if (this.sharableVarState.isReaderFlag()) { if (this.sharableVarState.isReaderFlag()) {
this.readerVar = createDeltaCrdt(cpId, varId); this.readerVar = createDeltaCrdt(cpId, varId);
this.readerVarDeltaQueue = new LinkedList<>(); this.readerVarDeltaQueue = new LinkedList<>();
if (this.sharableVarState.getReaderChildren() != null && this.sharableVarState.getReaderChildren().size() > 0 if (this.sharableVarState.getReaderChildren() != null
&& this.sharableVarState.getReaderInterval() != null && this.sharableVarState.getReaderInterval() > 0) { && this.sharableVarState.getReaderChildren().size() > 0
&& this.sharableVarState.getReaderInterval() != null
&& this.sharableVarState.getReaderInterval() > 0) {
this.readerTimer = new HashedWheelTimer(r -> { this.readerTimer = new HashedWheelTimer(r -> {
Thread t = Executors.defaultThreadFactory().newThread(r); Thread t = Executors.defaultThreadFactory().newThread(r);
t.setDaemon(true); t.setDaemon(true);
@ -48,15 +50,16 @@ public abstract class SharableVar<T extends JoinableCRDT> {
}, 5, TimeUnit.MILLISECONDS, 2); }, 5, TimeUnit.MILLISECONDS, 2);
this.readerTimer.newTimeout(timeout -> { this.readerTimer.newTimeout(timeout -> {
readerSyncTimerTask = new ReaderSyncTimerTask(); readerSyncTimerTask = new ReaderSyncTimerTask();
readerTimer.newTimeout(readerSyncTimerTask, sharableVarState.getReaderInterval(), readerTimer.newTimeout(readerSyncTimerTask,
TimeUnit.SECONDS); sharableVarState.getReaderInterval(), TimeUnit.SECONDS);
}, this.sharableVarState.getReaderInterval(), TimeUnit.SECONDS); }, this.sharableVarState.getReaderInterval(), TimeUnit.SECONDS);
} }
} }
if (this.sharableVarState.isWriterFlag()) { if (this.sharableVarState.isWriterFlag()) {
this.writerVar = createDeltaCrdt(cpId, varId); this.writerVar = createDeltaCrdt(cpId, varId);
this.writerVarDeltaQueue = new LinkedList<>(); this.writerVarDeltaQueue = new LinkedList<>();
if (this.sharableVarState.getWriteInterval() != null && this.sharableVarState.getWriteInterval() > 0) { if (this.sharableVarState.getWriteInterval() != null
&& this.sharableVarState.getWriteInterval() > 0) {
this.writerTimer = new HashedWheelTimer(r -> { this.writerTimer = new HashedWheelTimer(r -> {
Thread t = Executors.defaultThreadFactory().newThread(r); Thread t = Executors.defaultThreadFactory().newThread(r);
t.setDaemon(true); t.setDaemon(true);
@ -83,7 +86,8 @@ public abstract class SharableVar<T extends JoinableCRDT> {
} }
} }
String content = JsonUtil.toJson(joinedDelta); String content = JsonUtil.toJson(joinedDelta);
SharableVarManager.instance.broadcastSyncMessage(varId, sharableVarState.getReaderChildren(), content, "r2r"); SharableVarManager.instance.broadcastSyncMessage(varId,
sharableVarState.getReaderChildren(), content, "r2r");
} }
private void syncWriterVar() { private void syncWriterVar() {
@ -100,10 +104,12 @@ public abstract class SharableVar<T extends JoinableCRDT> {
String content = JsonUtil.toJson(joinedDelta); String content = JsonUtil.toJson(joinedDelta);
if (sharableVarState.getWriterParent() != null) { if (sharableVarState.getWriterParent() != null) {
// 父节点是Writer // 父节点是Writer
SharableVarManager.instance.broadcastSyncMessage(varId, Collections.singletonList(sharableVarState.getWriterParent()), content, "w2w"); SharableVarManager.instance.broadcastSyncMessage(varId,
Collections.singletonList(sharableVarState.getWriterParent()), content, "w2w");
} else if (sharableVarState.getReaderRoots() != null) { } else if (sharableVarState.getReaderRoots() != null) {
// 自己是writer根结点 向reader根结点们广播 // 自己是writer根结点 向reader根结点们广播
SharableVarManager.instance.broadcastSyncMessage(varId, sharableVarState.getReaderRoots(), content, "w2r"); SharableVarManager.instance.broadcastSyncMessage(varId,
sharableVarState.getReaderRoots(), content, "w2r");
} }
} }