Class Microservice.Builder
- Enclosing class:
Microservice
-
Constructor Summary
ModifierConstructorDescriptionprotected
Builder()
Constructor.protected
Builder
(Microservice.Builder copyFrom) Copy constructor. -
Method Summary
Modifier and TypeMethodDescriptionSpecifies the command-line arguments passed into the Java command.Specifies the command-line arguments passed into the Java command.build()
Instantiate a new microservice using the settings defined on this builder.Specifies the config for initializing this microservice.configName
(String configName) Specifies the config name for initializing this microservice.configStore
(ConfigStore configStore) Specifies the config store to use for storing and retrieving configurations.console
(Scanner consoleReader, PrintWriter consoleWriter) Specifies the console input and output.consoleCommands
(Class<? extends ConsoleCommand>... consoleCommands) Specifies console commands to make available on the Java console.consoleCommands
(ConsoleCommand... consoleCommands) Specifies console commands to make available on the Java console.consoleEnabled
(boolean consoleEnabled) Specifies that the Java console is enabled for this microservice.copy()
Creates a copy of this builder.listener
(MicroserviceListener listener) Registers an event listener for this microservice.Specifies logging instructions for the microservice.Specifies the logger used by the microservice and returned by theMicroservice.getLogger()
method.Specifies the manifest file of the jar file this microservice is contained within.protected File
resolveFile
(String path) Resolves the specified path.Adds a bean for vars defined in the var resolver.Augments the set of variables defined in the configuration and var resolver.workingDir
(File workingDir) Specifies the directory to use to resolve the config file and other paths defined with the config file.workingDir
(String workingDir) Specifies the directory to use to resolve the config file and other paths defined with the config file.
-
Constructor Details
-
Builder
protected Builder()Constructor. -
Builder
Copy constructor.- Parameters:
copyFrom
- The builder to copy.
-
-
Method Details
-
copy
Creates a copy of this builder.- Returns:
- A new copy of this builder.
-
build
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-parsedArgs
object.- Returns:
- This object.
-
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 asMain-Config .If you do not specify the manifest file, we attempt to resolve it through the following methods:
-
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. -
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.
-
Looking on the file system for a file at
-
logger
Specifies the logger used by the microservice and returned by theMicroservice.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)
andconfigStore(ConfigStore)
methods.- Parameters:
config
- The configuration.- Returns:
- This object.
-
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:
-
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" ).
-
The
-
Resolve any
"*.cfg" file that can be found in the working directory. -
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.
-
Resolve file first in working directory, then in classpath, using the following names:
-
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
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 tofalse .- 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
Specifies the console input and output.If not specified, uses the console returned by
System.console()
. If that is not available, usesSystem.in
andSystem.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
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 byMicroservice.getConfig()
and the var resolver returned byMicroservice.getVarResolver()
.- Parameters:
vars
- The set of variables to append to the var resolver builder.- Returns:
- This object.
-
varBean
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 byMicroservice.getConfig()
and the var resolver returned byMicroservice.getVarResolver()
.- Type Parameters:
T
- The bean type.- Parameters:
c
- The bean type.value
- The bean.- Returns:
- This object.
-
workingDir
Specifies the directory to use to resolve the config file and other paths defined with the config file.- Parameters:
workingDir
- The working directory, ornull to use the underlying working directory.- Returns:
- This object.
-
workingDir
Specifies the directory to use to resolve the config file and other paths defined with the config file.- Parameters:
workingDir
- The working directory, ornull 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
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.
-