blob: 0063ec0e990cfc17a3069dc518e66521acb58f23 (
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
|
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.clustercontroller.utils.communication.async;
/**
* Utility class in order to wrap com.yahoo.vespa.clustercontroller.utils.communication.async operation callbacks. Useful when translating com.yahoo.vespa.clustercontroller.utils.communication.async operations returning JSON to com.yahoo.vespa.clustercontroller.utils.communication.async operations returning specific values.
*/
public abstract class RedirectedAsyncOperation<S, T> implements AsyncOperation<T> {
protected final AsyncOperation<S> source;
private final AsyncOperationListenImpl<T> listenImpl;
public RedirectedAsyncOperation(AsyncOperation<S> source) {
this.source = source;
this.listenImpl = new AsyncOperationListenImpl<>(this);
source.register(new AsyncCallback<S>() {
@Override
public void done(AsyncOperation<S> op) { notifyDone(); }
});
}
private void notifyDone() {
listenImpl.notifyListeners();
}
@Override
public String getName() { return source.getName(); }
@Override
public String getDescription() { return source.getDescription(); }
@Override
public boolean cancel() { return source.cancel(); }
@Override
public boolean isCanceled() { return source.isCanceled(); }
@Override
public boolean isDone() { return source.isDone(); }
@Override
public boolean isSuccess() { return source.isSuccess(); }
@Override
public Double getProgress() { return source.getProgress(); }
@Override
public Exception getCause() { return source.getCause(); }
@Override
public void register(AsyncCallback<T> callback) {
listenImpl.register(callback);
}
@Override
public void unregister(AsyncCallback<T> callback) {
listenImpl.unregister(callback);
}
}
|