blob: 0471e05a5f9e81fe472a61d2c72eccb3ee4f2d01 (
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
|
// 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.yahoo.jdisc.Response;
import java.util.concurrent.Callable;
/**
* This is a convenient subclass of {@link ResponseDispatch} that implements the {@link Callable} interface. This
* should be used in place of {@link ResponseDispatch} if you intend to schedule its execution. Because {@link #call()}
* does not return until the entirety of the {@link Response} and its content have been consumed, you can use the
* <tt>Future</tt> return value of <tt>ExecutorService.submit(Callable)</tt> to wait for it to complete.
*
* @author Simon Thoresen Hult
*/
public abstract class CallableResponseDispatch extends ResponseDispatch implements Callable<Boolean> {
private final ResponseHandler handler;
/**
* Constructs a new instances of this class over the given {@link ResponseHandler}. Invoking {@link #call()} will
* dispatch to this handler.
*
* @param handler The ResponseHandler to dispatch to.
*/
public CallableResponseDispatch(ResponseHandler handler) {
this.handler = handler;
}
@Override
public final Boolean call() throws Exception {
return dispatch(handler).get();
}
}
|