Package org.attribyte.snook
Class Server
java.lang.Object
org.attribyte.snook.Server
- Direct Known Subclasses:
ExampleServer
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classA builder for configuring server options. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final booleanIs the server running in "debug" mode?static final StringThe system property name that holds the debug flag ("server.debug").protected final org.eclipse.jetty.server.ServerThe HTTP server.protected final org.attribyte.api.LoggerThe configured logger.protected final PropertiesThe resolved properties.static final StringThe request log base default value ("server").static final StringThe request log base name property name ("requestLogBase").static final StringThe request log directory property name ("requestLog.Dir").static final booleanThe request log extended option default value (true).static final StringThe request log extended option property ("requestLogExtended").static final StringThe request output format property name ("requestLogOutput").static final intThe default request log retain days (180).static final StringThe request log retain days property name ("requestLogRetainDays").static final StringThe request log time zone property ("requestLogTimeZone").protected final org.eclipse.jetty.ee10.servlet.ServletContextHandlerThe root context.protected final ServerConfigurationThe server configuration. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedDeprecated.protectedServer(String[] args, String propsResourceName, String loggerName, boolean withGzip, ErrorHandler errorHandler) Deprecated.Usebuilder(String[])instead.protectedDeprecated.Usebuilder(String[])instead.protectedServer(String[] args, String propsResourceName, org.attribyte.api.Logger logger, boolean withGzip, ErrorHandler errorHandler) Deprecated.Usebuilder(String[])instead.protectedServer(Properties props, org.attribyte.api.Logger logger, boolean withGzip) Deprecated.Usebuilder(Properties)instead.protectedServer(Server.Builder builder) Creates the server from a builder. -
Method Summary
Modifier and TypeMethodDescriptionprotected ServeraddHealthCheckServlet(com.codahale.metrics.health.HealthCheckRegistry registry, String path) Adds a health check servlet to the server.protected ServeraddMetricsServlet(com.codahale.metrics.MetricRegistry registry, String path) Adds a metrics reporting servlet at the specified path.protected ServeraddStaticAssets(StaticAssetsConfig config, String path) Adds configuration to serve static assets for a path.protected final ServeraddStaticAssets(StaticAssetsConfig config, List<String> paths) Adds configuration to serve static assets for a list of paths.static Server.BuilderCreates a builder that loads properties from command line arguments.static Server.Builderbuilder(Properties props) Creates a builder that uses pre-built properties.voidjoin()Join with the calling thread.static org.attribyte.api.Loggerlog4jLogger(String loggerName, org.apache.logging.log4j.Level minimumLevel) Create a log4j-based logger.protected voidLogs an error message toSystem.errand the logger, if configured.protected voidLogs an error toSystem.errand the logger, if configured and prints the stack trace.protected voidLogs an informational message toSystem.outand the logger, if configured.protected abstract voidshutdown()Called on server shutdown.voidstart()Starts the server.voidstart(ErrorHandler errorHandler) Starts the server with a custom error handler.voidStarts the server, then joins.voidstartWithJoin(ErrorHandler errorHandler) Starts the server with a custom error handler, then joins.
-
Field Details
-
DEBUG_SYSTEM_PROP
The system property name that holds the debug flag ("server.debug").- See Also:
-
REQUEST_LOG_OUTPUT_PROPERTY
The request output format property name ("requestLogOutput").- See Also:
-
REQUEST_LOG_DIRECTORY_PROPERTY
The request log directory property name ("requestLog.Dir").- See Also:
-
REQUEST_LOG_BASE_PROPERTY
The request log base name property name ("requestLogBase").- See Also:
-
REQUEST_LOG_BASE_DEFAULT
The request log base default value ("server").- See Also:
-
REQUEST_LOG_RETAIN_DAYS_PROPERTY
The request log retain days property name ("requestLogRetainDays").- See Also:
-
REQUEST_LOG_RETAIN_DAYS_DEFAULT
public static final int REQUEST_LOG_RETAIN_DAYS_DEFAULTThe default request log retain days (180).- See Also:
-
REQUEST_LOG_EXTENDED_PROPERTY
The request log extended option property ("requestLogExtended").- See Also:
-
REQUEST_LOG_EXTENDED_DEFAULT
public static final boolean REQUEST_LOG_EXTENDED_DEFAULTThe request log extended option default value (true).- See Also:
-
REQUEST_LOG_TIMEZONE_PROPERTY
The request log time zone property ("requestLogTimeZone").Value must be a valid timezone ID. If unspecified, default is the system default.
- See Also:
-
logger
protected final org.attribyte.api.Logger loggerThe configured logger. -
props
The resolved properties. -
serverConfiguration
The server configuration. -
httpServer
protected final org.eclipse.jetty.server.Server httpServerThe HTTP server. -
rootContext
protected final org.eclipse.jetty.ee10.servlet.ServletContextHandler rootContextThe root context. -
debug
protected final boolean debugIs the server running in "debug" mode?
-
-
Constructor Details
-
Server
@Deprecated protected Server(String[] args, String propsResourceName, String loggerName, boolean withGzip) throws Exception Deprecated.Usebuilder(String[])instead.Creates the server with properties from a resource and a named logger.- Parameters:
args- The command line arguments.propsResourceName- The name of a resource that contains default properties.loggerName- The name of a logger.withGzip- Should auto-gzip handling be configured?- Throws:
Exception- on configuration error.
-
Server
@Deprecated protected Server(String[] args, String propsResourceName, String loggerName, boolean withGzip, ErrorHandler errorHandler) throws Exception Deprecated.Usebuilder(String[])instead.Creates the server with properties from a resource, a named logger and a custom error handler.- Parameters:
args- The command line arguments.propsResourceName- The name of a resource that contains default properties.loggerName- The name of a logger.withGzip- Should auto-gzip handling be configured?errorHandler- A custom error handler.- Throws:
Exception- on configuration error.
-
Server
@Deprecated protected Server(String[] args, String propsResourceName, org.attribyte.api.Logger logger, boolean withGzip) throws Exception Deprecated.Usebuilder(String[])instead.Creates the server with properties from a resource and a specified logger.- Parameters:
args- The command line arguments.propsResourceName- The name of a resource that contains default properties.logger- The logger.withGzip- Should auto-gzip handling be configured?- Throws:
Exception- on configuration error.
-
Server
@Deprecated protected Server(String[] args, String propsResourceName, org.attribyte.api.Logger logger, boolean withGzip, ErrorHandler errorHandler) throws Exception Deprecated.Usebuilder(String[])instead.Creates the server with properties from a resource, a specified logger and a custom error handler.- Parameters:
args- The command line arguments.propsResourceName- The name of a resource that contains default properties.logger- The logger.withGzip- Should auto-gzip handling be configured?errorHandler- A custom error handler.- Throws:
Exception- on configuration error.
-
Server
@Deprecated protected Server(Properties props, org.attribyte.api.Logger logger, boolean withGzip) throws Exception Deprecated.Usebuilder(Properties)instead.Creates the server from properties and a logger.- Parameters:
props- The properties.logger- The logger.withGzip- Should auto-gzip handling be configured?- Throws:
Exception- on configuration error.
-
Server
Creates the server from a builder.- Parameters:
builder- The builder.- Throws:
Exception- on configuration error.
-
-
Method Details
-
log4jLogger
public static org.attribyte.api.Logger log4jLogger(String loggerName, org.apache.logging.log4j.Level minimumLevel) Create a log4j-based logger.- Parameters:
loggerName- The name of the log4j logger.minimumLevel- The minimum level.- Returns:
- The API logger.
-
builder
Creates a builder that loads properties from command line arguments.- Parameters:
args- The command line arguments.- Returns:
- A new builder.
-
builder
Creates a builder that uses pre-built properties.- Parameters:
props- The properties.- Returns:
- A new builder.
-
logInfo
Logs an informational message toSystem.outand the logger, if configured.- Parameters:
message- The message.
-
logError
Logs an error message toSystem.errand the logger, if configured.- Parameters:
message- The message.
-
logError
Logs an error toSystem.errand the logger, if configured and prints the stack trace.- Parameters:
message- The message.t- A throwable.
-
start
Starts the server.- Throws:
Exception- on start error.
-
start
Starts the server with a custom error handler.- Parameters:
errorHandler- The error handler.- Throws:
Exception- on start error.
-
startWithJoin
Starts the server, then joins.- Throws:
Exception- on start error.
-
startWithJoin
Starts the server with a custom error handler, then joins.- Parameters:
errorHandler- The error handler.- Throws:
Exception- on start error.
-
join
Join with the calling thread.- Throws:
InterruptedException- on interrupted.
-
shutdown
protected abstract void shutdown()Called on server shutdown. -
addMetricsServlet
Adds a metrics reporting servlet at the specified path.- Parameters:
registry- The metric registry.path- The report path.- Returns:
- A self-reference.
-
addHealthCheckServlet
protected Server addHealthCheckServlet(com.codahale.metrics.health.HealthCheckRegistry registry, String path) Adds a health check servlet to the server.- Parameters:
registry- The health check registry.path- The report path.- Returns:
- A self-reference.
-
addStaticAssets
Adds configuration to serve static assets for a path.- Parameters:
config- The configuration.path- The path.- Returns:
- A self-reference.
-
addStaticAssets
Adds configuration to serve static assets for a list of paths.- Parameters:
config- The configuration.paths- The path list.- Returns:
- A self-reference.
-
builder(String[])instead.