aboutsummaryrefslogtreecommitdiffstats
path: root/documentapi/src/main/java/com/yahoo/documentapi/AsyncSession.java
blob: c297b61fc9130ee9c11f2fc4efcbbc2da22d25b5 (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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.documentapi;

import com.yahoo.document.Document;
import com.yahoo.document.DocumentId;
import com.yahoo.document.DocumentPut;
import com.yahoo.document.DocumentRemove;
import com.yahoo.document.DocumentUpdate;
import com.yahoo.documentapi.messagebus.protocol.DocumentProtocol;

import static com.yahoo.documentapi.DocumentOperationParameters.parameters;

/**
 * <p>A session for asynchronous access to a document repository.
 * This class provides document repository writes and random access with high
 * throughput.</p>
 *
 * <p>All operations which are <i>accepted</i> by an async session will cause one or more
 * {@link Response responses} to be returned within the timeout limit. When an operation fails,
 * the response will contain the argument which was submitted to the operation.</p>
 *
 * @author bratseth
 */
public interface AsyncSession extends Session {

    /**
     * <p>Puts a document. This method returns immediately.</p>
     *
     * <p>If this result is a success, this
     * call will cause one or more {@link DocumentResponse} objects to appear within the timeout time of this session.
     * The response returned later will either be a success, or contain the document submitted here.
     * If it was not a success, this method has no further effects.</p>
     *
     * @param document the Document to put
     * @return the synchronous result of this operation
     */
    Result put(Document document);

    /**
     * <p>Puts a document, with optional conditions on the operation. This method returns immediately.</p>
     *
     * <p>If this result is a success, this
     * call will cause one or more {@link DocumentResponse} objects to appear within the timeout time of this session.
     * The response returned later will either be a success, or contain the document submitted here.
     * If it was not a success, this method has no further effects.</p>
     *
     * @param documentPut the DocumentPut to perform
     * @return the synchronous result of this operation
     */
    default Result put(DocumentPut documentPut) {
        return put(documentPut, parameters());
    }

    /**
     * <p>Puts a document, with optional conditions on the operation. This method returns immediately.</p>
     *
     * <p>If this result is a success, this
     * call will cause one or more {@link DocumentResponse} objects to appear within the timeout time of this session.
     * The response returned later will either be a success, or contain the document submitted here.
     * If it was not a success, this method has no further effects.</p>
     *
     * @param documentPut the DocumentPut to perform
     * @param parameters parameters for the operation
     * @return the synchronous result of this operation
     */
    default Result put(DocumentPut documentPut, DocumentOperationParameters parameters) {
        return put(documentPut.getDocument());
    }

    /**
     * <p>Gets a document. This method returns immediately.</p>
     *
     * <p>If this result is a success, this
     * call will cause one or more {@link DocumentResponse} objects to appear within the timeout time of this session.
     * The response returned later will contain the requested document if it is a success.
     * If it was not a success, this method has no further effects.</p>
     *
     * @param id the id of the document to get
     * @return the synchronous result of this operation
     * @throws UnsupportedOperationException if this access implementation does not support retrieving
     */
    Result get(DocumentId id);

    /**
     * <p>Gets a document. This method returns immediately.</p>
     *
     * <p>If this result is a success, this
     * call will cause one or more {@link DocumentResponse} objects to appear within the timeout time of this session.
     * The response returned later will contain the requested document if it is a success.
     * If it was not a success, this method has no further effects.</p>
     *
     * @param id the id of the document to get
     * @param parameters parameters for the operation
     * @return the synchronous result of this operation
     * @throws UnsupportedOperationException if this access implementation does not support retrieving
     */
    default Result get(DocumentId id, DocumentOperationParameters parameters) {
        return get(id);
    }


    /**
     * <p>Removes a document if it is present. This method returns immediately.</p>
     *
     * <p>If this result is a success, this
     * call will cause one or more {@link RemoveResponse} objects to appear within the timeout time of this session.
     * The response returned later will either be a success, or contain the document id submitted here.
     * If it was not a success, this method has no further effects.</p>
     *
     * @param id the id of the document to remove
     * @return the synchronous result of this operation
     * @throws UnsupportedOperationException if this access implementation does not support removal
     */
    Result remove(DocumentId id);

    /**
     * <p>Removes a document if it is present. This method returns immediately.</p>
     *
     * <p>If this result is a success, this
     * call will cause one or more {@link DocumentIdResponse} objects to appear within the timeout time of this session.
     * The response returned later will either be a success, or contain the document id submitted here.
     * If it was not a success, this method has no further effects.</p>
     *
     * @param id the id of the document to remove
     * @param parameters parameters for the operation
     * @return the synchronous result of this operation
     * @throws UnsupportedOperationException if this access implementation does not support removal
     */
    default Result remove(DocumentId id, DocumentOperationParameters parameters) {
        return remove(new DocumentRemove(id), parameters);
    }

    /**
     * <p>Removes a document if it is present. This method returns immediately.</p>
     *
     * <p>If this result is a success, this
     * call will cause one or more {@link DocumentIdResponse} objects to appear within the timeout time of this session.
     * The response returned later will either be a success, or contain the document id submitted here.
     * If it was not a success, this method has no further effects.</p>
     *
     * @param remove the document remove operation
     * @param parameters parameters for the operation
     * @return the synchronous result of this operation
     * @throws UnsupportedOperationException if this access implementation does not support removal
     */
    default Result remove(DocumentRemove remove, DocumentOperationParameters parameters) {
        return remove(remove.getId());
    }

    /**
     * <p>Updates a document. This method returns immediately.</p>
     *
     * <p>If this result is a success, this
     * call will cause one or more {@link DocumentUpdateResponse} within the timeout time of this session.
     * The returned response returned later will either be a success or contain the update submitted here.
     * If it was not a success, this method has no further effects.</p>
     *
     * @param update the updates to perform
     * @return the synchronous result of this operation
     * @throws UnsupportedOperationException if this access implementation does not support update
     */
    Result update(DocumentUpdate update);

    /**
     * <p>Updates a document. This method returns immediately.</p>
     *
     * <p>If this result is a success, this
     * call will cause one or more {@link DocumentUpdateResponse} within the timeout time of this session.
     * The returned response returned later will either be a success or contain the update submitted here.
     * If it was not a success, this method has no further effects.</p>
     *
     * @param update the updates to perform
     * @param parameters parameters for the operation
     * @return the synchronous result of this operation
     * @throws UnsupportedOperationException if this access implementation does not support update
     */
    default Result update(DocumentUpdate update, DocumentOperationParameters parameters) {
        return update(update);
    }

    /**
     * Returns the current send window size of the session.
     *
     * @return Returns the window size.
     */
    double getCurrentWindowSize();


}