java内存对象映射文件_java-dirty: java-dirty 是一个快速的基于文件的对象存储系统,只能往存储里添加对象,使用内存映射文件技术...

java-dirty

c5e5d25de4ce5e75b2d47c24ddb18b9a.png

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

uk.co.probablyfine

java-dirty

1.6

Usage

Creating a store.

Store store = Store.of(Foo.class).from("/path/to/file");

Inserting an object

store.put(new Foo(1,2));

Iterating over all objects in the store

store.all().forEach(System.out::println);

Iterate over objects, most recent first

store.reverse().forEach(System.out::println);

Iterate over objects from a starting index

store.from(100).forEach(System.out::println);

Access an index directly

Optional foo = store.get(1234);

Reset the entire store

store.reset(); // Reset position to 0, overwriting old entries

Close the store and its backing file

store.close();

Trying to read from/write to a closed store will throw a ClosedStoreException.

Observe each write

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

Optional first = store

.reverse()

.filter(x -> x.indexField == valueToFind)

.findFirst();

Build an lookup index using write observers

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值