Package com.google.api.gax.grpc
Class GrpcResponseMetadata
- java.lang.Object
-
- com.google.api.gax.grpc.GrpcResponseMetadata
-
- All Implemented Interfaces:
ResponseMetadataHandler
public class GrpcResponseMetadata extends Object implements ResponseMetadataHandler
GrpcResponseMetadata provides a mechanism to access the headers and trailers returned by a gRPC client method.NOTE: the GrpcResponseMetadata class is not thread-safe and should NOT be re-used for multiple calls. A new instance of GrpcResponseMetadata should be constructed for each call that requires metadata to be accessed.
Example usage:
GrpcResponseMetadata grpcResponseMetadata = new GrpcResponseMetadata(); Foo foo = client.getFooCallable().call(getFooRequest, grpcResponseMetadata.createContextWithHandlers()); Metadata headers = grpcResponseMetadata.getMetadata(); Metadata trailers = grpcResponseMetadata.getTrailingMetadata();
-
-
Constructor Summary
Constructors Constructor Description GrpcResponseMetadata()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description GrpcCallContextaddHandlers(com.google.api.gax.rpc.ApiCallContext apiCallContext)Constructs a new call context from an existing ApiCallContext, and sets the CallOptions to add handlers to retrieve the headers and trailers, and make them available via the getMetadata and getTrailingMetadata methods.GrpcCallContextcreateContextWithHandlers()Constructs a new call context and sets the CallOptions to add handlers to retrieve the headers and trailers, and make them available via the getMetadata and getTrailingMetadata methods.io.grpc.MetadatagetMetadata()Returns the headers from the gRPC method as Metadata.io.grpc.MetadatagetTrailingMetadata()Returns the trailers from the gRPC method as Metadata.voidonHeaders(io.grpc.Metadata metadata)Handle the headers returned by an RPC.voidonTrailers(io.grpc.Metadata metadata)Handle the trailers returned by an RPC.
-
-
-
Method Detail
-
addHandlers
public GrpcCallContext addHandlers(com.google.api.gax.rpc.ApiCallContext apiCallContext)
Constructs a new call context from an existing ApiCallContext, and sets the CallOptions to add handlers to retrieve the headers and trailers, and make them available via the getMetadata and getTrailingMetadata methods.
-
createContextWithHandlers
public GrpcCallContext createContextWithHandlers()
Constructs a new call context and sets the CallOptions to add handlers to retrieve the headers and trailers, and make them available via the getMetadata and getTrailingMetadata methods.
-
getMetadata
public io.grpc.Metadata getMetadata()
Returns the headers from the gRPC method as Metadata. If the call has not completed, will return null.
-
getTrailingMetadata
public io.grpc.Metadata getTrailingMetadata()
Returns the trailers from the gRPC method as Metadata. If the call has not completed, will return null.
-
onHeaders
public void onHeaders(io.grpc.Metadata metadata)
Description copied from interface:ResponseMetadataHandlerHandle the headers returned by an RPC.- Specified by:
onHeadersin interfaceResponseMetadataHandler
-
onTrailers
public void onTrailers(io.grpc.Metadata metadata)
Description copied from interface:ResponseMetadataHandlerHandle the trailers returned by an RPC.- Specified by:
onTrailersin interfaceResponseMetadataHandler
-
-