aboutsummaryrefslogtreecommitdiffstats
path: root/jdisc_core/src/main/java/com/yahoo/jdisc/handler/FutureCompletion.java
blob: e18c88382b629004e45b65edb2c205b9e92e4638 (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
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.jdisc.handler;

import com.google.common.util.concurrent.AbstractFuture;

/**
 * <p>This class provides an implementation of {@link CompletionHandler} that allows you to wait for either {@link
 * #completed()} or {@link #failed(Throwable)} to be called. If failed() was called, the corresponding Throwable will
 * be rethrown when calling either of the get() methods. Unless an exception is thrown, the get() methods will always
 * return Boolean.TRUE.</p>
 *
 * <p>Notice that calling {@link #cancel(boolean)} throws an UnsupportedOperationException.</p>
 *
 * @author Simon Thoresen
 */
public final class FutureCompletion extends AbstractFuture<Boolean> implements CompletionHandler {

    @Override
    public void completed() {
        set(true);
    }

    @Override
    public void failed(Throwable t) {
        setException(t);
    }

    @Override
    public final boolean cancel(boolean mayInterruptIfRunning) {
        throw new UnsupportedOperationException();
    }

    @Override
    public final boolean isCancelled() {
        return false;
    }
}