Interface GrpcServer

All Known Implementing Classes:
JettyBackedGrpcServer

public interface GrpcServer
This interface handles the lifecycle of Netty and Jetty servers in a unified way, while still supporting the use cases that Deephaven expects:
  • Deephaven wants to initiate stop early in the shutdown process, and block on it after all services have begun to stop.
  • gRPC+Netty supports a non-blocking stop, a "stop now", and a pair of await methods, one of which takes a timeout.
  • gRPC+Jetty supports a blocking stop with a timeout, and a join() method.
In order to not block on the initial stop call, the Jetty implementation will run stop() in another thread. Since Jetty doesn't have an extra "shutdownNow" method, the Netty implementation will use the timeout in another thread to decide if it needs to invoke shutdownNow when normal shutdown is taking too long.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Server must stop accepting new streams, but let existing streams continue for now.
    int
    After the server is started, this will return the port it is using.
    void
    Blocks as long as the server is running, unless this thread is interrupted.
    static GrpcServer
    of(io.grpc.Server server)
     
    void
    Starts the server, if possible.
    void
    stopWithTimeout(long timeout, TimeUnit unit)
    Stops the server, using the specified timeout as a deadline.
  • Method Details

    • start

      void start() throws IOException
      Starts the server, if possible. Otherwise, throws an exception. If successful, returns.
      Throws:
      IOException - if there is an error on startup
    • join

      void join() throws InterruptedException
      Blocks as long as the server is running, unless this thread is interrupted. If stopWithTimeout has been called and the timeout has expired, this will return, and the server will be stopped.
      Throws:
      InterruptedException
    • beginShutdown

      void beginShutdown()
      Server must stop accepting new streams, but let existing streams continue for now.

      In theory the listening socket should be freed and available for another application to take it, but this is not rigorously tested.

      To complete shutdown, call stopWithTimeout() after any remaining calls have been completed to the server's satisfaction, which will terminate the remaining calls.
    • stopWithTimeout

      void stopWithTimeout(long timeout, TimeUnit unit)
      Stops the server, using the specified timeout as a deadline. Returns immediately. Call join() to block until this is completed.

      If pending calls do not matter, it is unnecessary to call beginShutdown() before this method.
      Parameters:
      timeout - time to allow for a graceful shutdown before giving up and halting
      unit - unit to apply to the timeout
    • getPort

      int getPort()
      After the server is started, this will return the port it is using.
      Returns:
      the tcp port that the server is listening on after it has started
    • of

      static GrpcServer of(io.grpc.Server server)