Class GrpcContext

java.lang.Object
com.codename1.backend.grpc.GrpcContext

public final class GrpcContext extends Object

What a gRPC handler can learn about its call and add to the answer: the request metadata, the deadline, whether the client went away, and response headers and trailers.

Declare it as the last parameter of a @GrpcService method to receive it.

  • Method Details

    • getMethod

      public String getMethod()
      Returns:
      the full method name, /package.Service/Method
    • get

      public String get(String name)
      A request metadata value. Names are lower case; a binary (-bin) value is returned as the base64 text it was sent as, see getBinary(String).
      Parameters:
      name - the header name
      Returns:
      the value or null
    • getBinary

      public byte[] getBinary(String name)
      A binary request metadata value, decoded.
      Parameters:
      name - a name ending in -bin
      Returns:
      the bytes, or null when absent or not base64
    • getMetadata

      public Map<String,String> getMetadata()
      Returns:
      every request metadata entry, read only
    • getRemainingMillis

      public long getRemainingMillis()
      Returns:
      milliseconds until the client's deadline, or -1 without one; 0 once it has passed
    • isDeadlineExceeded

      public boolean isDeadlineExceeded()
      Returns:
      whether the deadline has passed
    • isCancelled

      public boolean isCancelled()
      Returns:
      whether the client cancelled or the stream was reset
    • addHeader

      public void addHeader(String name, String value)
      Adds a response header. Only effective before the first response message is sent.
      Parameters:
      name - lower-case name
      value - the value
    • addTrailer

      public void addTrailer(String name, String value)
      Adds a response trailer, sent with the status.
      Parameters:
      name - lower-case name, not a grpc- reserved one
      value - the value
    • addBinaryTrailer

      public void addBinaryTrailer(String name, byte[] value)
      Adds a binary response trailer.
      Parameters:
      name - a name ending in -bin
      value - the bytes