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.
|
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.
|
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)
Inject the I/O streams to the invokable and then calls
Invokable.init() and then
Invokable.execute(). |
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.
|
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 - Implementation to invoke.public 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 - Implementation to invoke.ioStreams - I/O streams.public static void main(Invokable invokable, IO ioStreams, boolean debug)
Invokable.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 void init()
public final String[] getArgs()
public final IO getIoStreams()
InvokablegetIoStreams in interface Invokablereset.public final void setIoStreams(IO ioStreams)
InvokablesetIoStreams in interface InvokableioStreams - Stream object.public 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 © 2012 Sven Strittmatter. All Rights Reserved.