Class ServerBuilder

java.lang.Object
com.mastfrog.acteur.server.ServerBuilder

public final class ServerBuilder extends Object
Hides the complexity of initializing Guice and Settings to start a server simply.
Author:
Tim Boudreau
  • Constructor Details

    • ServerBuilder

      public ServerBuilder(com.mastfrog.giulius.scope.ReentrantScope scope)
    • ServerBuilder

      public ServerBuilder(String namespace, com.mastfrog.giulius.scope.ReentrantScope scope)
    • ServerBuilder

      public ServerBuilder()
      Create a ServerBuilder with Namespace.DEFAULT as its namespace. That means settings will be read from /etc/defaults.properties, ~/defaults.properties and ./defaults.properties
    • ServerBuilder

      public ServerBuilder(String namespace)
      Create a ServerBuilder with the passed namespace as its namespace. That means settings will be read from /etc/$NAMESPACE.properties, ~/$NAMESPACE.properties and ./$NAMESPACE.properties
      Parameters:
      namespace - A namespace - must be a legal file name, no path separators
  • Method Details

    • mergeNamespaces

      public ServerBuilder mergeNamespaces()
      If true, do not actually use the namespace feature of Dependencies - there is only one namespace - it is just not named "default". This is the common case, but for compatibility reasons is not currently the default. This reduces memory footprint overhead when looking up bound settings, since reflection is not needed and there is only one place to look.
      Returns:
    • applicationClass

      public ServerBuilder applicationClass(Class<? extends Application> type)
      Set the class of the application. If not set, assumes GenericApplication
      Parameters:
      type - The application class
      Returns:
      this
    • sslConfig

      public ServerBuilder sslConfig(io.netty.handler.ssl.SslContext context)
    • ssl

      public ServerBuilder ssl()
    • add

      public ServerBuilder add(com.mastfrog.settings.Settings settings)
      Explicitly add a Settings which should be used for resolving @Named bindings, in addition to any bound to the namespace (i.e. /etc/$NAMESPACE.properties)
      Parameters:
      settings - A settings
      Returns:
      this
    • add

      public ServerBuilder add(com.google.inject.Module module)
      Add a module which should be used for Guice bindings
      Parameters:
      module - A module
      Returns:
      this
    • add

      public ServerBuilder add(Class<? extends com.google.inject.Module> module)
      Add a module type which will be instantiated. The constructor may be a default constructor, or may take a Settings object, or a Settings and a ReentrantScope.
      Parameters:
      module - The module type
      Returns:
      this
    • withType

      public ServerBuilder withType(Class<?>... types)
      Add a type which will be bound. Use this to add your classes to the Guice injector if they will be passed between Acteurs. The rule is: If you accept it in an Acteur constructor and it is not part of the framework, you need to pass it here.
      Parameters:
      types - Some classes
      Returns:
      this
    • scope

      public com.mastfrog.giulius.scope.ReentrantScope scope()
    • enableHelp

      public ServerBuilder enableHelp()
    • disableHelp

      public ServerBuilder disableHelp()
    • enableCORS

      public ServerBuilder enableCORS()
    • disableCORS

      public ServerBuilder disableCORS()
    • disableBindings

      public ServerBuilder disableBindings(com.mastfrog.giulius.SettingsBindings... bindings)
      Disable binding of settings to some types if you know they will not be used, to save (minimal) memory. This is only significant if you are running in < 20Mb heap.
      Parameters:
      bindings - The bindings to remove
      Returns:
      this
    • enableOnlyBindingsFor

      public ServerBuilder enableOnlyBindingsFor(com.mastfrog.giulius.SettingsBindings... bindings)
      Explicitly set the list of types that are bound to settings to save (minimal) memory.
      Parameters:
      bindings - The types of bindings to set up
      Returns:
      this
    • build

      public com.mastfrog.acteur.util.Server build() throws IOException
      Build a Server object which can be started with its start() method (call await() on the resulting ServerControl object to keep it running).
      Returns:
      A server, not yet started
      Throws:
      IOException - if something goes wrong
    • withShutdownHookWaitMillis

      public ServerBuilder withShutdownHookWaitMillis(Duration dur)
    • toDependenciesBuilder

      public com.mastfrog.giulius.DependenciesBuilder toDependenciesBuilder() throws IOException
      Throws:
      IOException