A fast file-based append-only object store, using memory mapped files.
Absolutely not - but it's fast enough that putting it behind e.g. a Disruptor and consuming writes in a single thread should be fine.
<dependency>
<groupId>uk.co.probablyfine</groupId>
<artifactId>java-dirty</artifactId>
<version>1.6</version>
</dependency>
Store<Foo> store = Store.of(Foo.class).from("/path/to/file");
store.put(new Foo(1,2));
store.all().forEach(System.out::println);
store.reverse().forEach(System.out::println);
store.from(100).forEach(System.out::println);
Optional<Foo> foo = store.get(1234);
store.reset(); // Reset position to 0, overwriting old entries
store.close();
Trying to read from/write to a closed store will throw a ClosedStoreException.
store.observeWrites((object, index) ->
System.out.println("Stored "+object+" at "+index);
);
java-dirty does not support replacements, or deletions. Both .all()
and .reverse()
expose a Stream.
Optional<StoredObject> first = store
.reverse()
.filter(x -> x.indexField == valueToFind)
.findFirst();
Store<StoredObject> store = Store.of(StoredObject.class).from("/some/path");
Map<Integer, Integer> index = new HashMap<>();
store.observeWrites((object, location) -> {
index.put(object.indexField, location);
});
store.put(new StoredObject(1234,5));
store.get(index.get(1234)); // Optional[StoredObject(1234,5)];
java-dirty will only persist primitive fields on objects. All primitive types are currently supported.
See the README in java-dirty-benchmarks for the latest