Interface ServerConfig
-
- All Superinterfaces:
ConfigData
public interface ServerConfig extends ConfigData
The configuration of the server.This object represents the basic information needed to bootstrap the server (e.g.
getPort()
), but also provides access to any externalised config objects to be used by the application viaConfigData.get(String, Class)
(see also:getRequiredConfig()
). A server config object is-aConfigData
object.Server config objects are programmatically built via a
ServerConfigBuilder
, which can be obtained via the static methodsbuilder()
} andembedded()
.
-
-
Field Summary
Fields Modifier and Type Field Description static int
DEFAULT_MAX_CHUNK_SIZE
The default maximum chunk size to use when reading request/response bodies.static int
DEFAULT_MAX_CONTENT_LENGTH
The default max content length.static int
DEFAULT_MAX_HEADER_SIZE
The default maximum header size to use when reading requests.static int
DEFAULT_MAX_INITIAL_LINE_LENGTH
The default maximum initial line length to use when reading requests.static int
DEFAULT_PORT
The default port for Ratpack applications, 5050.static int
DEFAULT_THREADS
The default number of threads an application should use.static com.google.common.reflect.TypeToken<ServerConfig>
TYPE
A type token for this type.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Modifier and Type Method Description static ServerConfigBuilder
builder()
static ServerConfigBuilder
embedded()
Creates a builder configured for development mode and an ephemeral port.InetAddress
getAddress()
The address of the interface that the application should bind to.FileSystemBinding
getBaseDir()
The base dir of the application, which is also the initialFileSystemBinding
.Optional<Integer>
getConnectQueueSize()
The maximum amount of connections that may be waiting to be accepted at any time.Optional<Integer>
getConnectTimeoutMillis()
The connect timeout of the channel.DecodingErrorLevel
getDecodingErrorLevel()
Specifies how to log messages associated with request decode failures.Duration
getIdleTimeout()
The default amount of time to allow a connection to remain open without any traffic.int
getMaxChunkSize()
The maximum chunk size to use when reading request (server) or response (client) bodies.int
getMaxContentLength()
The max content length to use for the HttpObjectAggregator.int
getMaxHeaderSize()
The maximum size of all headers allowed for reading http requests.int
getMaxInitialLineLength()
The maximum initial line length allowed for reading http requests.Optional<Integer>
getMaxMessagesPerRead()
The maximum number of messages to read per read loop.int
getPort()
The port that the application should listen to requests on.Optional<Path>
getPortFile()
The path to write the port that the application is listening on.URI
getPublicAddress()
The public address of the site used for redirects.Optional<Integer>
getReceiveBufferSize()
The StandardSocketOptions.SO_RCVBUF option.com.google.common.collect.ImmutableSet<ConfigObject<?>>
getRequiredConfig()
The config objects that were declared as required when this server config was built.io.netty.util.Mapping<String,io.netty.handler.ssl.SslContext>
getSslContext()
The SSL context to use if the application will serve content over HTTPS.int
getThreads()
The number of threads for handling application requests.Optional<Integer>
getWriteSpinCount()
The maximum loop count for a write operation until WritableByteChannel.write(ByteBuffer) returns a non-zero value.boolean
isDevelopment()
Whether or not the server is in "development" mode.boolean
isHasBaseDir()
Whether or not the base dir of the application has been set.boolean
isRegisterShutdownHook()
Whether a JVM shutdown hook was registered for the application in order to shut it down gracefully.static ServerConfig
of(Action<? super ServerConfigBuilder> action)
-
Methods inherited from interface ratpack.config.ConfigData
get, get, getAsConfigObject, getAsConfigObject, getRootNode
-
-
-
-
Field Detail
-
TYPE
static final com.google.common.reflect.TypeToken<ServerConfig> TYPE
A type token for this type.- Since:
- 1.1
-
DEFAULT_PORT
static final int DEFAULT_PORT
The default port for Ratpack applications, 5050.- See Also:
- Constant Field Values
-
DEFAULT_MAX_CONTENT_LENGTH
static final int DEFAULT_MAX_CONTENT_LENGTH
The default max content length.- See Also:
- Constant Field Values
-
DEFAULT_THREADS
static final int DEFAULT_THREADS
The default number of threads an application should use. Calculated asRuntime.getRuntime().availableProcessors() * 2
.
-
DEFAULT_MAX_CHUNK_SIZE
static final int DEFAULT_MAX_CHUNK_SIZE
The default maximum chunk size to use when reading request/response bodies.Defaults to 8192.
- See Also:
getMaxChunkSize()
, Constant Field Values
-
DEFAULT_MAX_INITIAL_LINE_LENGTH
static final int DEFAULT_MAX_INITIAL_LINE_LENGTH
The default maximum initial line length to use when reading requests.Defaults to 4096
- Since:
- 1.4
- See Also:
getMaxInitialLineLength()
, Constant Field Values
-
DEFAULT_MAX_HEADER_SIZE
static final int DEFAULT_MAX_HEADER_SIZE
The default maximum header size to use when reading requests.Defaults to 8192
- Since:
- 1.4
- See Also:
getMaxHeaderSize()
, Constant Field Values
-
-
Method Detail
-
embedded
static ServerConfigBuilder embedded()
Creates a builder configured for development mode and an ephemeral port.- Returns:
- a server config builder
-
builder
static ServerConfigBuilder builder()
-
of
static ServerConfig of(Action<? super ServerConfigBuilder> action) throws Exception
- Throws:
Exception
-
getPort
int getPort()
The port that the application should listen to requests on.Defaults to 5050.
- Returns:
- The port that the application should listen to requests on.
-
getPortFile
Optional<Path> getPortFile()
The path to write the port that the application is listening on.Defaults to empty
- Returns:
- the optional path the the listening port will be written to.
- Since:
- 1.8
-
getAddress
@Nullable InetAddress getAddress()
The address of the interface that the application should bind to.A value of null causes all interfaces to be bound. Defaults to null.
- Returns:
- The address of the interface that the application should bind to.
-
getRequiredConfig
com.google.common.collect.ImmutableSet<ConfigObject<?>> getRequiredConfig()
The config objects that were declared as required when this server config was built.Required config is declared via the
ServerConfigBuilder.require(String, Class)
when building. All required config is made part of the base registry (which the server registry joins with), which automatically makes the config objects available to the server registry.- Returns:
- the declared required config
- See Also:
ServerConfigBuilder.require(String, Class)
-
isDevelopment
boolean isDevelopment()
Whether or not the server is in "development" mode.A flag for indicating to Ratpack internals that the app is under development; diagnostics and reloading are more important than performance and security.
In development mode Ratpack will leak internal information through diagnostics and stacktraces by sending them to the response.
- Returns:
true
if the server is in "development" mode
-
getThreads
int getThreads()
The number of threads for handling application requests.If the value is greater than 0, a thread pool (of this size) will be created for servicing requests and doing computation. If the value is 0 (default) or less, a thread pool of size
Runtime.availableProcessors()
* 2
will be used.This effectively sizes the
ExecController.getExecutor()
thread pool size.- Returns:
- the number of threads for handling application requests.
-
isRegisterShutdownHook
boolean isRegisterShutdownHook()
Whether a JVM shutdown hook was registered for the application in order to shut it down gracefully.When
true
, the application will bestopped
when the JVM starts shutting down. This allows graceful shutdown of the application when the process is terminated. Defaults totrue
.- Returns:
- whether the shutdown hook was registered
- Since:
- 1.6
-
getPublicAddress
URI getPublicAddress()
The public address of the site used for redirects.- Returns:
- The url of the public address
-
getSslContext
io.netty.util.Mapping<String,io.netty.handler.ssl.SslContext> getSslContext()
The SSL context to use if the application will serve content over HTTPS.- Returns:
- The SSL context or
null
if the application does not use SSL. - Since:
- 2.0 this returns a full mapping to support SNI.
-
getMaxContentLength
int getMaxContentLength()
The max content length to use for the HttpObjectAggregator.- Returns:
- The max content length as an int.
-
getConnectTimeoutMillis
Optional<Integer> getConnectTimeoutMillis()
The connect timeout of the channel.- Returns:
- The connect timeout in milliseconds
- See Also:
- setConnectTimeoutMillis
-
getMaxMessagesPerRead
Optional<Integer> getMaxMessagesPerRead()
The maximum number of messages to read per read loop.If this value is greater than 1, an event loop might attempt to read multiple times to procure multiple messages.
- Returns:
- The maximum number of messages to read
- See Also:
- setMaxMessagesPerRead
-
getReceiveBufferSize
Optional<Integer> getReceiveBufferSize()
The StandardSocketOptions.SO_RCVBUF option.- Returns:
- The receive buffer size
- See Also:
- setReceiveBufferSize
-
getConnectQueueSize
Optional<Integer> getConnectQueueSize()
The maximum amount of connections that may be waiting to be accepted at any time.This is effectively the
SO_BACKLOG
standard socket parameter. If the queue is full (i.e. there are too many pending connections), connection attempts will be rejected. Established connections are not part of this queue so do not contribute towards the limit.The default value is platform specific, but usually either 200 or 128. Most application do not need to change this default.
- Returns:
- the connection queue size
- Since:
- 1.5
-
getWriteSpinCount
Optional<Integer> getWriteSpinCount()
The maximum loop count for a write operation until WritableByteChannel.write(ByteBuffer) returns a non-zero value.It is similar to what a spin lock is used for in concurrency programming. It improves memory utilization and write throughput depending on the platform that JVM runs on.
- Returns:
- The write spin count
- See Also:
- setWriteSpinCount
-
isHasBaseDir
boolean isHasBaseDir()
Whether or not the base dir of the application has been set.- Returns:
- whether or not the base dir of the application has been set.
-
getMaxChunkSize
int getMaxChunkSize()
The maximum chunk size to use when reading request (server) or response (client) bodies.This value is used to determine the size of chunks to emit when consuming request/response bodies. This generally only has an impact when consuming the body as a stream. A lower value will reduce memory pressure by requiring less memory at one time, but at the expense of throughput.
Defaults to
DEFAULT_MAX_CHUNK_SIZE
. This value is suitable for most applications. If your application deals with very large bodies, you may want to increase it.- Returns:
- the maximum chunk size
-
getMaxInitialLineLength
int getMaxInitialLineLength()
The maximum initial line length allowed for reading http requests.This value is used to determine the maximum allowed length for the initial line of an http request.
Defaults to
DEFAULT_MAX_INITIAL_LINE_LENGTH
. This value is suitable for most applications. If your application deals with very large request URIs, you may want to increase it.- Returns:
- the maximum initial line length allowed for http requests.
- Since:
- 1.4
-
getMaxHeaderSize
int getMaxHeaderSize()
The maximum size of all headers allowed for reading http requests.This value is used to determine the maximum allowed size for the sum of the length all headers of an http request.
Defaults to
DEFAULT_MAX_HEADER_SIZE
. This value is suitable for most applications. If your application deals with very large http headers, you may want to increase it.- Returns:
- the maximum size of http headers allowed for an incoming http requests.
- Since:
- 1.4
-
getIdleTimeout
Duration getIdleTimeout()
The default amount of time to allow a connection to remain open without any traffic.If the connection is idle for the timeout value, it will be closed. This value can be overridden on a per request basis by
Request.setIdleTimeout(Duration)
.A value of
Duration.ZERO
is interpreted as no timeout. The value is neverDuration.isNegative()
.This timeout affects several aspects.
Reading
After making a connection, this timeout will fire if the client does not send any data within the timeout value. This includes the initial headers and the body. This may occur because the application has not requested more data. That is, it has not requested the body with
Request.getBody()
or similar. if the body is requested after the connection times out, aConnectionClosedException
will be propagated.Writing
This timeout also applies to writing the response. If the application does not emit a response within the timeout after the client has sent all the bytes it is going to, the connection will be closed.
When sending a response, if the client does not read within the timeout, the connection will be closed.
When streaming a response, if nothing is sent within the timeout, the connection will be closed. This means that if you are streaming a real time data set where new data may not be available within the timeout but you do not want to drop the connection, you should set a request specific timeout using
Request.setIdleTimeout(Duration)
Connection keep-alive
If the client supports keep alive, the connection will remain open after first use so that it can be reused for subsequent requests from the client. If the request is not reused (i.e. no new request headers are sent) within this timeout, the connection will be closed. This value is always used for this timeout. Any specific timeout set when handling the previous request is not used.
- Returns:
- the default idle timeout for connections
- Since:
- 1.5
-
getBaseDir
FileSystemBinding getBaseDir() throws NoBaseDirException
The base dir of the application, which is also the initialFileSystemBinding
.- Returns:
- The base dir of the application.
- Throws:
NoBaseDirException
- if this launch config has no base dir set.
-
getDecodingErrorLevel
DecodingErrorLevel getDecodingErrorLevel()
Specifies how to log messages associated with request decode failures.This is useful when using Ratpack as an HTTPS server and misbehaving clients are sending HTTP requests.
The default value for this setting is
WARN
which emits a single line message for each non SSL/TLS record.- Returns:
- the configured log setting
- Since:
- 2.0
-
-