Async LLInt and LLLong
This commit is contained in:
parent
b1612cb20f
commit
3ad9efe71f
@ -1,11 +1,11 @@
|
||||
package it.cavallium.dbengine.database;
|
||||
|
||||
import java.io.IOException;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
public interface LLSingleton extends LLKeyValueDatabaseStructure {
|
||||
|
||||
byte[] get(@Nullable LLSnapshot snapshot) throws IOException;
|
||||
Mono<byte[]> get(@Nullable LLSnapshot snapshot);
|
||||
|
||||
void set(byte[] value) throws IOException;
|
||||
Mono<Void> set(byte[] value);
|
||||
}
|
||||
|
@ -10,6 +10,8 @@ import org.rocksdb.RocksDBException;
|
||||
import org.rocksdb.Snapshot;
|
||||
import it.cavallium.dbengine.database.LLSingleton;
|
||||
import it.cavallium.dbengine.database.LLSnapshot;
|
||||
import reactor.core.publisher.Mono;
|
||||
import reactor.core.scheduler.Schedulers;
|
||||
|
||||
public class LLLocalSingleton implements LLSingleton {
|
||||
|
||||
@ -44,21 +46,22 @@ public class LLLocalSingleton implements LLSingleton {
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] get(@Nullable LLSnapshot snapshot) throws IOException {
|
||||
try {
|
||||
return db.get(cfh, resolveSnapshot(snapshot), name);
|
||||
} catch (RocksDBException e) {
|
||||
throw new IOException(e);
|
||||
}
|
||||
public Mono<byte[]> get(@Nullable LLSnapshot snapshot) {
|
||||
return Mono
|
||||
.fromCallable(() -> db.get(cfh, resolveSnapshot(snapshot), name))
|
||||
.onErrorMap(IOException::new)
|
||||
.subscribeOn(Schedulers.boundedElastic());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void set(byte[] value) throws IOException {
|
||||
try {
|
||||
db.put(cfh, name, value);
|
||||
} catch (RocksDBException e) {
|
||||
throw new IOException(e);
|
||||
}
|
||||
public Mono<Void> set(byte[] value) {
|
||||
return Mono
|
||||
.<Void>fromCallable(() -> {
|
||||
db.put(cfh, name, value);
|
||||
return null;
|
||||
})
|
||||
.onErrorMap(IOException::new)
|
||||
.subscribeOn(Schedulers.boundedElastic());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -4,8 +4,8 @@ import com.google.common.primitives.Ints;
|
||||
import it.cavallium.dbengine.database.LLKeyValueDatabaseStructure;
|
||||
import it.cavallium.dbengine.database.LLSingleton;
|
||||
import it.cavallium.dbengine.database.LLSnapshot;
|
||||
import java.io.IOException;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
public class LLInt implements LLKeyValueDatabaseStructure {
|
||||
|
||||
@ -15,12 +15,12 @@ public class LLInt implements LLKeyValueDatabaseStructure {
|
||||
this.singleton = singleton;
|
||||
}
|
||||
|
||||
public int get(@Nullable LLSnapshot snapshot) throws IOException {
|
||||
return Ints.fromByteArray(singleton.get(snapshot));
|
||||
public Mono<Integer> get(@Nullable LLSnapshot snapshot) {
|
||||
return singleton.get(snapshot).map(Ints::fromByteArray);
|
||||
}
|
||||
|
||||
public void set(int value) throws IOException {
|
||||
singleton.set(Ints.toByteArray(value));
|
||||
public Mono<Void> set(int value) {
|
||||
return singleton.set(Ints.toByteArray(value));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -5,8 +5,8 @@ import com.google.common.primitives.Longs;
|
||||
import it.cavallium.dbengine.database.LLKeyValueDatabaseStructure;
|
||||
import it.cavallium.dbengine.database.LLSingleton;
|
||||
import it.cavallium.dbengine.database.LLSnapshot;
|
||||
import java.io.IOException;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
public class LLLong implements LLKeyValueDatabaseStructure {
|
||||
|
||||
@ -16,17 +16,18 @@ public class LLLong implements LLKeyValueDatabaseStructure {
|
||||
this.singleton = singleton;
|
||||
}
|
||||
|
||||
public long get(@Nullable LLSnapshot snapshot) throws IOException {
|
||||
var array = singleton.get(snapshot);
|
||||
if (array.length == 4) {
|
||||
return Ints.fromByteArray(array);
|
||||
} else {
|
||||
return Longs.fromByteArray(array);
|
||||
}
|
||||
public Mono<Long> get(@Nullable LLSnapshot snapshot) {
|
||||
return singleton.get(snapshot).map(array -> {
|
||||
if (array.length == 4) {
|
||||
return (long) Ints.fromByteArray(array);
|
||||
} else {
|
||||
return Longs.fromByteArray(array);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void set(long value) throws IOException {
|
||||
singleton.set(Longs.toByteArray(value));
|
||||
public Mono<Void> set(long value) {
|
||||
return singleton.set(Longs.toByteArray(value));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Loading…
Reference in New Issue
Block a user