2021-01-31 00:36:21 +01:00
|
|
|
package it.cavallium.dbengine.database.collections;
|
|
|
|
|
2021-09-17 16:56:28 +02:00
|
|
|
import io.net5.buffer.api.Buffer;
|
|
|
|
import io.net5.buffer.api.Send;
|
2021-01-31 00:36:21 +01:00
|
|
|
import it.cavallium.dbengine.client.CompositeSnapshot;
|
|
|
|
import it.cavallium.dbengine.database.LLDictionary;
|
2021-02-02 19:40:37 +01:00
|
|
|
import it.cavallium.dbengine.database.serialization.Serializer;
|
2021-01-31 00:36:21 +01:00
|
|
|
import org.jetbrains.annotations.Nullable;
|
|
|
|
import reactor.core.publisher.Mono;
|
|
|
|
|
2021-01-31 19:52:47 +01:00
|
|
|
public class SubStageGetterSingle<T> implements SubStageGetter<T, DatabaseStageEntry<T>> {
|
|
|
|
|
2021-09-01 00:01:56 +02:00
|
|
|
private final Serializer<T> serializer;
|
2021-01-31 19:52:47 +01:00
|
|
|
|
2021-09-01 00:01:56 +02:00
|
|
|
public SubStageGetterSingle(Serializer<T> serializer) {
|
2021-01-31 19:52:47 +01:00
|
|
|
this.serializer = serializer;
|
|
|
|
}
|
2021-01-31 00:36:21 +01:00
|
|
|
|
|
|
|
@Override
|
2021-01-31 19:52:47 +01:00
|
|
|
public Mono<DatabaseStageEntry<T>> subStage(LLDictionary dictionary,
|
2021-01-31 00:36:21 +01:00
|
|
|
@Nullable CompositeSnapshot snapshot,
|
2021-08-29 23:18:03 +02:00
|
|
|
Mono<Send<Buffer>> keyPrefixMono) {
|
2021-08-22 18:20:05 +02:00
|
|
|
return Mono.usingWhen(
|
|
|
|
keyPrefixMono,
|
|
|
|
keyPrefix -> Mono
|
2021-08-29 23:18:03 +02:00
|
|
|
.<DatabaseStageEntry<T>>fromSupplier(() -> new DatabaseSingle<>(dictionary, keyPrefix, serializer)),
|
|
|
|
keyPrefix -> Mono.fromRunnable(keyPrefix::close)
|
2021-08-22 18:20:05 +02:00
|
|
|
);
|
2021-01-31 19:52:47 +01:00
|
|
|
}
|
|
|
|
|
2021-01-31 00:36:21 +01:00
|
|
|
}
|