Class ServerCallImpl<ReqT,RespT>
- java.lang.Object
-
- io.grpc.ServerCall<ReqT,RespT>
-
- io.grpc.internal.ServerCallImpl<ReqT,RespT>
-
final class ServerCallImpl<ReqT,RespT> extends ServerCall<ReqT,RespT>
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static class
ServerCallImpl.ServerStreamListenerImpl<ReqT>
All of these callbacks are assumed to called on an application thread, and the caller is responsible for handling thrown exceptions.-
Nested classes/interfaces inherited from class io.grpc.ServerCall
ServerCall.Listener<ReqT>
-
-
Field Summary
Fields Modifier and Type Field Description private boolean
cancelled
private boolean
closeCalled
private Compressor
compressor
private CompressorRegistry
compressorRegistry
private Context.CancellableContext
context
private DecompressorRegistry
decompressorRegistry
private static java.util.logging.Logger
log
private byte[]
messageAcceptEncoding
private boolean
messageSent
private MethodDescriptor<ReqT,RespT>
method
(package private) static java.lang.String
MISSING_RESPONSE
private boolean
sendHeadersCalled
private CallTracer
serverCallTracer
private ServerStream
stream
private io.perfmark.Tag
tag
(package private) static java.lang.String
TOO_MANY_RESPONSES
-
Constructor Summary
Constructors Constructor Description ServerCallImpl(ServerStream stream, MethodDescriptor<ReqT,RespT> method, Metadata inboundHeaders, Context.CancellableContext context, DecompressorRegistry decompressorRegistry, CompressorRegistry compressorRegistry, CallTracer serverCallTracer, io.perfmark.Tag tag)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close(Status status, Metadata trailers)
Close the call with the provided status.private void
closeInternal(Status status, Metadata trailers)
Attributes
getAttributes()
Returns properties of a single call.java.lang.String
getAuthority()
Gets the authority this call is addressed to.MethodDescriptor<ReqT,RespT>
getMethodDescriptor()
TheMethodDescriptor
for the call.SecurityLevel
getSecurityLevel()
Returns the level of security guarantee in communicationsprivate void
handleInternalError(java.lang.Throwable internalError)
Close theServerStream
because an internal error occurred.boolean
isCancelled()
Returnstrue
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()
Iftrue
, indicates that the call is capable of sending additional messages without requiring excessive buffering internally.(package private) ServerStreamListener
newServerStreamListener(ServerCall.Listener<ReqT> listener)
void
request(int numMessages)
Requests up to the given number of messages from the call to be delivered toServerCall.Listener.onMessage(Object)
.void
sendHeaders(Metadata headers)
Send response header metadata prior to sending a response message.private void
sendHeadersInternal(Metadata headers)
void
sendMessage(RespT message)
Send a response message.private void
sendMessageInternal(RespT message)
void
setCompression(java.lang.String compressorName)
Sets the compression algorithm for this call.void
setMessageCompression(boolean enable)
Enables per-message compression, if an encoding type has been negotiated.void
setOnReadyThreshold(int numBytes)
A hint to the call that specifies how many bytes must be queued beforeServerCall.isReady()
will return false.
-
-
-
Field Detail
-
log
private static final java.util.logging.Logger log
-
TOO_MANY_RESPONSES
static final java.lang.String TOO_MANY_RESPONSES
- See Also:
- Constant Field Values
-
MISSING_RESPONSE
static final java.lang.String MISSING_RESPONSE
- See Also:
- Constant Field Values
-
stream
private final ServerStream stream
-
method
private final MethodDescriptor<ReqT,RespT> method
-
tag
private final io.perfmark.Tag tag
-
context
private final Context.CancellableContext context
-
messageAcceptEncoding
private final byte[] messageAcceptEncoding
-
decompressorRegistry
private final DecompressorRegistry decompressorRegistry
-
compressorRegistry
private final CompressorRegistry compressorRegistry
-
serverCallTracer
private CallTracer serverCallTracer
-
cancelled
private volatile boolean cancelled
-
sendHeadersCalled
private boolean sendHeadersCalled
-
closeCalled
private boolean closeCalled
-
compressor
private Compressor compressor
-
messageSent
private boolean messageSent
-
-
Constructor Detail
-
ServerCallImpl
ServerCallImpl(ServerStream stream, MethodDescriptor<ReqT,RespT> method, Metadata inboundHeaders, Context.CancellableContext context, DecompressorRegistry decompressorRegistry, CompressorRegistry compressorRegistry, CallTracer serverCallTracer, io.perfmark.Tag tag)
-
-
Method Detail
-
request
public void request(int numMessages)
Description copied from class:ServerCall
Requests up to the given number of messages from the call to be delivered toServerCall.Listener.onMessage(Object)
. OncenumMessages
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.
- Specified by:
request
in classServerCall<ReqT,RespT>
- Parameters:
numMessages
- the requested number of messages to be delivered to the listener.
-
sendHeaders
public void sendHeaders(Metadata headers)
Description copied from class:ServerCall
Send response header metadata prior to sending a response message. This method may only be called once and cannot be called after calls toServerCall.sendMessage(RespT)
orServerCall.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.- Specified by:
sendHeaders
in classServerCall<ReqT,RespT>
- Parameters:
headers
- metadata to send prior to any response body.
-
sendHeadersInternal
private void sendHeadersInternal(Metadata headers)
-
sendMessage
public void sendMessage(RespT message)
Description copied from class:ServerCall
Send a response message. Messages are the primary form of communication associated with RPCs. Multiple response messages may exist for streaming calls.- Specified by:
sendMessage
in classServerCall<ReqT,RespT>
- Parameters:
message
- response message.
-
sendMessageInternal
private void sendMessageInternal(RespT message)
-
setMessageCompression
public void setMessageCompression(boolean enable)
Description copied from class:ServerCall
Enables per-message compression, if an encoding type has been negotiated. If no message encoding has been negotiated, this is a no-op. By default per-message compression is enabled, but may not have any effect if compression is not enabled on the call.- Overrides:
setMessageCompression
in classServerCall<ReqT,RespT>
-
setOnReadyThreshold
public void setOnReadyThreshold(int numBytes)
Description copied from class:ServerCall
A hint to the call that specifies how many bytes must be queued beforeServerCall.isReady()
will return false. A call may ignore this property if unsupported. This may only be set before any messages are sent.- Overrides:
setOnReadyThreshold
in classServerCall<ReqT,RespT>
- Parameters:
numBytes
- The number of bytes that must be queued. Must be a positive integer.
-
setCompression
public void setCompression(java.lang.String compressorName)
Description copied from class:ServerCall
Sets the compression algorithm for this call. This compression is utilized for sending. If the server does not support the compression algorithm, the call will fail. This method may only be called beforeServerCall.sendHeaders(io.grpc.Metadata)
. The compressor to use will be looked up in theCompressorRegistry
. 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.
- Overrides:
setCompression
in classServerCall<ReqT,RespT>
- Parameters:
compressorName
- the name of the compressor to use.
-
isReady
public boolean isReady()
Description copied from class:ServerCall
Iftrue
, 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 afterisReady()
transitions totrue
.This abstract class's implementation always returns
true
. Implementations generally override the method.- Overrides:
isReady
in classServerCall<ReqT,RespT>
-
close
public void close(Status status, Metadata trailers)
Description copied from class:ServerCall
Close the call with the provided status. No further sending or receiving will occur. IfStatus.isOk()
isfalse
, 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 ofstatus
. OtherwiseServerCall.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()
orServerCall.Listener.onCancel()
instead. This method is not necessarily invoked when Listener.onCancel() is called.- Specified by:
close
in classServerCall<ReqT,RespT>
-
isCancelled
public boolean isCancelled()
Description copied from class:ServerCall
Returnstrue
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.
- Specified by:
isCancelled
in classServerCall<ReqT,RespT>
-
newServerStreamListener
ServerStreamListener newServerStreamListener(ServerCall.Listener<ReqT> listener)
-
getAttributes
public Attributes getAttributes()
Description copied from class:ServerCall
Returns properties of a single call.Attributes originate from the transport and can be altered by
ServerTransportFilter
.- Overrides:
getAttributes
in classServerCall<ReqT,RespT>
- Returns:
- non-
null
Attributes container
-
getAuthority
public java.lang.String getAuthority()
Description copied from class:ServerCall
Gets the authority this call is addressed to.- Overrides:
getAuthority
in classServerCall<ReqT,RespT>
- Returns:
- the authority string.
null
if not available.
-
getMethodDescriptor
public MethodDescriptor<ReqT,RespT> getMethodDescriptor()
Description copied from class:ServerCall
TheMethodDescriptor
for the call.- Specified by:
getMethodDescriptor
in classServerCall<ReqT,RespT>
-
getSecurityLevel
public SecurityLevel getSecurityLevel()
Description copied from class:ServerCall
Returns the level of security guarantee in communicationsDetermining the level of security offered by the transport for RPCs on server-side. This can be approximated by looking for the SSLSession, but that doesn't work for ALTS and maybe some future TLS approaches. May return a lower security level when it cannot be determined precisely.
- Overrides:
getSecurityLevel
in classServerCall<ReqT,RespT>
- Returns:
- non-
null
SecurityLevel enum
-
handleInternalError
private void handleInternalError(java.lang.Throwable internalError)
Close theServerStream
because an internal error occurred. Allow the application to run until completion, but silently ignore interactions with theServerStream
from now on.
-
-