Class Server

java.lang.Object
org.attribyte.snook.Server
Direct Known Subclasses:
ExampleServer

public abstract class Server extends Object
  • Field Details

    • DEBUG_SYSTEM_PROP

      public static final String DEBUG_SYSTEM_PROP
      The system property name that holds the debug flag ("server.debug").
      See Also:
    • REQUEST_LOG_OUTPUT_PROPERTY

      public static final String REQUEST_LOG_OUTPUT_PROPERTY
      The request output format property name ("requestLogOutput").
      See Also:
    • REQUEST_LOG_DIRECTORY_PROPERTY

      public static final String REQUEST_LOG_DIRECTORY_PROPERTY
      The request log directory property name ("requestLog.Dir").
      See Also:
    • REQUEST_LOG_BASE_PROPERTY

      public static final String REQUEST_LOG_BASE_PROPERTY
      The request log base name property name ("requestLogBase").
      See Also:
    • REQUEST_LOG_BASE_DEFAULT

      public static final String REQUEST_LOG_BASE_DEFAULT
      The request log base default value ("server").
      See Also:
    • REQUEST_LOG_RETAIN_DAYS_PROPERTY

      public static final String 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_DEFAULT
      The default request log retain days (180).
      See Also:
    • REQUEST_LOG_EXTENDED_PROPERTY

      public static final String REQUEST_LOG_EXTENDED_PROPERTY
      The request log extended option property ("requestLogExtended").
      See Also:
    • REQUEST_LOG_EXTENDED_DEFAULT

      public static final boolean REQUEST_LOG_EXTENDED_DEFAULT
      The request log extended option default value (true).
      See Also:
    • REQUEST_LOG_TIMEZONE_PROPERTY

      public static final String 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 logger
      The configured logger.
    • props

      protected final Properties props
      The resolved properties.
    • serverConfiguration

      protected final ServerConfiguration serverConfiguration
      The server configuration.
    • httpServer

      protected final org.eclipse.jetty.server.Server httpServer
      The HTTP server.
    • rootContext

      protected final org.eclipse.jetty.ee10.servlet.ServletContextHandler rootContext
      The root context.
    • debug

      protected final boolean debug
      Is the server running in "debug" mode?
  • Constructor Details

    • Server

      @Deprecated protected Server(String[] args, String propsResourceName, String loggerName, boolean withGzip) throws Exception
      Deprecated.
      Use builder(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.
      Use builder(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.
      Use builder(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.
      Use builder(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.
      Use builder(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

      protected Server(Server.Builder builder) throws Exception
      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

      public static Server.Builder builder(String[] args)
      Creates a builder that loads properties from command line arguments.
      Parameters:
      args - The command line arguments.
      Returns:
      A new builder.
    • builder

      public static Server.Builder builder(Properties props)
      Creates a builder that uses pre-built properties.
      Parameters:
      props - The properties.
      Returns:
      A new builder.
    • logInfo

      protected void logInfo(String message)
      Logs an informational message to System.out and the logger, if configured.
      Parameters:
      message - The message.
    • logError

      protected void logError(String message)
      Logs an error message to System.err and the logger, if configured.
      Parameters:
      message - The message.
    • logError

      protected void logError(String message, Throwable t)
      Logs an error to System.err and the logger, if configured and prints the stack trace.
      Parameters:
      message - The message.
      t - A throwable.
    • start

      public void start() throws Exception
      Starts the server.
      Throws:
      Exception - on start error.
    • start

      public void start(ErrorHandler errorHandler) throws Exception
      Starts the server with a custom error handler.
      Parameters:
      errorHandler - The error handler.
      Throws:
      Exception - on start error.
    • startWithJoin

      public void startWithJoin() throws Exception
      Starts the server, then joins.
      Throws:
      Exception - on start error.
    • startWithJoin

      public void startWithJoin(ErrorHandler errorHandler) throws Exception
      Starts the server with a custom error handler, then joins.
      Parameters:
      errorHandler - The error handler.
      Throws:
      Exception - on start error.
    • join

      public void join() throws InterruptedException
      Join with the calling thread.
      Throws:
      InterruptedException - on interrupted.
    • shutdown

      protected abstract void shutdown()
      Called on server shutdown.
    • addMetricsServlet

      protected Server addMetricsServlet(com.codahale.metrics.MetricRegistry registry, String path)
      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

      protected Server addStaticAssets(StaticAssetsConfig config, String path)
      Adds configuration to serve static assets for a path.
      Parameters:
      config - The configuration.
      path - The path.
      Returns:
      A self-reference.
    • addStaticAssets

      protected final Server addStaticAssets(StaticAssetsConfig config, List<String> paths)
      Adds configuration to serve static assets for a list of paths.
      Parameters:
      config - The configuration.
      paths - The path list.
      Returns:
      A self-reference.