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 19, 2019
1 parent 4f08588 commit 489b25a
Showing 1 changed file with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -651,12 +651,17 @@ private void removeFromMapAndDataStore(ProtectedStorageEntry protectedStorageEnt

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

if (entriesToRemoveWithPayloadHash.isEmpty())
return;

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 +674,8 @@ private void removeFromMapAndDataStore(
}
}
});

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

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

0 comments on commit 489b25a

Please sign in to comment.