All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.yamcs.client.base.ResponseObserver Maven / Gradle / Ivy

There is a newer version: 5.10.8
Show 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"));
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy