aboutsummaryrefslogtreecommitdiffstats
path: root/documentapi/src/main/java/com/yahoo/documentapi/VisitorControlSession.java
blob: d89e0abb817101cbe1b549398868b01b3d6ee97e (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
42
43
44
45
46
47
48
49
50
51
52
53
54
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.documentapi;

/**
 * Superclass for document <i>visiting</i> functionality - accessing
 * documents in an order decided by the document repository. This allows much
 * higher read throughput than random access.
 * <p>
 * The class supplies an interface for functions that are common for different
 * kinds of visitor sessions, such as acking visitor data and aborting the
 * session.
 *
 * @author Håkon Humberset
 */
public interface VisitorControlSession {

    /**
     * Acknowledges a response previously retrieved by the <code>getNext</code>
     * method.
     *
     * @param token The ack token. You must get this from the visitor response
     *              returned by the <code>getNext</code> method.
     */
    void ack(AckToken token);

    /**
     * Aborts the session.
     */
    void abort();

    /**
     * Returns the next response of this session. This method returns immediately.
     *
     * @return the next response, or null if no response is ready at this time
     */
    VisitorResponse getNext();

    /**
     * Returns the next response of this session. This will block until a response is ready
     * or until the given timeout is reached
     *
     * @param timeoutMilliseconds the max time to wait for a response. If the number is 0, this will block
     *                            without any timeout limit
     * @return the next response, or null if no response becomes ready before the timeout expires
     * @throws InterruptedException if this thread is interrupted while waiting
     */
    VisitorResponse getNext(int timeoutMilliseconds) throws InterruptedException;

    /**
     * Destroys this session and frees up any resources it has held.
     */
    void destroy();

}