2021-02-04 00:48:49 +01:00
|
|
|
package it.cavallium.dbengine.database.collections;
|
|
|
|
|
2021-08-29 23:18:03 +02:00
|
|
|
import io.netty.buffer.api.Buffer;
|
2021-08-31 09:14:46 +02:00
|
|
|
import io.netty.buffer.api.Send;
|
2021-05-02 19:18:15 +02:00
|
|
|
import io.netty.util.ReferenceCounted;
|
2021-02-04 00:48:49 +01:00
|
|
|
import it.cavallium.dbengine.client.CompositeSnapshot;
|
|
|
|
import it.cavallium.dbengine.database.LLDictionary;
|
|
|
|
import it.cavallium.dbengine.database.collections.DatabaseEmpty.Nothing;
|
|
|
|
import it.cavallium.dbengine.database.serialization.SerializerFixedBinaryLength;
|
2021-05-03 00:29:26 +02:00
|
|
|
import java.util.List;
|
2021-02-04 00:48:49 +01:00
|
|
|
import java.util.Map;
|
|
|
|
import org.jetbrains.annotations.Nullable;
|
|
|
|
import reactor.core.publisher.Flux;
|
|
|
|
import reactor.core.publisher.Mono;
|
|
|
|
|
|
|
|
public class SubStageGetterSet<T> implements SubStageGetter<Map<T, Nothing>, DatabaseSetDictionary<T>> {
|
|
|
|
|
2021-09-02 17:15:40 +02:00
|
|
|
private final SerializerFixedBinaryLength<T> keySerializer;
|
2021-02-04 00:48:49 +01:00
|
|
|
|
2021-09-02 17:15:40 +02:00
|
|
|
public SubStageGetterSet(SerializerFixedBinaryLength<T> keySerializer) {
|
2021-02-04 00:48:49 +01:00
|
|
|
this.keySerializer = keySerializer;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Mono<DatabaseSetDictionary<T>> subStage(LLDictionary dictionary,
|
|
|
|
@Nullable CompositeSnapshot snapshot,
|
2021-08-31 09:14:46 +02:00
|
|
|
Mono<Send<Buffer>> prefixKeyMono) {
|
2021-08-22 18:20:05 +02:00
|
|
|
return Mono.usingWhen(prefixKeyMono,
|
|
|
|
prefixKey -> Mono
|
2021-08-31 09:14:46 +02:00
|
|
|
.fromSupplier(() -> DatabaseSetDictionary.tail(dictionary, prefixKey, keySerializer)),
|
|
|
|
prefixKey -> Mono.fromRunnable(prefixKey::close)
|
2021-08-22 18:20:05 +02:00
|
|
|
);
|
2021-02-04 00:48:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2021-03-14 13:24:46 +01:00
|
|
|
public boolean isMultiKey() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2021-02-04 00:48:49 +01:00
|
|
|
public int getKeyBinaryLength() {
|
|
|
|
return keySerializer.getSerializedBinaryLength();
|
|
|
|
}
|
|
|
|
}
|