Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,18 @@

public class InMemoryKeyValueStore implements KeyValueStore<Bytes, byte[]> {
private final String name;
private final ConcurrentNavigableMap<Bytes, byte[]> map;
private final ConcurrentNavigableMap<Bytes, byte[]> map = new ConcurrentSkipListMap<>();
private volatile boolean open = false;

private static final Logger LOG = LoggerFactory.getLogger(InMemoryKeyValueStore.class);

public InMemoryKeyValueStore(final String name) {
this.name = name;

this.map = new ConcurrentSkipListMap<>();
}

@Override
public String name() {
return this.name;
return name;
}

@Override
Expand All @@ -65,7 +63,7 @@ public void init(final ProcessorContext context,
});
}

this.open = true;
open = true;
}

@Override
Expand All @@ -75,20 +73,20 @@ public boolean persistent() {

@Override
public boolean isOpen() {
return this.open;
return open;
}

@Override
public byte[] get(final Bytes key) {
return this.map.get(key);
return map.get(key);
}

@Override
public void put(final Bytes key, final byte[] value) {
if (value == null) {
this.map.remove(key);
map.remove(key);
} else {
this.map.put(key, value);
map.put(key, value);
}
}

Expand All @@ -110,7 +108,7 @@ public void putAll(final List<KeyValue<Bytes, byte[]>> entries) {

@Override
public byte[] delete(final Bytes key) {
return this.map.remove(key);
return map.remove(key);
}

@Override
Expand All @@ -125,19 +123,19 @@ public KeyValueIterator<Bytes, byte[]> range(final Bytes from, final Bytes to) {

return new DelegatingPeekingKeyValueIterator<>(
name,
new InMemoryKeyValueIterator(this.map.subMap(from, true, to, true).entrySet().iterator()));
new InMemoryKeyValueIterator(map.subMap(from, true, to, true).entrySet().iterator()));
}

@Override
public KeyValueIterator<Bytes, byte[]> all() {
return new DelegatingPeekingKeyValueIterator<>(
name,
new InMemoryKeyValueIterator(this.map.entrySet().iterator()));
new InMemoryKeyValueIterator(map.entrySet().iterator()));
}

@Override
public long approximateNumEntries() {
return this.map.size();
return map.size();
}

@Override
Expand All @@ -147,8 +145,8 @@ public void flush() {

@Override
public void close() {
this.map.clear();
this.open = false;
map.clear();
open = false;
}

private static class InMemoryKeyValueIterator implements KeyValueIterator<Bytes, byte[]> {
Expand Down
Loading