Package io.grpc
gRPC is based on a client-server model of remote procedure calls. A client creates a channel which is connected to a server. RPCs are initiated from the client and sent to the server which then responds back to the client. When the client and server are done sending messages, they half close their respective connections. The RPC is complete as soon as the server closes.
To send an RPC, first create a Channel using ManagedChannelBuilder.forTarget(java.lang.String). When using auto generate Protobuf stubs, the stub class
will have constructors for wrapping the channel. These include newBlockingStub,
newStub, and newFutureStub which you can use based on your design. The stub is the
primary way a client interacts with a server.
To receive RPCs, create a Server using ServerBuilder.forPort(int).
The Protobuf stub will contain an abstract class called AbstractFoo, where Foo is the name of
your service. Extend this class, and pass an instance of it to ServerBuilder.addService(io.grpc.ServerServiceDefinition). Once your server is built, call Server.start()
to begin accepting RPCs.
Both Clients and Servers should use a custom Executor. The gRPC
runtime includes a default executor that eases testing and examples, but is not ideal for use in
a production environment. See the associated documentation in the respective builders.
Clients and Servers can also be shutdown gracefully using the shutdown method. The API
to conduct an orderly shutdown is modeled from the ExecutorService.
gRPC also includes support for more advanced features, such as name resolution, load balancing, bidirectional streaming, health checking, and more. See the relative methods in the client and server builders.
Development of gRPC is done primary on Github at https://github.com/grpc/grpc-java, where the gRPC team welcomes contributions and bug reports. There is also a mailing list at grpc-io if you have questions about gRPC.
-
ClassDescriptionAn immutable type-safe container of attributes.The helper class to build an Attributes instance.Key for an key-value pair.A binary log that can be installed on a channel or server.Provides a way to bind instance of service implementation to server.Tagging interface for MetricInstruments that can be used with batch callbacks.Carries credential data that will be propagated to the server via request metadata for each RPC.The outlet of the produced headers.The request-related information passed to
CallCredentials.applyRequestMetadata().The collection of runtime options for a new RPC call.Key for a key-value pair.A virtual connection to a conceptual endpoint, to perform RPCs.Represents a security configuration to be used for channels.A Channel-specific logger provided by GRPC library toLoadBalancerimplementations.Log levels.Provides a list ofChannelCredentials, where any one may be used.Provides a list ofServerCredentials, where any one may be used.ClientCall<ReqT,RespT> An instance of a call to a remote method.Callbacks for receiving metadata, response messages and completion status from the server.Interface for intercepting outgoing calls before they are dispatched by aChannel.Utility methods for working withClientInterceptors.ClientInterceptors.CheckedForwardingClientCall<ReqT,RespT> AForwardingClientCallthat delivers exceptions from its start logic to the call listener.StreamTracerfor the client-side.Factory class forClientStreamTracer.Information about a stream.BuildsClientStreamTracer.StreamInfoobjects.Listens on the client transport life-cycle events.Encloses classes related to the compression and decompression of messages.A gzip compressor and decompressor.The "identity", or "none" codec.Uses multipleCallCredentialsas if they were one.ChannelCredentialswhich use per-RPCCallCredentials.Represents a message compressor.Encloses classes related to the compression and decompression of messages.The connectivity states.A tuple of aConnectivityStateand its associatedStatus.A context propagation mechanism which can carry scoped-values across API boundaries and between threads.A context which inherits cancellation from its parent but which can also be independently cancelled and which will propagate cancellation to its descendants.A listener notified on context cancellation.Context.Key<T>Key for indexing values stored in a context.Defines the mechanisms for attaching and detaching the "current" context.Utility methods for working withContexts in GRPC.An absolute point in time, generally for tracking when a task should be completed.Time source representing nanoseconds since fixed but arbitrary point in time.Represents a message decompressor.Encloses classes related to the compression and decompression of messages.An extension ofInputStreamthat allows the underlying data source to be detached and transferred to a new instance of the same kind.Represents a double-valued counter metric instrument.Represents a double-valued histogram metric instrument.Extension to anInputStreamor alike by adding a method that transfers all content to anOutputStream.A group ofSocketAddresses that are considered equivalent when channel makes connections.Annotation forEquivalentAddressGroup's attributes.Indicates a public API that can change at any time, and has no guarantee of API stability and backward-compatibility.ForwardingChannelBuilder<T extends ForwardingChannelBuilder<T>>AManagedChannelBuilderthat delegates all its builder methods to another builder by default.ForwardingChannelBuilder2<T extends ManagedChannelBuilder<T>>AManagedChannelBuilderthat delegates all its builder methods to another builder by default.ForwardingClientCall<ReqT,RespT> AClientCallwhich forwards all of its methods to anotherClientCall.ForwardingClientCall.SimpleForwardingClientCall<ReqT,RespT> A simplified version ofForwardingClientCallwhere subclasses can pass in aClientCallas the delegate.ForwardingClientCallListener<RespT>AClientCall.Listenerwhich forwards all of its methods to anotherClientCall.Listener.A simplified version ofForwardingClientCallListenerwhere subclasses can pass in aClientCall.Listeneras the delegate.ForwardingServerBuilder<T extends ServerBuilder<T>>AServerBuilderthat delegates all its builder methods to another builder by default.ForwardingServerCall<ReqT,RespT> AServerCallwhich forwards all of its methods to anotherServerCall.ForwardingServerCall.SimpleForwardingServerCall<ReqT,RespT> A simplified version ofForwardingServerCallwhere subclasses can pass in aServerCallas the delegate.AServerCall.Listenerwhich forwards all of its methods to anotherServerCall.Listenerof matching parameterized types.A simplified version ofForwardingServerCallListenerwhere subclasses can pass in aServerCall.Listeneras the delegate.Stuff that are part of the public API but are not bound to particular classes, e.g., static methods, constants, attribute and context keys.Annotation for transport attributes.Registry of services and their methods used by servers to dispatching incoming calls.Extension to anInputStreamwhose content can be accessed asByteBuffers.AnProxiedSocketAddressfor making a connection to an endpoint via an HTTP CONNECT proxy.The builder forHttpConnectProxiedSocketAddress.No client identity, authentication, or encryption is to be used.No server identity or encryption is to be used.Annotates a program element (class, method, package, etc) which is internal to gRPC, not part of the public API, and should not be used by users of gRPC.Internal accessor forCallOptions.This is an internal API.A data class to represent a channel's stats.A data class to represent transport stats.Internal accessor.Per method config selector that the channel or load balancers will use to choose the appropriate config or take config related actions for an RPC.Internal access to Configurator API.Access internal global configurators.Private accessor for decompressor registries.An internal class.All known transports.An internal class.Internal accessors forManagedChannelBuilder.Internal accessor forManagedChannelProvider.InternalMetadataaccessor.A specialized plain ASCII marshaller.Accesses internal data and methods.Accessor to internal methods ofServerInterceptors.Internal accessor forServerProvider.Accesses internal data.An internal class.AnInputStreamor alike whose total number of bytes that can be read is known upfront.A pluggable component that receives resolved addresses fromNameResolverand provides the channel a usable subchannel when asked.Arguments for creating aLoadBalancer.Subchannel.Key for a key-value pair.Deprecated.Factory to createLoadBalancerinstance.A picker that always returns the same result.Provides essentials for LoadBalancer implementations.Receives information about the pick being chosen.A balancing decision made bySubchannelPickerfor an RPC.Provides arguments for aLoadBalancer.SubchannelPicker.pickSubchannel(LoadBalancer.PickSubchannelArgs).Represents a combination of the resolved server address, associated attributes and a load balancing policy config.Builder forLoadBalancer.ResolvedAddresses.A logical connection to a server, or a group of equivalent servers represented by anEquivalentAddressGroup.The main balancing logic.Receives state changes for oneLoadBalancer.Subchannel.Provider ofLoadBalancers.Registry ofLoadBalancerProviders.Represents a long-valued counter metric instrument.Represents a long-valued gauge metric instrument.Represents a long-valued histogram metric instrument.AChannelthat provides lifecycle management.ManagedChannelBuilder<T extends ManagedChannelBuilder<T>>A builder forManagedChannelinstances.Internal-only.Provider of managed channels for transport agnostic consumption.Thrown when no suitableManagedChannelProviderobjects can be found.Registry ofManagedChannelProviders.Thrown when no suitableManagedChannelProviderobjects can be found.Provides access to read and write metadata values to be exchanged during a call.Marshaller for metadata values that are serialized into ASCII strings.Marshaller for metadata values that are serialized into raw binary.Marshaller for metadata values that are serialized to an InputStream.Metadata.Key<T>Key for metadata entries.MethodDescriptor<ReqT,RespT> Description of a remote method used byChannelto initiate a call.MethodDescriptor.Builder<ReqT,RespT> A builder for aMethodDescriptor.A typed abstraction over message serialization and deserialization, a.k.a.The call type of a method.A marshaller that uses a fixed instance of the type it produces.A marshaller that supports retrieving its type parameterTat runtime.Represents a metric instrument.A registry for globally registered metric instruments.An interface used for recording gRPC metrics.Callback to record gauge values.Recorder for instrument values produced by a batch callback.A handle to a registration, that allows unregistration.An internal interface representing a receiver or aggregator of gRPC metrics data.A pluggable component that resolves a targetURIand return addresses to the caller.Information that aNameResolver.Factoryuses to create aNameResolver.Builder forNameResolver.Args.Represents either a successfully parsed service config, containing all necessary parts to be later applied by the channel, or a Status containing the error encountered while parsing.Factory that createsNameResolverinstances.Receives address updates.Receives address updates.Represents the results from a Name Resolver.A builder forNameResolver.ResolutionResult.Annotation for name resolution result attributes.Parses and validates service configuration.Provider of name resolvers for name agnostic consumption.Registry ofNameResolverProviders.An address that contains the information about making a connection via a proxy.A utility class to detect which proxy, if any, should be used for a givenSocketAddress.The level of security guarantee in communications.Server for listening for and dispatching incoming calls.ServerBuilder<T extends ServerBuilder<T>>A builder forServerinstances.ServerCall<ReqT,RespT> Encapsulates a single call received from a remote client.ServerCall.Listener<ReqT>Callbacks for consuming incoming RPC messages.Defines what executor handles the server call, based on each RPC call information at runtime.ServerCallHandler<RequestT,ResponseT> Interface to initiate processing of incoming remote calls.Represents a security configuration to be used for servers.Interface for intercepting incoming calls before they are dispatched byServerCallHandler.Utility methods for working withServerInterceptors.ServerMethodDefinition<ReqT,RespT> Definition of a method exposed by aServer.Provider of servers for transport agnostic consumption.Registry ofServerProviders.Thrown when no suitableServerProviderobjects can be found.Definition of a service to be exposed via a Server.Builder for constructing Service instances.Listens to events on a stream to collect metrics.ServerStreamTracer.ServerCallInfo<ReqT,RespT> A data class with info about the startedServerCall.Listens on server transport life-cycle events, with the capability to read and/or change transport attributes.Descriptor for a service.A builder for aServiceDescriptor.Defines the status of an operation by providing a standardStatus.Codein conjunction with an optional descriptive message.The set of canonical status codes.Statusin Exception form, for propagating Status information via exceptions.Statusin RuntimeException form, for propagating Status information via exceptions.Listens to events on a stream to collect metrics.A synchronization context is a queue of tasks that run in sequence.Allows the user to check the status and/or cancel a task scheduled bySynchronizationContext.schedule(java.lang.Runnable, long, java.util.concurrent.TimeUnit, java.util.concurrent.ScheduledExecutorService).TLS credentials, providing server authentication and encryption.Builder forTlsChannelCredentials.Features to understand TLS configuration.TLS credentials, providing server identity and encryption.Builder forTlsServerCredentials.The level of authentication the server should expect from the client.Features to understand TLS configuration.
new FixedResultPicker(PickResult.withError(error))instead.