public abstract class Application
extends java.lang.Object
Application installs a per-process logger that logs to the standard
error output.
Applications must create a derived class that implements the run(java.lang.String[]) method.
A program can contain only one instance of this class.
run(java.lang.String[]),
Communicator,
Logger| Modifier and Type | Class and Description |
|---|---|
static class |
Application.AppHook |
| Modifier and Type | Field and Description |
|---|---|
protected static Application.AppHook |
_appHook |
protected static java.lang.String |
_appName |
protected static boolean |
_callbackInProgress |
protected static Communicator |
_communicator |
protected static boolean |
_destroyed |
protected static boolean |
_interrupted |
protected static java.lang.Object |
_mutex |
protected static SignalPolicy |
_signalPolicy |
| Constructor and Description |
|---|
Application()
Initializes an instance that calls
Communicator.shutdown() if
a signal is received. |
Application(SignalPolicy signalPolicy)
Initializes an instance that handles signals according to the signal
policy.
|
| Modifier and Type | Method and Description |
|---|---|
static java.lang.String |
appName()
Returns the value of
appName that is passed to main (which is also the
the value of Ice.ProgramName). |
static Communicator |
communicator()
Returns the communicator for the application.
|
static void |
defaultInterrupt()
Clears any shutdown hooks, including any hook established with
destroyOnInterrupt() or
shutdownOnInterrupt(). |
static void |
destroyOnInterrupt()
Instructs
Application to call Communicator.destroy() on receipt of a signal. |
protected int |
doMain(StringSeqHolder argHolder,
InitializationData initData) |
static boolean |
interrupted()
Determines whether the application shut down intentionally or was forced to shut down by the JVM.
|
int |
main(java.lang.String appName,
java.lang.String[] args)
The application must call
main after it has
instantiated the derived class. |
int |
main(java.lang.String appName,
java.lang.String[] args,
InitializationData initializationData)
The application must call
main after it has
instantiated the derived class. |
int |
main(java.lang.String appName,
java.lang.String[] args,
java.lang.String configFile)
The application must call
main after it has
instantiated the derived class. |
abstract int |
run(java.lang.String[] args)
Called once the communicator has been initialized.
|
static void |
setInterruptHook(java.lang.Thread newHook)
Installs a custom shutdown hook.
|
static void |
shutdownOnInterrupt()
Instructs
Application to call Communicator.shutdown() on receipt of a signal. |
protected static java.lang.String _appName
protected static Communicator _communicator
protected static Application.AppHook _appHook
protected static final java.lang.Object _mutex
protected static boolean _callbackInProgress
protected static boolean _destroyed
protected static boolean _interrupted
protected static SignalPolicy _signalPolicy
public Application()
Communicator.shutdown() if
a signal is received.public Application(SignalPolicy signalPolicy)
signalPolicy - Determines how to respond to signals.SignalPolicypublic final int main(java.lang.String appName,
java.lang.String[] args)
main after it has
instantiated the derived class. main creates
a communicator, establishes the specified signal policy, and,
once run returns, destroys the communicator.
The method prints an error message for any exception that propagates
out of run and ensures that the communicator is
destroyed correctly even if run completes abnormally.
appName - The name of the application. This parameter is used to initialize
the value of the Ice.ProgramName property.args - The arguments for the application (as passed to Main(String[])
by the operating system.run. If run terminates with an exception,
the return value is non-zero.public final int main(java.lang.String appName,
java.lang.String[] args,
java.lang.String configFile)
main after it has
instantiated the derived class. main creates
a communicator, establishes the specified signal policy, and,
once run returns, destroys the communicator.
The method prints an error message for any exception that propagates
out of run and ensures that the communicator is
destroyed correctly even if run completes abnormally.
appName - The name of the application. This parameter is used to initialize
the value of the Ice.ProgramName property.args - The command-line arguments.configFile - The configuration file with which to initialize
Ice properties.run. If run terminates with an exception,
the return value is non-zero.public final int main(java.lang.String appName,
java.lang.String[] args,
InitializationData initializationData)
main after it has
instantiated the derived class. main creates
a communicator, establishes the specified signal policy, and,
once run returns, destroys the communicator.
The method prints an error message for any exception that propagates
out of run and ensures that the communicator is
destroyed correctly even if run completes abnormally.
appName - The name of the application. This parameter is used to initialize
the value of the Ice.ProgramName property.args - The arguments for the application (as passed to Main(String[]).initializationData - Additional data used to initialize the communicator.run. If run terminates with an exception,
the return value is non-zero.InitializationDataprotected int doMain(StringSeqHolder argHolder, InitializationData initData)
public abstract int run(java.lang.String[] args)
run, which is the application's starting method.args - The argument vector for the application. Application
scans the argument vector passed to main for options that are
specific to the Ice run time and removes them; therefore, the vector passed
to run is free from Ice-related options and contains only options
and arguments that are application-specific.run method should return zero for successful termination, and
non-zero otherwise. Application.main returns the value returned by run.public static java.lang.String appName()
appName that is passed to main (which is also the
the value of Ice.ProgramName). This method is useful mainly for error messages that
include the application name. Because appName is a static method, it is available
from anywhere in the program.public static Communicator communicator()
communicator is a static method,
it permits access to the communicator from anywhere in the program. Note that, as a consequence,
you cannot have more than one instance of Application in a program.public static void destroyOnInterrupt()
Application to call Communicator.destroy() on receipt of a signal.
This is default signal handling policy established by the default constructor.Communicator.destroy()public static void shutdownOnInterrupt()
Application to call Communicator.shutdown() on receipt of a signal.Communicator.shutdown()public static void setInterruptHook(java.lang.Thread newHook)
run returns.
Note that the hook must obey the rules for shutdown hooks; specifically,
it must not call exit.newHook - The thread to run on shutdown.Runtime.addShutdownHook(java.lang.Thread)public static void defaultInterrupt()
destroyOnInterrupt() or
shutdownOnInterrupt().public static boolean interrupted()
true if a shutdown hook caused the communicator to shut down; false otherwise.