Skip to content

Commit

Permalink
Update lastMarkDeleteEntry using AtomicReferenceFieldUpdater
Browse files Browse the repository at this point in the history
  • Loading branch information
Masahiro Sakamoto committed Jun 9, 2021
1 parent de42532 commit 0dc734e
Showing 1 changed file with 18 additions and 15 deletions.
Expand Up @@ -288,17 +288,17 @@ public Map<String, Long> getProperties() {
@Override
public boolean putProperty(String key, Long value) {
if (lastMarkDeleteEntry != null) {
MarkDeleteEntry currentLastMarkDeleteEntry = lastMarkDeleteEntry;
Map<String, Long> properties = currentLastMarkDeleteEntry.properties;
if (properties == null || properties.isEmpty()) {
Map<String, Long> newProperties = Maps.newHashMap();
LAST_MARK_DELETE_ENTRY_UPDATER.updateAndGet(this, last -> {
Map<String, Long> newProperties = last.properties == null ? Maps.newHashMap()
: Maps.newHashMap(last.properties);
newProperties.put(key, value);
lastMarkDeleteEntry = new MarkDeleteEntry(currentLastMarkDeleteEntry.newPosition, newProperties,
currentLastMarkDeleteEntry.callback, currentLastMarkDeleteEntry.ctx);
lastMarkDeleteEntry.callbackGroup = currentLastMarkDeleteEntry.callbackGroup;
} else {
properties.put(key, value);
}

MarkDeleteEntry newLastMarkDeleteEntry = new MarkDeleteEntry(last.newPosition, newProperties,
last.callback, last.ctx);
newLastMarkDeleteEntry.callbackGroup = last.callbackGroup;

return newLastMarkDeleteEntry;
});
return true;
}
return false;
Expand All @@ -307,11 +307,14 @@ public boolean putProperty(String key, Long value) {
@Override
public boolean removeProperty(String key) {
if (lastMarkDeleteEntry != null) {
Map<String, Long> properties = lastMarkDeleteEntry.properties;
if (properties != null && properties.containsKey(key)) {
properties.remove(key);
return true;
}
LAST_MARK_DELETE_ENTRY_UPDATER.updateAndGet(this, last -> {
Map<String, Long> properties = last.properties;
if (properties != null && properties.containsKey(key)) {
properties.remove(key);
}
return last;
});
return true;
}
return false;
}
Expand Down

0 comments on commit 0dc734e

Please sign in to comment.