diff options
Diffstat (limited to 'container-search/src/main/java/com/yahoo/search/dispatch/CloseableChannel.java')
-rw-r--r-- | container-search/src/main/java/com/yahoo/search/dispatch/CloseableChannel.java | 53 |
1 files changed, 20 insertions, 33 deletions
diff --git a/container-search/src/main/java/com/yahoo/search/dispatch/CloseableChannel.java b/container-search/src/main/java/com/yahoo/search/dispatch/CloseableChannel.java index 643b8f81318..3f5ebe53d0d 100644 --- a/container-search/src/main/java/com/yahoo/search/dispatch/CloseableChannel.java +++ b/container-search/src/main/java/com/yahoo/search/dispatch/CloseableChannel.java @@ -1,54 +1,41 @@ // Copyright 2018 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.search.dispatch; -import com.yahoo.fs4.BasicPacket; -import com.yahoo.fs4.ChannelTimeoutException; -import com.yahoo.fs4.mplex.Backend; -import com.yahoo.fs4.mplex.FS4Channel; -import com.yahoo.fs4.mplex.InvalidChannelException; +import com.yahoo.fs4.QueryPacket; +import com.yahoo.prelude.fastsearch.CacheKey; import com.yahoo.search.Query; +import com.yahoo.search.Result; import java.io.Closeable; import java.io.IOException; -import java.util.Optional; /** + * CloseableChannel is an interface for running a search query and getting document summaries against some + * content node, node group or dispatcher while abstracting the specifics of the invocation target. + * * @author ollivir */ -public class CloseableChannel implements Closeable { - private FS4Channel channel; - private final Optional<Integer> distributionKey; +public abstract class CloseableChannel implements Closeable { + /** Retrieve the hits for the given {@link Query} */ + public abstract Result search(Query query, QueryPacket queryPacket, CacheKey cacheKey) throws IOException; - public CloseableChannel(Backend backend) { - this(backend, Optional.empty()); - } - - public CloseableChannel(Backend backend, Optional<Integer> distributionKey) { - this.channel = backend.openChannel(); - this.distributionKey = distributionKey; - } + /** Retrieve document summaries for the unfilled hits in the given {@link Result} */ + public abstract void partialFill(Result result, String summaryClass); - public void setQuery(Query query) { - channel.setQuery(query); - } + protected abstract void closeChannel(); - public boolean sendPacket(BasicPacket packet) throws InvalidChannelException, IOException { - return channel.sendPacket(packet); - } - - public BasicPacket[] receivePackets(long timeout, int packetCount) throws InvalidChannelException, ChannelTimeoutException { - return channel.receivePackets(timeout, packetCount); - } + private Runnable teardown = null; - public Optional<Integer> distributionKey() { - return distributionKey; + public void teardown(Runnable teardown) { + this.teardown = teardown; } @Override - public void close() { - if (channel != null) { - channel.close(); - channel = null; + public final void close() { + if (teardown != null) { + teardown.run(); + teardown = null; } + closeChannel(); } } |