S
- the concrete type of this stub.public abstract class AbstractStub<S extends AbstractStub<S>> extends Object
This is the base class of the stub classes from the generated code. It allows for reconfiguration, e.g., attaching interceptors to the stub.
Modifier | Constructor and Description |
---|---|
protected |
AbstractStub(Channel channel)
Constructor for use by subclasses, with the default
CallOptions . |
protected |
AbstractStub(Channel channel,
CallOptions callOptions)
Constructor for use by subclasses, with the default
CallOptions . |
Modifier and Type | Method and Description |
---|---|
protected abstract S |
build(Channel channel,
CallOptions callOptions)
Returns a new stub with the given channel for the provided method configurations.
|
CallOptions |
getCallOptions()
The
CallOptions of the stub. |
Channel |
getChannel()
The underlying channel of the stub.
|
S |
withCallCredentials(CallCredentials credentials)
Returns a new stub that uses the given call credentials.
|
S |
withChannel(Channel newChannel)
Returns a new stub that uses the given channel.
|
S |
withCompression(String compressorName)
Set's the compressor name to use for the call.
|
S |
withDeadline(Deadline deadline)
Returns a new stub with an absolute deadline.
|
S |
withDeadlineAfter(long duration,
TimeUnit unit)
Returns a new stub with a deadline that is after the given
duration from now. |
S |
withDeadlineNanoTime(Long deadlineNanoTime)
Deprecated.
Use
withDeadline(Deadline) instead. |
S |
withInterceptors(ClientInterceptor... interceptors)
Returns a new stub that has the given interceptors attached to the underlying channel.
|
<T> S |
withOption(CallOptions.Key<T> key,
T value)
Sets a custom option to be passed to client interceptors on the channel
ClientInterceptor via the CallOptions parameter. |
protected AbstractStub(Channel channel)
CallOptions
.channel
- the channel that this stub will use to do communicationsprotected AbstractStub(Channel channel, CallOptions callOptions)
CallOptions
.channel
- the channel that this stub will use to do communicationscallOptions
- the runtime call options to be applied to every call on this stubpublic final Channel getChannel()
public final CallOptions getCallOptions()
CallOptions
of the stub.protected abstract S build(Channel channel, CallOptions callOptions)
channel
- the channel that this stub will use to do communicationscallOptions
- the runtime call options to be applied to every call on this stubpublic final S withDeadline(@Nullable Deadline deadline)
This is mostly used for propagating an existing deadline. withDeadlineAfter(long, java.util.concurrent.TimeUnit)
is the
recommended way of setting a new deadline,
deadline
- the deadline or null
for unsetting the deadline.@Deprecated public final S withDeadlineNanoTime(@Nullable Long deadlineNanoTime)
withDeadline(Deadline)
instead.System.nanoTime()
.
This is mostly used for propagating an existing deadline. withDeadlineAfter(long, java.util.concurrent.TimeUnit)
is the
recommended way of setting a new deadline,
deadlineNanoTime
- nanoseconds in the clock as per System.nanoTime()
public final S withDeadlineAfter(long duration, TimeUnit unit)
duration
from now.@ExperimentalApi(value="https://github.com/grpc/grpc-java/issues/1704") public final S withCompression(String compressorName)
DecompressorRegistry
on the ManagedChannelBuilder
.compressorName
- the name (e.g. "gzip") of the compressor to use.public final S withChannel(Channel newChannel)
@ExperimentalApi(value="https://github.com/grpc/grpc-java/issues/1869") public final <T> S withOption(CallOptions.Key<T> key, T value)
ClientInterceptor
via the CallOptions parameter.key
- the option being setvalue
- the value for the keypublic final S withInterceptors(ClientInterceptor... interceptors)
@ExperimentalApi(value="https//github.com/grpc/grpc-java/issues/1914") public final S withCallCredentials(CallCredentials credentials)