Module io.jooby
Package io.jooby

Interface Server

All Known Implementing Classes:
Server.Base

public interface Server
Web server contract. Defines operations to start, join and stop a web server. Jooby comes with three web server implementation: Jetty, Netty and Undertow.

A web server is automatically discovered using the Java Service Loader API. All you need is to add the server dependency to your project classpath.

When service loader is not an option or do you want to manually bootstrap a server:


 Server server = new NettyServer(); // or JettyServer or UndertowServer

 App app = new App();

 server.start(app);

 ...

 server.stop();

 
Since:
2.0.0
Author:
edgar
  • Method Details

    • setOptions

      @NonNull Server setOptions(@NonNull ServerOptions options)
      Set server options.
      Parameters:
      options - Server options.
      Returns:
      This server.
    • getName

      @NonNull String getName()
      Get server name.
      Returns:
      Server name.
    • getOptions

      @NonNull ServerOptions getOptions()
      Get server options.
      Returns:
      Server options.
    • start

      @NonNull Server start(@NonNull Jooby application)
      Start an application.
      Parameters:
      application - Application to start.
      Returns:
      This server.
    • getLoggerOff

      @NonNull default List<String> getLoggerOff()
      Utility method to turn off odd logger. This help to ensure same startup log lines across server implementations.

      These logs are silent at application startup time.

      Returns:
      Name of the logs we want to temporarily silent.
    • stop

      @NonNull Server stop()
      Stop the server.
      Returns:
      Stop the server.
    • addConnectionLost

      static void addConnectionLost(@NonNull Predicate<Throwable> predicate)
      Add a connection lost predicate. On unexpected exception, this method allows to customize which error are considered connection lost. If the error is considered a connection lost, no log statement will be emitted by the application.
      Parameters:
      predicate - Customize connection lost error.
    • addAddressInUse

      static void addAddressInUse(@NonNull Predicate<Throwable> predicate)
      Add an address in use predicate. On unexpected exception, this method allows to customize which error are considered address in use. If the error is considered an address in use, no log statement will be emitted by the application.
      Parameters:
      predicate - Customize connection lost error.
    • connectionLost

      static boolean connectionLost(@Nullable Throwable cause)
      Test whenever the given exception is a connection-lost. Connection-lost exceptions don't generate log.error statements.
      Parameters:
      cause - Exception to check.
      Returns:
      True for connection lost.
    • isAddressInUse

      static boolean isAddressInUse(@Nullable Throwable cause)
      Whenever the given exception is an address already in use. This probably won't work in none English locale systems.
      Parameters:
      cause - Exception to check.
      Returns:
      True address already in use.