public class ServerOptions extends Object
Modifier and Type | Field and Description |
---|---|
static int |
_10MB
10mb constant in bytes.
|
static int |
_16KB
16kb constant in bytes.
|
static int |
_4KB
4kb constant in bytes.
|
static int |
_8KB
8kb constant in bytes.
|
static int |
DEFAULT_COMPRESSION_LEVEL
Default compression level for gzip.
|
static int |
IO_THREADS
Number of available threads, but never smaller than
2 . |
static int |
SERVER_PORT
Default application port
8080 or the value of system property server.port . |
static int |
SEVER_SECURE_PORT
Default application secure port
8443 or the value of system property
server.securePort . |
static int |
WORKER_THREADS
Number of worker (a.k.a application) threads.
|
Constructor and Description |
---|
ServerOptions() |
Modifier and Type | Method and Description |
---|---|
static Optional<ServerOptions> |
from(com.typesafe.config.Config conf)
Creates server options from config object.
|
int |
getBufferSize()
Server buffer size in bytes.
|
Integer |
getCompressionLevel()
Indicates compression level to use while producing gzip responses.
|
boolean |
getDefaultHeaders()
True if default headers:
Date , Content-Type and Server
are enabled. |
boolean |
getGzip()
Deprecated.
In favor of
getCompressionLevel() . |
String |
getHost()
Server host, defaults is
0.0.0.0 . |
int |
getIoThreads()
Number of IO threads used by the server.
|
int |
getIoThreads(int defaultIoThreads)
Number of IO threads used by the server.
|
int |
getMaxRequestSize()
Maximum request size in bytes.
|
int |
getPort()
Server HTTP port.
|
Integer |
getSecurePort()
HTTPs port or
null . |
String |
getServer()
Server name.
|
SslOptions |
getSsl()
SSL options.
|
SSLContext |
getSSLContext(ClassLoader loader)
Creates SSL context using the given resource loader.
|
int |
getWorkerThreads()
Number of worker threads (a.k.a application) to use.
|
int |
getWorkerThreads(int defaultWorkerThreads)
Number of worker threads (a.k.a application) to use.
|
boolean |
isSSLEnabled()
True when SSL is enabled.
|
ServerOptions |
setBufferSize(int bufferSize)
Set buffer size.
|
ServerOptions |
setCompressionLevel(Integer compressionLevel)
Set compression level to use while producing gzip responses.
|
ServerOptions |
setDefaultHeaders(boolean defaultHeaders)
Enabled/disabled default server headers:
Date , Content-Type and
Server . |
ServerOptions |
setGzip(boolean gzip)
Deprecated.
In favor of
setCompressionLevel(Integer) . |
void |
setHost(String host)
Set the server host, defaults to
0.0.0.0 . |
ServerOptions |
setIoThreads(int ioThreads)
Set number of IO threads to use.
|
ServerOptions |
setMaxRequestSize(int maxRequestSize)
Set max request size in bytes.
|
ServerOptions |
setPort(int port)
Set the server port (default is 8080).
|
ServerOptions |
setSecurePort(Integer securePort)
Set HTTPs port.
|
ServerOptions |
setServer(String server)
Set server name.
|
ServerOptions |
setSsl(SslOptions ssl)
Set SSL options.
|
ServerOptions |
setWorkerThreads(int workerThreads)
Set number of worker threads (a.k.a application) to use.
|
String |
toString() |
public static final int SERVER_PORT
8080
or the value of system property server.port
.public static final int SEVER_SECURE_PORT
8443
or the value of system property
server.securePort
.public static final int DEFAULT_COMPRESSION_LEVEL
public static final int _4KB
public static final int _8KB
public static final int _16KB
public static final int _10MB
public static final int IO_THREADS
2
.public static final int WORKER_THREADS
8
.@Nonnull public static Optional<ServerOptions> from(@Nonnull com.typesafe.config.Config conf)
server.port
, server.ioThreads
, etc...conf
- Configuration object.@Nonnull public ServerOptions setServer(@Nonnull String server)
server
- Name of the underlying server.public int getPort()
@Nonnull public ServerOptions setPort(int port)
0
.port
- Server port or 0
to pick a random port.@Nullable public Integer getSecurePort()
null
.null
.public boolean isSSLEnabled()
@Nullable public ServerOptions setSecurePort(@Nullable Integer securePort)
securePort
- Port number or 0
for random number.public int getIoThreads()
public int getIoThreads(int defaultIoThreads)
defaultIoThreads
- Default number of threads if none was set.@Nonnull public ServerOptions setIoThreads(int ioThreads)
ioThreads
- Number of threads. Must be greater than 0
.public int getWorkerThreads()
public int getWorkerThreads(int defaultWorkerThreads)
defaultWorkerThreads
- Default worker threads is none was set.@Nonnull public ServerOptions setWorkerThreads(int workerThreads)
workerThreads
- Number of worker threads to use.@Deprecated public boolean getGzip()
getCompressionLevel()
.@Deprecated @Nonnull public ServerOptions setGzip(boolean gzip)
setCompressionLevel(Integer)
.gzip
- True to enabled it. Default is disabled(false).@Nullable public Integer getCompressionLevel()
0...9
or null
when off.@Nonnull public ServerOptions setCompressionLevel(@Nullable Integer compressionLevel)
compressionLevel
- Value between 0..9
or null
.public boolean getDefaultHeaders()
Date
, Content-Type
and Server
are enabled.Date
, Content-Type
and
Server
are enabled.@Nonnull public ServerOptions setDefaultHeaders(boolean defaultHeaders)
Date
, Content-Type
and
Server
. Enabled by default.defaultHeaders
- True for enabled.public int getBufferSize()
16kb
. Used for reading/writing data.16kb
. Used for reading/writing
data.@Nonnull public ServerOptions setBufferSize(int bufferSize)
bufferSize
- Buffer size.public int getMaxRequestSize()
StatusCode.REQUEST_ENTITY_TOO_LARGE
response. Default is 10mb
.@Nonnull public ServerOptions setMaxRequestSize(int maxRequestSize)
maxRequestSize
- Max request size in bytes.public String getHost()
0.0.0.0
.0.0.0.0
.public void setHost(String host)
0.0.0.0
.host
- Server host. Localhost, null or empty values fallback to 0.0.0.0
.@Nullable public SslOptions getSsl()
@Nonnull public ServerOptions setSsl(@Nullable SslOptions ssl)
ssl
- SSL options.@Nullable public SSLContext getSSLContext(@Nonnull ClassLoader loader)
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
.loader
- Resource loader.null
when SSL is disabled.Copyright © 2020. All rights reserved.