Class ServletServerBuilder


  • @ExperimentalApi("https://github.com/grpc/grpc-java/issues/5066")
    @NotThreadSafe
    public final class ServletServerBuilder
    extends ForwardingServerBuilder<ServletServerBuilder>
    Builder to build a gRPC server that can run as a servlet. This is for advanced custom settings. Normally, users should consider extending the out-of-box GrpcServlet directly instead.

    The API is experimental. The authors would like to know more about the real usecases. Users are welcome to provide feedback by commenting on the tracking issue.

    • Field Detail

      • maxInboundMessageSize

        int maxInboundMessageSize
      • scheduler

        private java.util.concurrent.ScheduledExecutorService scheduler
      • internalCaller

        private boolean internalCaller
      • usingCustomScheduler

        private boolean usingCustomScheduler
    • Constructor Detail

      • ServletServerBuilder

        public ServletServerBuilder()
    • Method Detail

      • build

        public Server build()
        Builds a gRPC server that can run as a servlet.

        The returned server will not be started or bound to a port.

        Users should not call this method directly. Instead users should call buildServletAdapter() which internally will call build() and start() appropriately.

        Overrides:
        build in class ForwardingServerBuilder<ServletServerBuilder>
        Returns:
        a new Server
        Throws:
        java.lang.IllegalStateException - if this method is called by users directly
      • useTransportSecurity

        public ServletServerBuilder useTransportSecurity​(java.io.File certChain,
                                                         java.io.File privateKey)
        Throws UnsupportedOperationException. TLS should be configured by the servlet container.
        Overrides:
        useTransportSecurity in class ForwardingServerBuilder<ServletServerBuilder>
        Parameters:
        certChain - file containing the full certificate chain
        privateKey - file containing the private key
        Returns:
        this
      • maxInboundMessageSize

        public ServletServerBuilder maxInboundMessageSize​(int bytes)
        Description copied from class: ServerBuilder
        Sets the maximum message size allowed to be received on the server. If not called, defaults to 4 MiB. The default provides protection to servers who haven't considered the possibility of receiving large messages while trying to be large enough to not be hit in normal usage.

        This method is advisory, and implementations may decide to not enforce this. Currently, the only known transport to not enforce this is InProcessServer.

        Overrides:
        maxInboundMessageSize in class ForwardingServerBuilder<ServletServerBuilder>
        Parameters:
        bytes - the maximum number of bytes a single message can be.
        Returns:
        this
      • scheduledExecutorService

        public ServletServerBuilder scheduledExecutorService​(java.util.concurrent.ScheduledExecutorService scheduler)
        Provides a custom scheduled executor service to the server builder.
        Returns:
        this