|
| 1 | +/*+***************************************************************************** |
| 2 | + * ___ _ ____ ____ |
| 3 | + * / _ \ _ _ ___ ___| |_| _ \| __ ) |
| 4 | + * | | | | | | |/ _ \/ __| __| | | | _ \ |
| 5 | + * | |_| | |_| | __/\__ \ |_| |_| | |_) | |
| 6 | + * \__\_\\__,_|\___||___/\__|____/|____/ |
| 7 | + * |
| 8 | + * Copyright (c) 2014-2019 Appsicle |
| 9 | + * Copyright (c) 2019-2026 QuestDB |
| 10 | + * |
| 11 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 12 | + * you may not use this file except in compliance with the License. |
| 13 | + * You may obtain a copy of the License at |
| 14 | + * |
| 15 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 16 | + * |
| 17 | + * Unless required by applicable law or agreed to in writing, software |
| 18 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 19 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 20 | + * See the License for the specific language governing permissions and |
| 21 | + * limitations under the License. |
| 22 | + * |
| 23 | + ******************************************************************************/ |
| 24 | + |
| 25 | +package io.questdb.client; |
| 26 | + |
| 27 | +import java.util.concurrent.TimeUnit; |
| 28 | + |
| 29 | +/** |
| 30 | + * Async handle for a submitted {@link Query}. Returned by {@link Query#submit()}. |
| 31 | + * <p> |
| 32 | + * Lifecycle: the Completion is allocated once as a field on the per-thread |
| 33 | + * {@link Query} instance and is reused on every {@code submit()}. It is |
| 34 | + * single-flight: a new {@code submit()} cannot be issued on the same {@link Query} |
| 35 | + * until the previous Completion resolves (via {@link #await()}, |
| 36 | + * {@link #await(long, TimeUnit)} returning {@code true}, or an explicit |
| 37 | + * {@link #cancel()} that races to terminal). |
| 38 | + * <p> |
| 39 | + * Signaling: the Completion is signaled from the I/O thread of the pooled |
| 40 | + * query client when the handler's terminal callback ({@code onEnd}, |
| 41 | + * {@code onError}, or {@code onExecDone}) returns. |
| 42 | + */ |
| 43 | +public interface Completion { |
| 44 | + |
| 45 | + /** |
| 46 | + * Blocks until the query completes. Rethrows any server-reported failure |
| 47 | + * as a {@link QueryException}. Returns normally on success. |
| 48 | + * |
| 49 | + * @throws QueryException if the server reported an error or |
| 50 | + * {@link #cancel()} won the race |
| 51 | + * @throws InterruptedException if the calling thread is interrupted |
| 52 | + * while waiting |
| 53 | + */ |
| 54 | + void await() throws InterruptedException; |
| 55 | + |
| 56 | + /** |
| 57 | + * Blocks up to the given timeout. Returns {@code true} if the query |
| 58 | + * completed, {@code false} on timeout. |
| 59 | + * |
| 60 | + * @throws QueryException if the server reported an error or |
| 61 | + * {@link #cancel()} won the race |
| 62 | + * @throws InterruptedException if the calling thread is interrupted |
| 63 | + * while waiting |
| 64 | + */ |
| 65 | + boolean await(long timeout, TimeUnit unit) throws InterruptedException; |
| 66 | + |
| 67 | + /** |
| 68 | + * Requests cancellation of the in-flight query. The handler's |
| 69 | + * {@code onError} fires with a cancellation status. No-op if the query |
| 70 | + * has already completed. |
| 71 | + */ |
| 72 | + void cancel(); |
| 73 | + |
| 74 | + /** |
| 75 | + * Returns true once the query has terminated (success, error, or cancel |
| 76 | + * acknowledged). |
| 77 | + */ |
| 78 | + boolean isDone(); |
| 79 | +} |
0 commit comments