org.yamcs.client.base.ResponseObserver Maven / Gradle / Ivy
The newest version!
package org.yamcs.client.base;
import java.util.concurrent.CompletableFuture;
import org.yamcs.api.Observer;
/**
* An observer that completes a future based on a single response.
*/
public class ResponseObserver implements Observer {
private CompletableFuture future;
public ResponseObserver(CompletableFuture future) {
this.future = future;
}
@Override
public void next(T message) {
future.complete(message);
}
@Override
public void completeExceptionally(Throwable t) {
future.completeExceptionally(t);
}
@Override
public void complete() {
if (!future.isDone()) {
future.completeExceptionally(new IllegalStateException("no response received"));
}
}
}