2021-01-31 00:36:21 +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-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;
|
|
|
|
import it.cavallium.dbengine.database.serialization.SerializerFixedBinaryLength;
|
2021-05-03 00:29:26 +02:00
|
|
|
import java.util.List;
|
2021-01-31 00:36:21 +01:00
|
|
|
import java.util.Map;
|
|
|
|
import org.jetbrains.annotations.Nullable;
|
|
|
|
import reactor.core.publisher.Flux;
|
|
|
|
import reactor.core.publisher.Mono;
|
|
|
|
|
2021-02-02 18:42:18 +01:00
|
|
|
public class SubStageGetterMap<T, U> implements SubStageGetter<Map<T, U>, DatabaseMapDictionary<T, U>> {
|
2021-01-31 00:36:21 +01:00
|
|
|
|
2021-09-02 17:15:40 +02:00
|
|
|
private final SerializerFixedBinaryLength<T> keySerializer;
|
|
|
|
private final Serializer<U> valueSerializer;
|
2021-01-31 00:36:21 +01:00
|
|
|
|
2021-09-02 17:15:40 +02:00
|
|
|
public SubStageGetterMap(SerializerFixedBinaryLength<T> keySerializer,
|
|
|
|
Serializer<U> valueSerializer) {
|
2021-01-31 19:52:47 +01:00
|
|
|
this.keySerializer = keySerializer;
|
|
|
|
this.valueSerializer = valueSerializer;
|
2021-01-31 00:36:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2021-02-02 18:42:18 +01:00
|
|
|
public Mono<DatabaseMapDictionary<T, U>> subStage(LLDictionary dictionary,
|
2021-01-31 00:36:21 +01:00
|
|
|
@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
|
|
|
|
.fromSupplier(() -> DatabaseMapDictionary
|
|
|
|
.tail(dictionary,
|
2021-08-31 09:14:46 +02:00
|
|
|
prefixKey,
|
2021-08-22 18:20:05 +02:00
|
|
|
keySerializer,
|
|
|
|
valueSerializer
|
|
|
|
)
|
2021-08-28 22:42:51 +02:00
|
|
|
),
|
2021-08-31 09:14:46 +02:00
|
|
|
prefixKey -> Mono.fromRunnable(prefixKey::close)
|
2021-08-22 18:20:05 +02:00
|
|
|
);
|
2021-02-02 15:36:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2021-03-14 13:24:46 +01:00
|
|
|
public boolean isMultiKey() {
|
2021-03-14 13:08:03 +01:00
|
|
|
return true;
|
2021-02-02 15:36:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public int getKeyBinaryLength() {
|
|
|
|
return keySerializer.getSerializedBinaryLength();
|
2021-01-31 00:36:21 +01:00
|
|
|
}
|
|
|
|
}
|