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

org.apache.ratis.thirdparty.io.grpc.stub.StreamObserver Maven / Gradle / Ivy

There is a newer version: 1.0.6
Show newest version
/*
 * Copyright 2014 The gRPC Authors
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.apache.ratis.thirdparty.io.grpc.stub;

/**
 * Receives notifications from an observable stream of messages.
 *
 * 

It is used by both the client stubs and service implementations for sending or receiving * stream messages. It is used for all {@link org.apache.ratis.thirdparty.io.grpc.MethodDescriptor.MethodType}, including * {@code UNARY} calls. For outgoing messages, a {@code StreamObserver} is provided by the GRPC * library to the application. For incoming messages, the application implements the * {@code StreamObserver} and passes it to the GRPC library for receiving. * *

Implementations are not required to be thread-safe (but should be * * thread-compatible). Separate {@code StreamObserver}s do * not need to be synchronized together; incoming and outgoing directions are independent. * Since individual {@code StreamObserver}s are not thread-safe, if multiple threads will be * writing to a {@code StreamObserver} concurrently, the application must synchronize calls. * *

This API is asynchronous, so methods may return before the operation completes. The API * provides no guarantees for how quickly an operation will complete, so utilizing flow control via * {@link ClientCallStreamObserver} and {@link ServerCallStreamObserver} to avoid excessive * buffering is recommended for streaming RPCs. gRPC's implementation of {@code onError()} on * client-side causes the RPC to be cancelled and discards all messages, so completes quickly. * *

gRPC guarantees it does not block on I/O in its implementation, but applications are allowed * to perform blocking operations in their implementations. However, doing so will delay other * callbacks because the methods cannot be called concurrently. */ public interface StreamObserver { /** * Receives a value from the stream. * *

Can be called many times but is never called after {@link #onError(Throwable)} or {@link * #onCompleted()} are called. * *

Unary calls must invoke onNext at most once. Clients may invoke onNext at most once for * server streaming calls, but may receive many onNext callbacks. Servers may invoke onNext at * most once for client streaming calls, but may receive many onNext callbacks. * *

If an exception is thrown by an implementation the caller is expected to terminate the * stream by calling {@link #onError(Throwable)} with the caught exception prior to * propagating it. * * @param value the value passed to the stream */ void onNext(V value); /** * Receives a terminating error from the stream. * *

May only be called once and if called it must be the last method called. In particular if an * exception is thrown by an implementation of {@code onError} no further calls to any method are * allowed. * *

{@code t} should be a {@link org.apache.ratis.thirdparty.io.grpc.StatusException} or {@link * org.apache.ratis.thirdparty.io.grpc.StatusRuntimeException}, but other {@code Throwable} types are possible. Callers should * generally convert from a {@link org.apache.ratis.thirdparty.io.grpc.Status} via {@link org.apache.ratis.thirdparty.io.grpc.Status#asException()} or * {@link org.apache.ratis.thirdparty.io.grpc.Status#asRuntimeException()}. Implementations should generally convert to a * {@code Status} via {@link org.apache.ratis.thirdparty.io.grpc.Status#fromThrowable(Throwable)}. * * @param t the error occurred on the stream */ void onError(Throwable t); /** * Receives a notification of successful stream completion. * *

May only be called once and if called it must be the last method called. In particular if an * exception is thrown by an implementation of {@code onCompleted} no further calls to any method * are allowed. */ void onCompleted(); }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy