https://github.com/mrwilson/java-dirty
File-backed append-only object store.
https://github.com/mrwilson/java-dirty
Last synced: about 2 months ago
JSON representation
File-backed append-only object store.
- Host: GitHub
- URL: https://github.com/mrwilson/java-dirty
- Owner: mrwilson
- Created: 2015-03-04T21:37:34.000Z (about 11 years ago)
- Default Branch: master
- Last Pushed: 2016-06-12T20:20:56.000Z (almost 10 years ago)
- Last Synced: 2025-07-12T14:25:11.850Z (8 months ago)
- Language: Java
- Size: 76.2 KB
- Stars: 117
- Watchers: 7
- Forks: 18
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
- awesome-java - Java Dirty
README
# java-dirty
[](https://travis-ci.org/mrwilson/java-dirty)
A fast file-based append-only object store, using memory mapped files.
## Is java-dirty safe to use with multiple concurrent writers?
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.
## Downloading from Maven
```xml
uk.co.probablyfine
java-dirty
1.6
```
## Usage
### Creating a store.
```java
Store store = Store.of(Foo.class).from("/path/to/file");
```
### Inserting an object
```java
store.put(new Foo(1,2));
```
### Iterating over all objects in the store
```java
store.all().forEach(System.out::println);
```
### Iterate over objects, most recent first
```java
store.reverse().forEach(System.out::println);
```
### Iterate over objects from a starting index
```java
store.from(100).forEach(System.out::println);
```
### Access an index directly
```java
Optional foo = store.get(1234);
```
### Reset the entire store
```java
store.reset(); // Reset position to 0, overwriting old entries
```
### Close the store and its backing file
```java
store.close();
```
Trying to read from/write to a closed store will throw a ClosedStoreException.
### Observe each write
```java
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.
## Examples
### Look up most recent version of an object by index
```java
Optional first = store
.reverse()
.filter(x -> x.indexField == valueToFind)
.findFirst();
```
### Build an lookup index using write observers
```java
Store store = Store.of(StoredObject.class).from("/some/path");
Map 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)];
```
## Supported Fields
java-dirty will only persist primitive fields on objects. All primitive types are currently supported.
### Performance
See the README in java-dirty-benchmarks for the latest