trait App extends Closable with CloseAwaitably
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.
object MyApp extends App { val n = flag("n", 100, "Number of items to process") def main() { for (i <- 0 until n()) process(i) } }
Note that a missing main
is OK: mixins may provide behavior that
does not require defining a custom main
method.
- Alphabetic
- By Inheritance
- App
- CloseAwaitably
- CloseAwaitably0
- Awaitable
- Closable
- AnyRef
- Any
- Hide All
- Show All
- Public
- All
Value Members
-
final
def
!=(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
final
def
##(): Int
- Definition Classes
- AnyRef → Any
-
final
def
==(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
final
val
MinGrace: Duration
Minimum duration to allow for exits to be processed.
-
def
allowUndefinedFlags: Boolean
Whether or not to accept undefined flags
Whether or not to accept undefined flags
- Attributes
- protected
-
def
args: Array[String]
The remaining, unparsed arguments
-
final
def
asInstanceOf[T0]: T0
- Definition Classes
- Any
-
def
clone(): AnyRef
- Attributes
- protected[java.lang]
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
close(deadline: Time): Future[Unit]
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.
- Definition Classes
- App → Closable
-
def
close(after: Duration): Future[Unit]
- Definition Classes
- Closable
-
final
def
close(): Future[Unit]
- Definition Classes
- Closable
-
def
closeAwaitably(f: ⇒ Future[Unit]): Future[Unit]
- Attributes
- protected
- Definition Classes
- CloseAwaitably0
-
final
def
closeOnExit(closable: Closable): Unit
Close
closable
when shutdown is requested.Close
closable
when shutdown is requested. Closables are closed in parallel.- Attributes
- protected
-
def
defaultCloseGracePeriod: Duration
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 asclose(grace)
. -
final
def
eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
def
equals(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
def
exitOnError(reason: String): Unit
- Attributes
- protected
-
def
failfastOnFlagsNotParsed: Boolean
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 usingfalse
.- Attributes
- protected
-
def
finalize(): Unit
- Attributes
- protected[java.lang]
- Definition Classes
- AnyRef
- Annotations
- @throws( classOf[java.lang.Throwable] )
-
val
flag: Flags
The com.twitter.app.Flags instance associated with this application
-
final
def
getClass(): Class[_]
- Definition Classes
- AnyRef → Any
-
def
hashCode(): Int
- Definition Classes
- AnyRef → Any
-
final
def
init(f: ⇒ Unit): Unit
Invoke
f
before anything else (including flag parsing).Invoke
f
before anything else (including flag parsing).- Attributes
- protected
-
final
def
isInstanceOf[T0]: Boolean
- Definition Classes
- Any
-
def
isReady(implicit permit: CanAwait): Boolean
- Definition Classes
- CloseAwaitably0 → Awaitable
- final def main(args: Array[String]): Unit
-
val
name: String
The name of the application, based on the classname
-
final
def
ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- final def nonExitingMain(args: Array[String]): Unit
-
final
def
notify(): Unit
- Definition Classes
- AnyRef
-
final
def
notifyAll(): Unit
- Definition Classes
- AnyRef
-
final
def
onExit(f: ⇒ Unit): Unit
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 orcloseDeadline
expires.- Attributes
- protected
-
final
def
postmain(f: ⇒ Unit): Unit
Invoke
f
after the user's main has exited.Invoke
f
after the user's main has exited.- Attributes
- protected
-
final
def
premain(f: ⇒ Unit): Unit
Invoke
f
right before the user's main is invoked.Invoke
f
right before the user's main is invoked.- Attributes
- protected
-
def
ready(timeout: Duration)(implicit permit: CanAwait): App.this.type
- Definition Classes
- CloseAwaitably0 → Awaitable
-
def
result(timeout: Duration)(implicit permit: CanAwait): Unit
- Definition Classes
- CloseAwaitably0 → Awaitable
-
final
def
synchronized[T0](arg0: ⇒ T0): T0
- Definition Classes
- AnyRef
-
def
toString(): String
- Definition Classes
- AnyRef → Any
-
final
def
wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )