2021-07-10 20:52:01 +02:00
|
|
|
package it.cavallium.dbengine.database.memory;
|
|
|
|
|
2021-10-30 11:13:46 +02:00
|
|
|
import io.micrometer.core.instrument.MeterRegistry;
|
2021-07-10 20:52:01 +02:00
|
|
|
import it.cavallium.dbengine.database.LLDatabaseConnection;
|
|
|
|
import it.cavallium.dbengine.database.LLKeyValueDatabase;
|
|
|
|
import it.cavallium.dbengine.database.LLLuceneIndex;
|
|
|
|
import it.cavallium.dbengine.database.disk.LLLocalLuceneIndex;
|
2021-10-13 12:25:32 +02:00
|
|
|
import it.cavallium.dbengine.lucene.LuceneHacks;
|
2022-07-23 02:42:48 +02:00
|
|
|
import it.cavallium.dbengine.lucene.LuceneUtils;
|
2022-03-05 15:46:40 +01:00
|
|
|
import it.cavallium.dbengine.rpc.current.data.ByteBuffersDirectory;
|
2022-03-02 12:34:30 +01:00
|
|
|
import it.cavallium.dbengine.rpc.current.data.Column;
|
|
|
|
import it.cavallium.dbengine.rpc.current.data.DatabaseOptions;
|
2022-03-05 15:46:40 +01:00
|
|
|
import it.cavallium.dbengine.rpc.current.data.IndicizerAnalyzers;
|
|
|
|
import it.cavallium.dbengine.rpc.current.data.IndicizerSimilarities;
|
|
|
|
import it.cavallium.dbengine.rpc.current.data.LuceneIndexStructure;
|
|
|
|
import it.cavallium.dbengine.rpc.current.data.LuceneOptions;
|
|
|
|
import it.cavallium.dbengine.rpc.current.data.LuceneOptionsBuilder;
|
2021-07-10 20:52:01 +02:00
|
|
|
import java.util.List;
|
2021-11-21 12:31:23 +01:00
|
|
|
import java.util.concurrent.atomic.AtomicBoolean;
|
|
|
|
import java.util.concurrent.atomic.AtomicReference;
|
2021-10-13 00:23:56 +02:00
|
|
|
import org.jetbrains.annotations.Nullable;
|
2021-07-10 20:52:01 +02:00
|
|
|
|
|
|
|
public class LLMemoryDatabaseConnection implements LLDatabaseConnection {
|
|
|
|
|
2021-11-21 12:31:23 +01:00
|
|
|
private final AtomicBoolean connected = new AtomicBoolean();
|
2021-10-30 11:13:46 +02:00
|
|
|
private final MeterRegistry meterRegistry;
|
2021-07-10 20:52:01 +02:00
|
|
|
|
2023-02-09 23:34:25 +01:00
|
|
|
public LLMemoryDatabaseConnection(MeterRegistry meterRegistry) {
|
2021-10-30 11:13:46 +02:00
|
|
|
this.meterRegistry = meterRegistry;
|
2021-07-10 20:52:01 +02:00
|
|
|
}
|
|
|
|
|
2021-10-30 11:13:46 +02:00
|
|
|
@Override
|
|
|
|
public MeterRegistry getMeterRegistry() {
|
|
|
|
return meterRegistry;
|
|
|
|
}
|
|
|
|
|
2021-07-10 20:52:01 +02:00
|
|
|
@Override
|
2023-02-09 23:34:25 +01:00
|
|
|
public LLDatabaseConnection connect() {
|
|
|
|
if (!connected.compareAndSet(false, true)) {
|
|
|
|
throw new IllegalStateException("Already connected");
|
|
|
|
}
|
|
|
|
return this;
|
2021-07-10 20:52:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2023-02-09 23:34:25 +01:00
|
|
|
public LLKeyValueDatabase getDatabase(String name,
|
2021-07-10 20:52:01 +02:00
|
|
|
List<Column> columns,
|
|
|
|
DatabaseOptions databaseOptions) {
|
2023-02-09 23:34:25 +01:00
|
|
|
return new LLMemoryKeyValueDatabase(meterRegistry, name, columns);
|
2021-07-10 20:52:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2023-02-09 23:34:25 +01:00
|
|
|
public LLLuceneIndex getLuceneIndex(String clusterName,
|
2022-03-05 15:46:40 +01:00
|
|
|
LuceneIndexStructure indexStructure,
|
2021-07-10 20:52:01 +02:00
|
|
|
IndicizerAnalyzers indicizerAnalyzers,
|
|
|
|
IndicizerSimilarities indicizerSimilarities,
|
2022-03-05 15:46:40 +01:00
|
|
|
LuceneOptions luceneOptions,
|
2021-10-13 00:23:56 +02:00
|
|
|
@Nullable LuceneHacks luceneHacks) {
|
2022-02-26 22:51:22 +01:00
|
|
|
var memoryLuceneOptions = LuceneOptionsBuilder
|
2022-03-05 15:46:40 +01:00
|
|
|
.builder(luceneOptions)
|
2022-02-26 22:51:22 +01:00
|
|
|
.directoryOptions(new ByteBuffersDirectory())
|
|
|
|
.build();
|
2023-02-09 23:34:25 +01:00
|
|
|
return new LLLocalLuceneIndex(meterRegistry,
|
|
|
|
clusterName,
|
|
|
|
0,
|
|
|
|
indicizerAnalyzers,
|
|
|
|
indicizerSimilarities,
|
|
|
|
memoryLuceneOptions,
|
|
|
|
luceneHacks
|
|
|
|
);
|
2021-07-10 20:52:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2023-02-09 23:34:25 +01:00
|
|
|
public void disconnect() {
|
|
|
|
connected.compareAndSet(true, false);
|
2021-07-10 20:52:01 +02:00
|
|
|
}
|
|
|
|
}
|