public class MicroserviceBuilder extends Object
Microservice
class.
Instances of this class are created using Microservice.create()
.
Modifier | Constructor and Description |
---|---|
protected |
MicroserviceBuilder()
Constructor.
|
protected |
MicroserviceBuilder(MicroserviceBuilder copyFrom)
Copy constructor.
|
Modifier and Type | Method and Description |
---|---|
MicroserviceBuilder |
args(Args args)
Specifies the command-line arguments passed into the Java command.
|
MicroserviceBuilder |
args(String... args)
Specifies the command-line arguments passed into the Java command.
|
Microservice |
build()
Instantiate a new microservice using the settings defined on this builder.
|
MicroserviceBuilder |
config(Config config)
Specifies the config for initializing this microservice.
|
MicroserviceBuilder |
configName(String configName)
Specifies the config name for initializing this microservice.
|
MicroserviceBuilder |
configStore(ConfigStore configStore)
Specifies the config store to use for storing and retrieving configurations.
|
MicroserviceBuilder |
console(Scanner consoleReader,
PrintWriter consoleWriter)
Specifies the console input and output.
|
MicroserviceBuilder |
consoleCommands(Class<? extends ConsoleCommand>... consoleCommands)
Specifies console commands to make available on the Java console.
|
MicroserviceBuilder |
consoleCommands(ConsoleCommand... consoleCommands)
Specifies console commands to make available on the Java console.
|
MicroserviceBuilder |
consoleEnabled(boolean consoleEnabled)
Specifies that the Java console is enabled for this microservice.
|
MicroserviceBuilder |
copy()
Creates a copy of this builder.
|
MicroserviceBuilder |
listener(MicroserviceListener listener)
Registers an event listener for this microservice.
|
MicroserviceBuilder |
logConfig(LogConfig logConfig)
Specifies logging instructions for the microservice.
|
MicroserviceBuilder |
logger(Logger logger)
Specifies the logger used by the microservice and returned by the
Microservice.getLogger() method. |
MicroserviceBuilder |
manifest(Object value)
Specifies the manifest file of the jar file this microservice is contained within.
|
protected File |
resolveFile(String path)
Resolves the specified path.
|
MicroserviceBuilder |
varContext(String name,
Object object)
Adds a var resolver context object for vars defined in the configuration and var resolver.
|
MicroserviceBuilder |
vars(Class<? extends Var>... vars)
Augments the set of variables defined in the configuration and var resolver.
|
MicroserviceBuilder |
workingDir(File workingDir)
Specifies the directory to use to resolve the config file and other paths defined with the config file.
|
MicroserviceBuilder |
workingDir(String workingDir)
Specifies the directory to use to resolve the config file and other paths defined with the config file.
|
protected MicroserviceBuilder()
protected MicroserviceBuilder(MicroserviceBuilder copyFrom)
copyFrom
- The builder to copy settings from.public MicroserviceBuilder copy()
public Microservice build() throws Exception
Exception
- Error occurred.public MicroserviceBuilder args(Args args)
This is required if you use Microservice.getArgs()
or
args
- The command-line arguments passed into the Java command as a pre-parsed Args
object.public MicroserviceBuilder args(String... args)
This is required if you use Microservice.getArgs()
or
args
- The command-line arguments passed into the Java command as the raw command-line arguments.public MicroserviceBuilder manifest(Object value) throws IOException
This is required if you use Microservice.getManifest()
.
It's also used to locate initialization values such as
If you do not specify the manifest file, we attempt to resolve it through the following methods:
value
- The manifest file of this microservice.
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.
IOException
- Thrown by underlying stream.public MicroserviceBuilder logger(Logger logger)
Microservice.getLogger()
method.
Calling this method overrides the default logging mechanism controlled by the logConfig(LogConfig)
method.
logger
- The logger to use for logging microservice messages.public MicroserviceBuilder logConfig(LogConfig logConfig)
If not specified, the values are taken from the
This method is ignored if logger(Logger)
is used to set the microservice logger.
logConfig
- The log configuration.public MicroserviceBuilder config(Config config)
Calling this method overrides the default configuration controlled by the configName(String)
and configStore(ConfigStore)
methods.
config
- The configuration.public MicroserviceBuilder configName(String configName)
If you do not specify the config file location, we attempt to resolve it through the following methods:
If no configuration file is found, and empty in-memory configuration is used.
configName
- The configuration name.public MicroserviceBuilder configStore(ConfigStore configStore)
By default, we use a ConfigFileStore
store for configuration files.
configStore
- The configuration name.public MicroserviceBuilder consoleEnabled(boolean consoleEnabled)
If not specified, this value is taken from the
consoleEnabled
- public MicroserviceBuilder consoleCommands(Class<? extends ConsoleCommand>... consoleCommands) throws ExecutableException
Note that these are ignored if the console is not enabled via consoleEnabled(boolean)
.
This list augments the commands defined via the
This method can only be used on console commands with no-arg constructors.
consoleCommands
- The list of console commands to append to the list of available commands.ExecutableException
- Exception occurred on invoked constructor/method/field.public MicroserviceBuilder consoleCommands(ConsoleCommand... consoleCommands)
Note that these are ignored if the console is not enabled via consoleEnabled(boolean)
.
This list augments the commands defined via the
consoleCommands
- The list of console commands to append to the list of available commands.public MicroserviceBuilder console(Scanner consoleReader, PrintWriter consoleWriter)
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)
.
consoleReader
- The console input.consoleWriter
- The console output.public MicroserviceBuilder vars(Class<? extends Var>... vars)
This calls VarResolverBuilder.vars(Class[])
on the var resolver used to construct the configuration
object returned by Microservice.getConfig()
and the var resolver returned by Microservice.getVarResolver()
.
vars
- The set of variables to append to the var resolver builder.public MicroserviceBuilder varContext(String name, Object object)
This calls VarResolverBuilder.contextObject(String,Object)
on the var resolver used to construct the configuration
object returned by Microservice.getConfig()
and the var resolver returned by Microservice.getVarResolver()
.
name
- The context object name.object
- The context object.public MicroserviceBuilder workingDir(File workingDir)
workingDir
- The working directory, or public MicroserviceBuilder workingDir(String workingDir)
workingDir
- The working directory, or public MicroserviceBuilder listener(MicroserviceListener listener)
listener
- An event listener for this microservice.protected File resolveFile(String path)
If the working directory has been explicitly specified, relative paths are resolved relative to that.
path
- The path to resolve.Copyright © 2016–2019 The Apache Software Foundation. All rights reserved.