com.oracle.coherence.grpc.client.common.StreamStreamObserver Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of coherence-grpc-client-common Show documentation
Show all versions of coherence-grpc-client-common Show documentation
Oracle Coherence Community Edition
The newest version!
/*
* Copyright (c) 2000, 2024, 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.grpc.client.common;
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<>();
}