com.oracle.coherence.client.StreamStreamObserver Maven / Gradle / Ivy
/*
* Copyright (c) 2000, 2023, Oracle and/or its affiliates.
*
* Licensed under the Universal Permissive License v 1.0 as shown at
* https://oss.oracle.com/licenses/upl.
*/
package com.oracle.coherence.client;
import io.grpc.stub.StreamObserver;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CompletableFuture;
/**
* A {@link StreamObserver} that collects all of its responses into a {@link List} and then completes a {@link
* CompletableFuture} when the observer completes.
*
* @param the response type
*
* @author Jonathan Knight 2020.09.21
* @since 20.06
*/
public class StreamStreamObserver
extends BaseFutureStreamObserver
{
// ----- accessors ------------------------------------------------------
public CompletableFuture> future()
{
return f_future;
}
// ----- StreamStreamObserver methods -----------------------------------
@Override
public void onNext(T value)
{
list.add(value);
}
@Override
public void onCompleted()
{
f_future.complete(list);
}
// ----- data members ---------------------------------------------------
private final CompletableFuture> f_future = new CompletableFuture<>();
private final List list = new ArrayList<>();
}