Module io.jooby
Package io.jooby

Class ServerOptions

java.lang.Object
io.jooby.ServerOptions

public class ServerOptions extends Object
Available server options. To load server options from configuration files, just do:

 Optional<ServerOptions> serverOptions = ServerOptions.from(getEnvironment().getConfig());

 
Since:
2.0.0
Author:
edgar
  • Field Details

    • SERVER_PORT

      public static final int SERVER_PORT
      Default application port 8080 or the value of system property server.port .
    • SEVER_SECURE_PORT

      public static final int SEVER_SECURE_PORT
      Default application secure port 8443 or the value of system property server.securePort.
    • DEFAULT_COMPRESSION_LEVEL

      public static final int DEFAULT_COMPRESSION_LEVEL
      Default compression level for gzip.
      See Also:
    • _4KB

      public static final int _4KB
      4kb constant in bytes.
      See Also:
    • _8KB

      public static final int _8KB
      8kb constant in bytes.
      See Also:
    • _16KB

      public static final int _16KB
      16kb constant in bytes.
      See Also:
    • _10MB

      public static final int _10MB
      10mb constant in bytes.
      See Also:
    • IO_THREADS

      public static final int IO_THREADS
      Number of available threads, but never smaller than 2.
    • WORKER_THREADS

      public static final int WORKER_THREADS
      Number of worker (a.k.a application) threads. It is the number of processors multiply by 8.
  • Constructor Details

    • ServerOptions

      public ServerOptions()
  • Method Details

    • from

      @NonNull public static Optional<ServerOptions> from(@NonNull com.typesafe.config.Config conf)
      Creates server options from config object. The configuration options must provided entries like: server.port, server.ioThreads, etc...
      Parameters:
      conf - Configuration object.
      Returns:
      Server options.
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • setServer

      @NonNull public ServerOptions setServer(@NonNull String server)
      Set server name.
      Parameters:
      server - Name of the underlying server.
      Returns:
      This options.
    • getServer

      @NonNull public String getServer()
      Server name.
      Returns:
      Server name.
    • getPort

      public int getPort()
      Server HTTP port.
      Returns:
      Server HTTP port.
    • setPort

      @NonNull public ServerOptions setPort(int port)
      Set the server port (default is 8080). For random port use: 0.
      Parameters:
      port - Server port or 0 to pick a random port.
      Returns:
      This options.
    • getSecurePort

      @Nullable public Integer getSecurePort()
      HTTPs port or null.
      Returns:
      HTTPs port or null.
    • isSSLEnabled

      public boolean isSSLEnabled()
      True when SSL is enabled. Either bc the secure port or SSL options are set.
      Returns:
      True when SSL is enabled. Either bc the secure port or SSL options are set.
    • setSecurePort

      @NonNull public ServerOptions setSecurePort(@Nullable Integer securePort)
      Set HTTPs port.
      Parameters:
      securePort - Port number or 0 for random number.
      Returns:
      This options.
    • isHttpsOnly

      public boolean isHttpsOnly()
      Bind only https port. Default is false.
      Returns:
      True when only https is required.
    • setHttpsOnly

      @NonNull public ServerOptions setHttpsOnly(boolean httpsOnly)
      Bind only https port. Default is false.
      Parameters:
      httpsOnly - True to bind only HTTPS.
      Returns:
      This options.
    • getIoThreads

      public int getIoThreads()
      Number of IO threads used by the server. Required by Netty and Undertow.
      Returns:
      Number of IO threads used by the server. Required by Netty and Undertow.
    • getIoThreads

      public int getIoThreads(int defaultIoThreads)
      Number of IO threads used by the server. Required by Netty and Undertow.
      Parameters:
      defaultIoThreads - Default number of threads if none was set.
      Returns:
      Number of IO threads used by the server. Required by Netty and Undertow.
    • setIoThreads

      @NonNull public ServerOptions setIoThreads(int ioThreads)
      Set number of IO threads to use. Supported by Netty and Undertow.
      Parameters:
      ioThreads - Number of threads. Must be greater than 0.
      Returns:
      This options.
    • getWorkerThreads

      public int getWorkerThreads()
      Number of worker threads (a.k.a application) to use. These are the threads which are allowed to block.
      Returns:
      Number of worker threads (a.k.a application) to use. These are the threads which are allowed to block.
    • getWorkerThreads

      public int getWorkerThreads(int defaultWorkerThreads)
      Number of worker threads (a.k.a application) to use. These are the threads which are allowed to block.
      Parameters:
      defaultWorkerThreads - Default worker threads is none was set.
      Returns:
      Number of worker threads (a.k.a application) to use. These are the threads which are allowed to block.
    • setWorkerThreads

      @NonNull public ServerOptions setWorkerThreads(int workerThreads)
      Set number of worker threads (a.k.a application) to use. These are the threads which are allowed to block.
      Parameters:
      workerThreads - Number of worker threads to use.
      Returns:
      This options.
    • getCompressionLevel

      @Nullable public Integer getCompressionLevel()
      Indicates compression level to use while producing gzip responses.
      Returns:
      Compression level value between 0...9 or null when off.
    • setCompressionLevel

      @NonNull public ServerOptions setCompressionLevel(@Nullable Integer compressionLevel)
      Set compression level to use while producing gzip responses.

      Gzip is off by default (compression level is null).

      Parameters:
      compressionLevel - Value between 0..9 or null.
      Returns:
      This options.
    • getDefaultHeaders

      public boolean getDefaultHeaders()
      True if default headers: Date, Content-Type and Server are enabled.
      Returns:
      True if default headers: Date, Content-Type and Server are enabled.
    • setDefaultHeaders

      @NonNull public ServerOptions setDefaultHeaders(boolean defaultHeaders)
      Enabled/disabled default server headers: Date, Content-Type and Server. Enabled by default.
      Parameters:
      defaultHeaders - True for enabled.
      Returns:
      This options.
    • getBufferSize

      public int getBufferSize()
      Server buffer size in bytes. Default is: 16kb. Used for reading/writing data.
      Returns:
      Server buffer size in bytes. Default is: 16kb. Used for reading/writing data.
    • setBufferSize

      @NonNull public ServerOptions setBufferSize(int bufferSize)
      Set buffer size.
      Parameters:
      bufferSize - Buffer size.
      Returns:
      This options.
    • getMaxRequestSize

      public int getMaxRequestSize()
      Maximum request size in bytes. Request exceeding this value results in StatusCode.REQUEST_ENTITY_TOO_LARGE response. Default is 10mb.
      Returns:
      Maximum request size in bytes.
    • setMaxRequestSize

      @NonNull public ServerOptions setMaxRequestSize(int maxRequestSize)
      Set max request size in bytes.
      Parameters:
      maxRequestSize - Max request size in bytes.
      Returns:
      This options.
    • getHost

      public String getHost()
      Server host, defaults is 0.0.0.0.
      Returns:
      Server host, defaults is 0.0.0.0.
    • setHost

      public void setHost(String host)
      Set the server host, defaults to 0.0.0.0.
      Parameters:
      host - Server host. Localhost, null or empty values fallback to 0.0.0.0.
    • getSsl

      @Nullable public SslOptions getSsl()
      SSL options.
      Returns:
      SSL options.
    • setSsl

      @NonNull public ServerOptions setSsl(@Nullable SslOptions ssl)
      Set SSL options.
      Parameters:
      ssl - SSL options.
      Returns:
      Server options.
    • isHttp2

      @Nullable public Boolean isHttp2()
      Specify when HTTP/2 is enabled or not. This value is set to null, which allows Jooby to enabled by default when dependency is added it.

      To turn off set to false.

      Returns:
      Whenever HTTP/2 is enabled.
    • setHttp2

      public ServerOptions setHttp2(@Nullable Boolean http2)
      Turn on/off HTTP/2 support.
      Parameters:
      http2 - True to enabled.
      Returns:
      This options.
    • isExpectContinue

      @Nullable public Boolean isExpectContinue()
      Whenever 100-Expect and continue requests are handled by the server. This is off by default, except for Jetty which is always ON.
      Returns:
      True when enabled.
    • setExpectContinue

      public ServerOptions setExpectContinue(@Nullable Boolean expectContinue)
      Set 100-Expect and continue requests are handled by the server. This is off by default, except for Jetty which is always ON.
      Parameters:
      expectContinue - True or false.
      Returns:
      This options.
    • getSSLContext

      @Nullable public SSLContext getSSLContext(@NonNull ClassLoader loader)
      Creates SSL context using the given resource loader. This method attempts to create a SSLContext when:

      - getSecurePort() has been set; or - getSsl() has been set.

      If secure port is set and there is no SSL options, this method configure a SSL context using the a self-signed certificate for localhost.

      Parameters:
      loader - Resource loader.
      Returns:
      SSLContext or null when SSL is disabled.