public abstract static class ForwardingServerCall.SimpleForwardingServerCall<ReqT,RespT> extends ForwardingServerCall<ReqT,RespT>
ForwardingServerCall
where subclasses can pass in a ServerCall
as the delegate.ForwardingServerCall.SimpleForwardingServerCall<ReqT,RespT>
ServerCall.Listener<ReqT>
Modifier | Constructor and Description |
---|---|
protected |
SimpleForwardingServerCall(ServerCall<ReqT,RespT> delegate) |
Modifier and Type | Method and Description |
---|---|
void |
close(Status status,
Metadata trailers)
Close the call with the provided status.
|
protected ServerCall<ReqT,RespT> |
delegate()
Returns the delegated
ServerCall . |
Attributes |
getAttributes()
Returns properties of a single call.
|
String |
getAuthority()
Gets the authority this call is addressed to.
|
MethodDescriptor<ReqT,RespT> |
getMethodDescriptor()
The
MethodDescriptor for the call. |
boolean |
isCancelled()
Returns
true when the call is cancelled and the server is encouraged to abort
processing to save resources, since the client will not be processing any further methods. |
boolean |
isReady()
If
true , indicates that the call is capable of sending additional messages
without requiring excessive buffering internally. |
void |
request(int numMessages)
Requests up to the given number of messages from the call to be delivered to
ServerCall.Listener.onMessage(Object) . |
void |
sendHeaders(Metadata headers)
Send response header metadata prior to sending a response message.
|
void |
setCompression(String compressor)
Sets the compression algorithm for this call.
|
void |
setMessageCompression(boolean enabled)
Enables per-message compression, if an encoding type has been negotiated.
|
String |
toString() |
sendMessage
getSecurityLevel
protected SimpleForwardingServerCall(ServerCall<ReqT,RespT> delegate)
protected ServerCall<ReqT,RespT> delegate()
ForwardingServerCall
ServerCall
.delegate
in class ForwardingServerCall<ReqT,RespT>
public MethodDescriptor<ReqT,RespT> getMethodDescriptor()
ServerCall
MethodDescriptor
for the call.getMethodDescriptor
in class ServerCall<ReqT,RespT>
public void request(int numMessages)
ServerCall
ServerCall.Listener.onMessage(Object)
. Once numMessages
have been delivered
no further request messages will be delivered until more messages are requested by
calling this method again.
Servers use this mechanism to provide back-pressure to the client for flow-control.
This method is safe to call from multiple threads without external synchronization.
request
in class ServerCall<ReqT,RespT>
numMessages
- the requested number of messages to be delivered to the listener.public void sendHeaders(Metadata headers)
ServerCall
ServerCall.sendMessage(RespT)
or ServerCall.close(io.grpc.Status, io.grpc.Metadata)
.
Since Metadata
is not thread-safe, the caller must not access (read or write) headers
after this point.
sendHeaders
in class ServerCall<ReqT,RespT>
headers
- metadata to send prior to any response body.public boolean isReady()
ServerCall
true
, indicates that the call is capable of sending additional messages
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 call.
If false
, ServerCall.Listener.onReady()
will be called after isReady()
transitions to true
.
This abstract class's implementation always returns true
. Implementations generally
override the method.
isReady
in class ServerCall<ReqT,RespT>
public void close(Status status, Metadata trailers)
ServerCall
Status.isOk()
is false
, then the call is said to have failed.
If no errors or cancellations are known to have occurred, then a ServerCall.Listener.onComplete()
notification should be expected, independent of status
. Otherwise ServerCall.Listener.onCancel()
has been or will be called.
Since Metadata
is not thread-safe, the caller must not access (read or write) trailers
after this point.
This method implies the caller completed processing the RPC, but it does not imply the RPC
is complete. The call implementation will need additional time to complete the RPC and during
this time the client is still able to cancel the request or a network error might cause the
RPC to fail. If you wish to know when the call is actually completed/closed, you have to use
ServerCall.Listener.onComplete()
or ServerCall.Listener.onCancel()
instead. This method is not
necessarily invoked when Listener.onCancel() is called.
close
in class ServerCall<ReqT,RespT>
public boolean isCancelled()
ServerCall
true
when the call is cancelled and the server is encouraged to abort
processing to save resources, since the client will not be processing any further methods.
Cancellations can be caused by timeouts, explicit cancel by client, network errors, and
similar.
This method may safely be called concurrently from multiple threads.
isCancelled
in class ServerCall<ReqT,RespT>
@ExperimentalApi(value="https://github.com/grpc/grpc-java/issues/1703") public void setMessageCompression(boolean enabled)
ServerCall
setMessageCompression
in class ServerCall<ReqT,RespT>
@ExperimentalApi(value="https://github.com/grpc/grpc-java/issues/1704") public void setCompression(String compressor)
ServerCall
ServerCall.sendHeaders(io.grpc.Metadata)
.
The compressor to use will be looked up in the CompressorRegistry
. Default gRPC
servers support the "gzip" compressor.
It is safe to call this even if the client does not support the compression format chosen. The implementation will handle negotiation with the client and may fall back to no compression.
setCompression
in class ServerCall<ReqT,RespT>
compressor
- the name of the compressor to use.@ExperimentalApi(value="https://github.com/grpc/grpc-java/issues/1779") public Attributes getAttributes()
ServerCall
Attributes originate from the transport and can be altered by ServerTransportFilter
.
getAttributes
in class ServerCall<ReqT,RespT>
null
Attributes containerpublic String getAuthority()
ServerCall
getAuthority
in class ServerCall<ReqT,RespT>
null
if not available.