2021-03-27 03:35:27 +01:00
|
|
|
package it.cavallium.dbengine.database;
|
|
|
|
|
2021-08-04 01:12:39 +02:00
|
|
|
import it.cavallium.dbengine.client.query.current.data.TotalHitsCount;
|
2021-08-24 11:53:19 +02:00
|
|
|
import it.cavallium.dbengine.lucene.searcher.LuceneSearchResult;
|
|
|
|
import java.util.Objects;
|
|
|
|
import org.warp.commonutils.log.Logger;
|
|
|
|
import org.warp.commonutils.log.LoggerFactory;
|
2021-03-27 03:35:27 +01:00
|
|
|
import reactor.core.publisher.Flux;
|
2021-07-10 20:52:01 +02:00
|
|
|
import reactor.core.publisher.Mono;
|
2021-03-27 03:35:27 +01:00
|
|
|
|
2021-08-24 11:53:19 +02:00
|
|
|
public final class LLSearchResultShard {
|
|
|
|
|
|
|
|
private static final Logger logger = LoggerFactory.getLogger(LLSearchResultShard.class);
|
|
|
|
|
|
|
|
private volatile boolean releaseCalled;
|
|
|
|
|
|
|
|
private final Flux<LLKeyScore> results;
|
|
|
|
private final TotalHitsCount totalHitsCount;
|
|
|
|
private final Mono<Void> release;
|
|
|
|
|
|
|
|
public LLSearchResultShard(Flux<LLKeyScore> results, TotalHitsCount totalHitsCount, Mono<Void> release) {
|
|
|
|
this.results = results;
|
|
|
|
this.totalHitsCount = totalHitsCount;
|
|
|
|
this.release = Mono.fromRunnable(() -> {
|
|
|
|
if (releaseCalled) {
|
2021-08-24 11:55:33 +02:00
|
|
|
logger.warn(this.getClass().getName() + "::release has been called twice!");
|
2021-08-24 11:53:19 +02:00
|
|
|
}
|
|
|
|
releaseCalled = true;
|
|
|
|
}).then(release);
|
|
|
|
}
|
|
|
|
|
|
|
|
public Flux<LLKeyScore> results() {
|
|
|
|
return results;
|
|
|
|
}
|
|
|
|
|
|
|
|
public TotalHitsCount totalHitsCount() {
|
|
|
|
return totalHitsCount;
|
|
|
|
}
|
|
|
|
|
|
|
|
public Mono<Void> release() {
|
|
|
|
return release;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean equals(Object obj) {
|
|
|
|
if (obj == this)
|
|
|
|
return true;
|
|
|
|
if (obj == null || obj.getClass() != this.getClass())
|
|
|
|
return false;
|
|
|
|
var that = (LLSearchResultShard) obj;
|
|
|
|
return Objects.equals(this.results, that.results) && Objects.equals(this.totalHitsCount, that.totalHitsCount)
|
|
|
|
&& Objects.equals(this.release, that.release);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int hashCode() {
|
|
|
|
return Objects.hash(results, totalHitsCount, release);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String toString() {
|
|
|
|
return "LLSearchResultShard[" + "results=" + results + ", " + "totalHitsCount=" + totalHitsCount + ", " + "release="
|
|
|
|
+ release + ']';
|
|
|
|
}
|
|
|
|
|
|
|
|
@SuppressWarnings("deprecation")
|
|
|
|
@Override
|
|
|
|
protected void finalize() throws Throwable {
|
|
|
|
if (!releaseCalled) {
|
2021-08-24 11:55:33 +02:00
|
|
|
logger.warn(this.getClass().getName() + "::release has not been called before class finalization!");
|
2021-08-24 11:53:19 +02:00
|
|
|
}
|
|
|
|
super.finalize();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|