Skip to content

Commit

Permalink
Change removeFromMapAndDataStore to signal listeners at the end in a …
Browse files Browse the repository at this point in the history
…batch

All current users still call this one-at-a-time. But, it gives the ability
for the expire code path to remove in a batch.
  • Loading branch information
julianknutsen committed Nov 18, 2019
1 parent a5649dd commit 3f8a826
Showing 1 changed file with 5 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -651,12 +651,14 @@ private void removeFromMapAndDataStore(ProtectedStorageEntry protectedStorageEnt

private void removeFromMapAndDataStore(
Collection<Map.Entry<ByteArray, ProtectedStorageEntry>> entriesToRemoveWithPayloadHash) {

ArrayList<ProtectedStorageEntry> entriesForSignal = new ArrayList<>(entriesToRemoveWithPayloadHash.size());
entriesToRemoveWithPayloadHash.forEach(entryToRemoveWithPayloadHash -> {
ByteArray hashOfPayload = entryToRemoveWithPayloadHash.getKey();
ProtectedStorageEntry protectedStorageEntry = entryToRemoveWithPayloadHash.getValue();

map.remove(hashOfPayload);
hashMapChangedListeners.forEach(e -> e.onRemoved(Collections.singletonList(protectedStorageEntry)));
entriesForSignal.add(protectedStorageEntry);

ProtectedStoragePayload protectedStoragePayload = protectedStorageEntry.getProtectedStoragePayload();
if (protectedStoragePayload instanceof PersistablePayload) {
Expand All @@ -669,6 +671,8 @@ private void removeFromMapAndDataStore(
}
}
});

hashMapChangedListeners.forEach(e -> e.onRemoved(entriesForSignal));
}

private boolean hasSequenceNrIncreased(int newSequenceNumber, ByteArray hashOfData) {
Expand Down

0 comments on commit 3f8a826

Please sign in to comment.