summaryrefslogtreecommitdiffstats
path: root/container-search/src/main/java/com/yahoo/search/dispatch/CloseableChannel.java
blob: 3f5ebe53d0d1470ea25c42e35024dcb146856fb8 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
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.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;

/**
 * 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 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;

    /** Retrieve document summaries for the unfilled hits in the given {@link Result} */
    public abstract void partialFill(Result result, String summaryClass);

    protected abstract void closeChannel();

    private Runnable teardown = null;

    public void teardown(Runnable teardown) {
        this.teardown = teardown;
    }

    @Override
    public final void close() {
        if (teardown != null) {
            teardown.run();
            teardown = null;
        }
        closeChannel();
    }
}