Class Microservice.Builder

java.lang.Object
org.apache.juneau.microservice.Microservice.Builder
Enclosing class:
Microservice

public static class Microservice.Builder extends Object
Builder class.
  • Constructor Details

  • Method Details

    • copy

      Creates a copy of this builder.
      Returns:
      A new copy of this builder.
    • build

      public Microservice build() throws Exception
      Instantiate a new microservice using the settings defined on this builder.
      Returns:
      A new microservice.
      Throws:
      Exception - Error occurred.
    • args

      Specifies the command-line arguments passed into the Java command.

      This is required if you use Microservice.getArgs() or $A string variables.

      Parameters:
      args - The command-line arguments passed into the Java command as a pre-parsed Args object.
      Returns:
      This object.
    • args

      public Microservice.Builder args(String... args)
      Specifies the command-line arguments passed into the Java command.

      This is required if you use Microservice.getArgs() or $A string variables.

      Parameters:
      args - The command-line arguments passed into the Java command as the raw command-line arguments.
      Returns:
      This object.
    • manifest

      Specifies the manifest file of the jar file this microservice is contained within.

      This is required if you use Microservice.getManifest(). It's also used to locate initialization values such as Main-Config.

      If you do not specify the manifest file, we attempt to resolve it through the following methods:

      1. Looking on the file system for a file at "META-INF/MANIFEST.MF". This is primarily to allow for running microservices from within eclipse workspaces where the manifest file is located in the project root.
      2. Using the class loader for this class to find the file at the URL "META-INF/MANIFEST.MF".
      Parameters:
      value - The manifest file of this microservice.
      Can be any of the following types:
      • ManifestFile
      • Manifest
      • Reader - Containing the raw contents of the manifest. Note that the input must end with a newline.
      • InputStream - Containing the raw contents of the manifest. Note that the input must end with a newline.
      • File - File containing the raw contents of the manifest.
      • String - Path to file containing the raw contents of the manifest.
      • Class - Finds and loads the manifest file of the jar file that the specified class is contained within.
      Returns:
      This object.
      Throws:
      IOException - Thrown by underlying stream.
    • logger

      Specifies the logger used by the microservice and returned by the Microservice.getLogger() method.

      Calling this method overrides the default logging mechanism controlled by the logConfig(LogConfig) method.

      Parameters:
      logger - The logger to use for logging microservice messages.
      Returns:
      This object.
    • logConfig

      Specifies logging instructions for the microservice.

      If not specified, the values are taken from the "Logging" section of the configuration.

      This method is ignored if logger(Logger) is used to set the microservice logger.

      Parameters:
      logConfig - The log configuration.
      Returns:
      This object.
    • config

      Specifies the config for initializing this microservice.

      Calling this method overrides the default configuration controlled by the configName(String) and configStore(ConfigStore) methods.

      Parameters:
      config - The configuration.
      Returns:
      This object.
    • configName

      public Microservice.Builder configName(String configName)
      Specifies the config name for initializing this microservice.

      If you do not specify the config file location, we attempt to resolve it through the following methods:

      1. Resolve file first in working directory, then in classpath, using the following names:
        • The "configFile" argument in the command line arguments passed in through the constructor.
        • The value of the Main-Config entry in the manifest file.
        • A config file in the same location and with the same name as the executable jar file. (e.g. "java -jar myjar.jar" will look for "myjar.cfg").
      2. Resolve any "*.cfg" file that can be found in the working directory.
      3. Resolve any of the following files in the classpath: "juneau.cfg", "system.cfg"

      If no configuration file is found, and empty in-memory configuration is used.

      Parameters:
      configName - The configuration name.
      Returns:
      This object.
    • configStore

      Specifies the config store to use for storing and retrieving configurations.

      By default, we use a FileStore store for configuration files.

      Parameters:
      configStore - The configuration name.
      Returns:
      This object.
    • consoleEnabled

      public Microservice.Builder consoleEnabled(boolean consoleEnabled)
      Specifies that the Java console is enabled for this microservice.

      If not specified, this value is taken from the "Console/enabled" configuration setting. If not specified in the configuration, defaults to false.

      Parameters:
      consoleEnabled - true if the Java console is enabled for this microservice.
      Returns:
      This object.
    • consoleCommands

      public Microservice.Builder consoleCommands(Class<? extends ConsoleCommand>... consoleCommands) throws ExecutableException
      Specifies console commands to make available on the Java console.

      Note that these are ignored if the console is not enabled via consoleEnabled(boolean).

      This list augments the commands defined via the "Console/commands" configuration setting.

      This method can only be used on console commands with no-arg constructors.

      Parameters:
      consoleCommands - The list of console commands to append to the list of available commands.
      Returns:
      This object.
      Throws:
      ExecutableException - Exception occurred on invoked constructor/method/field.
    • consoleCommands

      Specifies console commands to make available on the Java console.

      Note that these are ignored if the console is not enabled via consoleEnabled(boolean).

      This list augments the commands defined via the "Console/commands" configuration setting.

      Parameters:
      consoleCommands - The list of console commands to append to the list of available commands.
      Returns:
      This object.
    • console

      public Microservice.Builder console(Scanner consoleReader, PrintWriter consoleWriter)
      Specifies the console input and output.

      If not specified, uses the console returned by System.console(). If that is not available, uses System.in and System.out.

      Note that these are ignored if the console is not enabled via consoleEnabled(boolean).

      Parameters:
      consoleReader - The console input.
      consoleWriter - The console output.
      Returns:
      This object.
    • vars

      public Microservice.Builder vars(Class<? extends Var>... vars)
      Augments the set of variables defined in the configuration and var resolver.

      This calls VarResolver.Builder.vars(Class[]) on the var resolver used to construct the configuration object returned by Microservice.getConfig() and the var resolver returned by Microservice.getVarResolver().

      Parameters:
      vars - The set of variables to append to the var resolver builder.
      Returns:
      This object.
    • varBean

      public <T> Microservice.Builder varBean(Class<T> c, T value)
      Adds a bean for vars defined in the var resolver.

      This calls VarResolver.Builder.bean(Class,Object) on the var resolver used to construct the configuration object returned by Microservice.getConfig() and the var resolver returned by Microservice.getVarResolver().

      Type Parameters:
      T - The bean type.
      Parameters:
      c - The bean type.
      value - The bean.
      Returns:
      This object.
    • workingDir

      public Microservice.Builder workingDir(File workingDir)
      Specifies the directory to use to resolve the config file and other paths defined with the config file.
      Parameters:
      workingDir - The working directory, or null to use the underlying working directory.
      Returns:
      This object.
    • workingDir

      public Microservice.Builder workingDir(String workingDir)
      Specifies the directory to use to resolve the config file and other paths defined with the config file.
      Parameters:
      workingDir - The working directory, or null to use the underlying working directory.
      Returns:
      This object.
    • listener

      Registers an event listener for this microservice.
      Parameters:
      listener - An event listener for this microservice.
      Returns:
      This object.
    • resolveFile

      protected File resolveFile(String path)
      Resolves the specified path.

      If the working directory has been explicitly specified, relative paths are resolved relative to that.

      Parameters:
      path - The path to resolve.
      Returns:
      The resolved file.