Package io.grpc

Class ClientCall.Listener<T>

  • Direct Known Subclasses:
    ForwardingClientCallListener
    Enclosing class:
    ClientCall<ReqT,​RespT>

    public abstract static class ClientCall.Listener<T>
    extends java.lang.Object
    Callbacks for receiving metadata, response messages and completion status from the server.

    Implementations are free to block for extended periods of time. Implementations are not required to be thread-safe.

    • Constructor Summary

      Constructors 
      Constructor Description
      Listener()  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void onClose​(Status status, Metadata trailers)
      The ClientCall has been closed.
      void onHeaders​(Metadata headers)
      The response headers have been received.
      void onMessage​(T message)
      A response message has been received.
      void onReady()
      This indicates that the ClientCall may now be capable of sending additional messages (via ClientCall.sendMessage(ReqT)) without requiring excessive buffering internally.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • Listener

        public Listener()
    • Method Detail

      • onHeaders

        public void onHeaders​(Metadata headers)
        The response headers have been received. Headers always precede messages.

        Since Metadata is not thread-safe, the caller must not access (read or write) headers after this point.

        Parameters:
        headers - containing metadata sent by the server at the start of the response.
      • onMessage

        public void onMessage​(T message)
        A response message has been received. May be called zero or more times depending on whether the call response is empty, a single message or a stream of messages.
        Parameters:
        message - returned by the server
      • onClose

        public void onClose​(Status status,
                            Metadata trailers)
        The ClientCall has been closed. Any additional calls to the ClientCall will not be processed by the server. No further receiving will occur and no further notifications will be made.

        Since Metadata is not thread-safe, the caller must not access (read or write) trailers after this point.

        If status returns false for Status.isOk(), then the call failed. An additional block of trailer metadata may be received at the end of the call from the server. An empty Metadata object is passed if no trailers are received.

        Parameters:
        status - the result of the remote call.
        trailers - metadata provided at call completion.
      • onReady

        public void onReady()
        This indicates that the ClientCall may now be capable of sending additional messages (via ClientCall.sendMessage(ReqT)) without requiring excessive buffering internally. This event is just a suggestion and the application is free to ignore it, however doing so may result in excessive buffering within the ClientCall.

        Because there is a processing delay to deliver this notification, it is possible for concurrent writes to cause isReady() == false within this callback. Handle "spurious" notifications by checking isReady()'s current value instead of assuming it is now true. If isReady() == false the normal expectations apply, so there would be another onReady() callback.

        If the type of a call is either MethodDescriptor.MethodType.UNARY or MethodDescriptor.MethodType.SERVER_STREAMING, this callback may not be fired. Calls that send exactly one message should not await this callback.