- All Implemented Interfaces:
ApplicationMetadata
,Component
,Receiver<Transmittable>
,Transmitter<Transmittable>
,Named
,NamedObject
,PackagePathed
,Versioned
,Broadcaster
,Listener
,Repeater
,Transceiver
- Direct Known Subclasses:
Server
Messaging
Because this class extends BaseRepeater
and has a Logger
that listens to the application class, all
Application
s automatically inherit logging functionality via the convenience methods in Repeater
.
Startup
The Application
object should be constructed in the main(String[]) Java entrypoint and the run(String[])
method should be called. This can be done in one step:
public static class MyApplication extends Application { public static void main( String[] arguments) { new MyApplication().run(arguments); } [...] }
Command Line Parsing
For within the application implementation in the onRun()
method, the Application
class provides
convenient access to the parsed command line:
commandLine()
- Gets the parsed command linearguments()
- Gets command line arguments (excluding switches)argument(ArgumentParser)
- Gets the first command line argument (excluding switches)argument(int, ArgumentParser)
- Gets the nth argument using the given argument parserget(SwitchParser)
- Gets the switch value for the given switch parserhas(SwitchParser)
- Determines if there is a switch value for the given switch parserexit(String, Object...)
- Exits the application displaying the given message and command line usage
Important Note: Project Initialization
All applications must pass one or more Project
s to the Application
constructor to ensure that all of
the application's dependent project(s) are correctly initialized. See Project
for details.
Running
The run(String[])
method will perform the following steps:
- Call
onProjectInitializing()
- Initialize and install the
Project
passed to the constructor - Call
onProjectInitialized()
- Parse command line arguments using:
- The
ArgumentParser
s returned byargumentParsers()
- The
SwitchParser
s returned byswitchParsers()
- The
- Call the application implementation in
onRun()
- Author:
- jonathanl (shibo)
- See Also:
BaseRepeater
,CommandLine
,SwitchParser
,ArgumentParser
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
A unique string identifier for a KivaKitApplication
. -
Method Summary
Modifier and TypeMethodDescription<T> T
argument(int index, ArgumentParser<T> parser)
<T> T
argument(ArgumentParser<T> parser)
commandLineDescription(String title)
void
Exits the application with the given message formatted byMessage.format(String, Object...)
static Application
get()
<T> T
get(SwitchParser<T> parser)
<T> T
get(SwitchParser<T> parser, T defaultValue)
<T> boolean
has(SwitchParser<T> parser)
localizedProperties(Locale locale)
project()
void
Runs the application by callingonRun()
given the arguments from the Java main(String[]) application entrypoint.void
version()
Methods inherited from class com.telenav.kivakit.component.BaseComponent
lookup, registerAllSettings, registerAllSettingsIn, registerAllSettingsIn, registerObject, registerSettingsObject, require, settings
Methods inherited from class com.telenav.kivakit.kernel.messaging.repeaters.BaseRepeater
message, onMessage
Methods inherited from class com.telenav.kivakit.kernel.messaging.broadcasters.Multicaster
addListener, clearListeners, debugClassContext, debugCodeContext, debugCodeContext, hasListeners, isDeaf, listenerChain, listeners, listenerTree, messageSource, messageSource, objectName, removeListener, transmit
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface com.telenav.kivakit.commandline.ApplicationMetadata
callSystemExitOnUnrecoverableError
Methods inherited from interface com.telenav.kivakit.kernel.messaging.Broadcaster
addListener, addListener, clearListeners, hasListeners, messageSource, messageSource, onHandle, onTransmit, removeListener, silence, transmit, transmit, transmitAll
Methods inherited from interface com.telenav.kivakit.component.Component
lookup, lookup, lookup, packageResource, registerDeployment, registerObject, registerObject, registerObject, registerSettingsObject, registry, relativePackage, relativeResource, require, require, require, settings, settings, settings, settingsRegistry
Methods inherited from interface com.telenav.kivakit.kernel.messaging.Listener
isDeaf, listenTo, listenTo, message, onMessage
Methods inherited from interface com.telenav.kivakit.kernel.interfaces.naming.NamedObject
objectName, objectName
Methods inherited from interface com.telenav.kivakit.kernel.language.paths.PackagePathed
packagePath
Methods inherited from interface com.telenav.kivakit.kernel.messaging.Repeater
onHandle, onReceive, receive
Methods inherited from interface com.telenav.kivakit.kernel.messaging.Transceiver
announce, debug, debugClassContext, debugCodeContext, debugCodeContext, fatal, fatal, glitch, glitch, glitch, glitch, halt, halt, handle, ifDebug, illegalArgument, illegalState, illegalState, information, isDebugOn, isOn, narrate, problem, problem, problem, problem, quibble, quibble, quibble, quibble, trace, trace, trace, trace, warning, warning, warning, warning
-
Method Details
-
get
- Returns:
- The currently running application
-
arguments
- Returns:
- All non-switch command line arguments
-
commandLine
- Returns:
- The parsed command line
-
commandLineDescription
- Returns:
- This command line in a text box intended for user feedback when starting an application
-
description
- Specified by:
description
in interfaceApplicationMetadata
- Returns:
- A description of the application for use in help
-
exit
Exits the application with the given message formatted byMessage.format(String, Object...)
- Parameters:
message
- The messagearguments
- Arguments to interpolate into the message
-
identifier
-
project
-
properties
-
run
Runs the application by callingonRun()
given the arguments from the Java main(String[]) application entrypoint. Operations occur in this order:onRunning()
is called to indicate that running is about to start- Command line arguments are validated and parsed into a
CommandLine
onConfigureListeners()
is called to allow redirection of outputonProjectInitializing()
is called before theProject
for this application is initializedProject.initialize()
is calledonProjectInitialized()
is calledonRun()
is calledonRan()
is called- The application exits
- Parameters:
arguments
- Command line arguments to parse
-
showCommandLine
public void showCommandLine() -
version
-