Skip to content

Commit

Permalink
We get the listeners calls when data got added to the stores. The dup…
Browse files Browse the repository at this point in the history
…licated listener calls have been redundant and caused issues on the clients (e.g. creating simultaneously 2 outbound connections)
  • Loading branch information
djing-chan committed Dec 19, 2023
1 parent f811f28 commit 6caca44
Showing 1 changed file with 0 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -150,11 +150,6 @@ public CompletableFuture<BroadcastResult> addAuthenticatedData(AuthenticatedData
AddAuthenticatedDataRequest request = AddAuthenticatedDataRequest.from(store, authenticatedData, keyPair);
DataStorageResult dataStorageResult = store.add(request);
if (dataStorageResult.isSuccess()) {
if (authenticatedData instanceof AuthorizedData) {
listeners.forEach(e -> e.onAuthorizedDataAdded((AuthorizedData) authenticatedData));
} else {
listeners.forEach(e -> e.onAuthenticatedDataAdded(authenticatedData));
}
return new BroadcastResult(broadcasters.stream().map(broadcaster -> broadcaster.broadcast(request)));
} else {
return new BroadcastResult();
Expand All @@ -176,7 +171,6 @@ public CompletableFuture<BroadcastResult> addAppendOnlyData(AppendOnlyData appen
AddAppendOnlyDataRequest request = new AddAppendOnlyDataRequest(appendOnlyData);
DataStorageResult dataStorageResult = store.add(request);
if (dataStorageResult.isSuccess()) {
listeners.forEach(listener -> listener.onAppendOnlyDataAdded(appendOnlyData));
return new BroadcastResult(broadcasters.stream().map(broadcaster -> broadcaster.broadcast(request)));
} else {
return new BroadcastResult();
Expand All @@ -193,7 +187,6 @@ public CompletableFuture<BroadcastResult> addMailboxData(MailboxData mailboxData
AddMailboxRequest request = AddMailboxRequest.from(mailboxData, senderKeyPair, receiverPublicKey);
DataStorageResult dataStorageResult = store.add(request);
if (dataStorageResult.isSuccess()) {
listeners.forEach(listener -> listener.onMailboxDataAdded(mailboxData));
return new BroadcastResult(broadcasters.stream().map(broadcaster -> broadcaster.broadcast(request)));
} else {
return new BroadcastResult();
Expand All @@ -218,11 +211,6 @@ public CompletableFuture<BroadcastResult> removeAuthenticatedData(AuthenticatedD
RemoveAuthenticatedDataRequest request = RemoveAuthenticatedDataRequest.from(store, authenticatedData, keyPair);
DataStorageResult dataStorageResult = store.remove(request);
if (dataStorageResult.isSuccess()) {
if (authenticatedData instanceof AuthorizedData) {
listeners.forEach(e -> e.onAuthorizedDataRemoved((AuthorizedData) authenticatedData));
} else {
listeners.forEach(e -> e.onAuthenticatedDataRemoved(authenticatedData));
}
return new BroadcastResult(broadcasters.stream().map(broadcaster -> broadcaster.broadcast(request)));
} else {
return new BroadcastResult();
Expand All @@ -245,7 +233,6 @@ public CompletableFuture<BroadcastResult> removeMailboxData(MailboxData mailboxD
RemoveMailboxRequest request = RemoveMailboxRequest.from(mailboxData, keyPair);
DataStorageResult dataStorageResult = store.remove(request);
if (dataStorageResult.isSuccess()) {
listeners.forEach(listener -> listener.onMailboxDataRemoved(mailboxData));
return new BroadcastResult(broadcasters.stream().map(broadcaster -> broadcaster.broadcast(request)));
} else {
return new BroadcastResult();
Expand Down Expand Up @@ -287,18 +274,6 @@ public void processAddDataRequest(AddDataRequest addDataRequest, boolean allowRe
storageService.onAddDataRequest(addDataRequest)
.whenComplete((optionalData, throwable) -> {
optionalData.ifPresent(storageData -> {
// We get called on dispatcher thread with onMessage, and we don't switch thread in
// async calls

if (storageData instanceof AuthorizedData) {
listeners.forEach(e -> e.onAuthorizedDataAdded((AuthorizedData) storageData));
} else if (storageData instanceof AuthenticatedData) {
listeners.forEach(e -> e.onAuthenticatedDataAdded((AuthenticatedData) storageData));
} else if (storageData instanceof MailboxData) {
listeners.forEach(listener -> listener.onMailboxDataAdded((MailboxData) storageData));
} else if (storageData instanceof AppendOnlyData) {
listeners.forEach(listener -> listener.onAppendOnlyDataAdded((AppendOnlyData) storageData));
}
if (allowReBroadcast) {
broadcasters.forEach(e -> e.reBroadcast(addDataRequest));
}
Expand All @@ -310,13 +285,6 @@ public void processRemoveDataRequest(RemoveDataRequest removeDataRequest, boolea
storageService.onRemoveDataRequest(removeDataRequest)
.whenComplete((optionalData, throwable) -> {
optionalData.ifPresent(storageData -> {
// We get called on dispatcher thread with onMessage, and we don't switch thread in
// async calls
if (storageData instanceof AuthorizedData) {
listeners.forEach(e -> e.onAuthorizedDataRemoved((AuthorizedData) storageData));
} else if (storageData instanceof AuthenticatedData) {
listeners.forEach(e -> e.onAuthenticatedDataRemoved((AuthenticatedData) storageData));
}
if (allowReBroadcast) {
broadcasters.forEach(e -> e.reBroadcast(removeDataRequest));
}
Expand Down

0 comments on commit 6caca44

Please sign in to comment.