public abstract class InvokableAdapter extends Object implements Invokable
Extend this class in your client code.
Example:
public final class MyApp extends InvokableAdapter {
public MyApp(final String[] args) {
super(args);
}
public static void main(final String[] args) {
InvokableAdapter.main(new MyApp(args));
}
@Override
public void execute() throws Exception {
registerShutdownHook(new Runnable() {
@Override
public void run() {
// Your shutdown code goes here.
}
});
// Your application code here.
}
}
| Modifier and Type | Field and Description |
|---|---|
private String[] |
args
Copy of the command line arguments.
|
boolean |
debug
Use this field to enable the printing of stack traces.
|
private Exitable |
exiter
Abstraction for
System.exit(int). |
private IO |
ioStreams
I/O streams.
|
private Runtime |
runtime
Runtime for registering callbacks.
|
private ShutDownHook |
shutDownHook
Container for shutdown
callbacks. |
| Constructor and Description |
|---|
InvokableAdapter(String[] args)
Copies the command line arguments.
|
InvokableAdapter(String[] args,
Runtime runtime,
ShutDownHook shutDownHook)
Dedicated constructor.
|
| Modifier and Type | Method and Description |
|---|---|
void |
exit(ExitCode status)
Exits the invokable.
|
void |
exit(int status)
Exits the invokable.
|
String[] |
getArgs()
Get the command line arguments.
|
IO |
getIoStreams()
Get stream object for I/O.
|
void |
init()
Adds shutdown hook to runtime.
|
boolean |
isDebugEnabled()
isDebugEnabled.
|
static void |
main(Invokable invokable)
Invokes
invokable with default I/O. |
static void |
main(Invokable invokable,
IO ioStreams)
Inject the I/O streams to the invokable and then calls
Invokable.init() and then
Invokable.execute(). |
static void |
main(Invokable invokable,
IO ioStreams,
boolean debug)
Deprecated.
|
void |
registerShutdownHook(Callable<Void> callback)
Register a
callback as shut down hook. |
void |
registerShutdownHook(Runnable callback)
Register a
callback as shut down hook. |
void |
setExiter(Exitable exiter)
Set an
exiter to handle exit calls. |
void |
setIoStreams(IO ioStreams)
Set stream object for I/O.
|
public boolean debug
By default this value is false. If you want stack traces from exceptions bubbled up until the main
function, then set this field to true.
private final String[] args
private final ShutDownHook shutDownHook
callbacks.private IO ioStreams
private Exitable exiter
System.exit(int).private final Runtime runtime
public InvokableAdapter(String[] args)
args - Command line arguments.public InvokableAdapter(String[] args, Runtime runtime, ShutDownHook shutDownHook)
args - Command line arguments.runtime - Runtime for registering callbacks.shutDownHook - Object to hold shutdown hooks.public static void main(Invokable invokable)
invokable with default I/O.invokable - must not be nullpublic static void main(Invokable invokable, IO ioStreams)
Invokable.init() and then
Invokable.execute().
This method handles ell thrown Exception and calls System.exit(int).
invokable - must not be nullioStreams - must not be null@Deprecated public static void main(Invokable invokable, IO ioStreams, boolean debug)
main(de.weltraumschaf.commons.application.Invokable, de.weltraumschaf.commons.application.IO) insteadInvokable.init() and then
Invokable.execute().
This method handles ell thrown Exception and calls System.exit(int), and
prints stack trace if debug is true.
invokable - implementation to invokeioStreams - I/O streamsdebug - print stack trace if truepublic final boolean isDebugEnabled()
InvokableisDebugEnabled.
isDebugEnabled in interface Invokablepublic final void init()
public final String[] getArgs()
public final IO getIoStreams()
InvokablegetIoStreams in interface Invokablenull, always same instance until it was
resetpublic final void setIoStreams(IO ioStreams)
InvokablesetIoStreams in interface InvokableioStreams - must not be nullpublic final void registerShutdownHook(Runnable callback)
callback as shut down hook.callback - must not be nullpublic final void registerShutdownHook(Callable<Void> callback)
callback as shut down hook.callback - must not be nullpublic final void exit(int status)
Invokablepublic final void exit(ExitCode status)
InvokableCopyright © 2014 Sven Strittmatter. All Rights Reserved.