Minimum duration to allow for exits to be processed.
Whether or not to accept undefined flags
Whether or not to accept undefined flags
The remaining, unparsed arguments
Notify the application that it may stop running.
Notify the application that it may stop running. Returns a Future that is satisfied when the App has been torn down or errors at the deadline.
Close closable
when shutdown is requested.
Close closable
when shutdown is requested. Closables are closed in parallel.
Register a closable
to be closed on application shutdown after those registered
via closeOnExit
.
Register a closable
to be closed on application shutdown after those registered
via closeOnExit
.
Application shutdown occurs in two sequential phases to allow explicit encoding of resource lifecycle relationships. Concretely this is useful for encoding that a monitoring resource should outlive a monitored resource. In all cases, the close deadline is enforced.
Default amount of time to wait for shutdown.
Default amount of time to wait for shutdown.
This value is not used as a default if close()
is called without parameters. It simply
provides a default value to be passed as close(grace)
.
The details Fn may be an expensive operation (which could fail).
The details Fn may be an expensive operation (which could fail). We want to
ensure that we've at least written the reason
field to System.err before
attempting to write the detail
field so that users will at a minimum see the
reason
for the exit regardless of any extra details.
Exit on error with the given reason
String
Exit on error with the given reason
String
Exit on error with the given Throwable
Exit on error with the given Throwable
Users of this code should override this to true
so that
you fail-fast instead of being surprised at runtime by code that
is reading from flags before they have been parsed.
Users of this code should override this to true
so that
you fail-fast instead of being surprised at runtime by code that
is reading from flags before they have been parsed.
Ideally this would default to true
, however, in order to avoid
breaking existing users, it was introduced using false
.
The com.twitter.app.Flags instance associated with this application
Invoke f
before anything else (including flag parsing).
Invoke f
before anything else (including flag parsing).
Programmatically specify which implementations to use in LoadService.apply for the given interfaces.
Programmatically specify which implementations to use in LoadService.apply for the given interfaces. This allows applications to circumvent the standard service loading mechanism when needed. It may be useful if the application has a broad and/or rapidly changing set of dependencies.
For example, to require SuperCoolMetrics
be used as the
com.twitter.finagle.stats.StatsReceiver
implementation:
import com.initech.SuperCoolMetrics import com.twitter.app.App import com.twitter.app.LoadService.Binding import com.twitter.finagle.stats.StatsReceiver class MyApp extends App { val implementationToUse = new SuperCoolMetrics() override protected[this] val loadServiceBindings: Seq[Binding[_]] = { Seq(new Binding(classOf[StatsReceiver], implementationToUse)) } def main(): Unit = { val loaded = LoadService[StatsReceiver]() assert(Seq(implementationToUse) == loaded) } }
If this is called for a Class[T]
after LoadService.apply
has been called for that same interface, an IllegalStateException
will be thrown. For this reason, bindings are done as early
as possible in the application lifecycle, before even inits
and flag parsing.
a mapping from Class
to the 1 or more implementations to
be used by LoadService.apply for that interface.
this should not generally be used by "libraries" as it forces their user's implementation choice.
The name of the application, based on the classname
Invoke f
when shutdown is requested.
Invoke f
when shutdown is requested. Exit hooks run in parallel and are
executed after all postmains complete. The thread resumes when all exit
hooks complete or closeDeadline
expires.
Parse the command line arguments as an Array of Strings.
Parse the command line arguments as an Array of Strings. The default implementation parses the given String[] as Flag input values.
Users may override this method to specify different functionality.
String Array which represents the command line input given to the application.
Invoke f
after the user's main has exited.
Invoke f
after the user's main has exited.
Invoke f
right before the user's main is invoked.
Invoke f
right before the user's main is invoked.
By default any failure during the graceful shutdown portion of an App's lifecycle bubbles up and causes non-zero return codes in the process.
By default any failure during the graceful shutdown portion of an App's lifecycle
bubbles up and causes non-zero return codes in the process. Setting this to false
allows an application to suppress these errors and express that graceful shutdown logic
should not be a determinant of the process exit code.
A composable application trait that includes flag parsing as well as basic application lifecycle (pre- and post- main). Flag parsing is done via com.twitter.app.Flags, an instance of which is defined in the member
flag
. Applications should be constructed with modularity in mind, and common functionality should be extracted into mixins.Flags should only be constructed in the constructor, and should only be read in the premain or later, after they have been parsed.
Note that a missing
main
is OK: mixins may provide behavior that does not require defining a custommain
method.