Package com.zeroc.Ice
Class Application
java.lang.Object
com.zeroc.Ice.Application
- Direct Known Subclasses:
Application
Utility base class that makes it easy to correctly initialize and finalize
the Ice run time, as well as handle signals. Unless the application specifies
a logger,
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.
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionInitializes an instance that callsCommunicator.destroy()
if a signal is received.Application
(SignalPolicy signalPolicy) Initializes an instance that handles signals according to the signal policy. -
Method Summary
Modifier and TypeMethodDescriptionstatic String
appName()
Returns the value ofappName
that is passed tomain
(which is also the the value ofIce.ProgramName
).static Communicator
Returns the communicator for the application.static void
Clears any shutdown hooks, including any hook established withdestroyOnInterrupt()
orshutdownOnInterrupt()
.static void
InstructsApplication
to callCommunicator.destroy()
on receipt of a signal.protected int
doMain
(String[] args, InitializationData initData) static boolean
Determines whether the application shut down intentionally or was forced to shut down by the JVM.final int
The application must callmain
after it has instantiated the derived class.final int
main
(String appName, String[] args, InitializationData initializationData) The application must callmain
after it has instantiated the derived class.final int
The application must callmain
after it has instantiated the derived class.abstract int
Called once the communicator has been initialized.static void
setInterruptHook
(Runnable newHook) Installs a custom shutdown hook.static void
InstructsApplication
to callCommunicator.shutdown()
on receipt of a signal.
-
Constructor Details
-
Application
public Application()Initializes an instance that callsCommunicator.destroy()
if a signal is received. -
Application
Initializes an instance that handles signals according to the signal policy.- Parameters:
signalPolicy
- Determines how to respond to signals.- See Also:
-
-
Method Details
-
main
The application must callmain
after it has instantiated the derived class.main
creates a communicator, establishes the specified signal policy, and, oncerun
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 ifrun
completes abnormally.- Parameters:
appName
- The name of the application. This parameter is used to initialize the value of theIce.ProgramName
property.args
- The arguments for the application (as passed toMain(String[])
by the operating system.- Returns:
- The value returned by
run
. Ifrun
terminates with an exception, the return value is non-zero.
-
main
The application must callmain
after it has instantiated the derived class.main
creates a communicator, establishes the specified signal policy, and, oncerun
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 ifrun
completes abnormally.- Parameters:
appName
- The name of the application. This parameter is used to initialize the value of theIce.ProgramName
property.args
- Command-line argumentsconfigFile
- The configuration file with which to initialize Ice properties.- Returns:
- The value returned by
run
. Ifrun
terminates with an exception, the return value is non-zero.
-
main
The application must callmain
after it has instantiated the derived class.main
creates a communicator, establishes the specified signal policy, and, oncerun
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 ifrun
completes abnormally.- Parameters:
appName
- The name of the application. This parameter is used to initialize the value of theIce.ProgramName
property.args
- The arguments for the application (as passed toMain(String[])
.initializationData
- Additional data used to initialize the communicator.- Returns:
- The value returned by
run
. Ifrun
terminates with an exception, the return value is non-zero. - See Also:
-
doMain
-
run
Called once the communicator has been initialized. The derived class must implementrun
, which is the application's starting method.- Parameters:
args
- The argument vector for the application.Application
scans the argument vector passed tomain
for options that are specific to the Ice run time and removes them; therefore, the vector passed torun
is free from Ice-related options and contains only options and arguments that are application-specific.- Returns:
- The
run
method should return zero for successful termination, and non-zero otherwise.Application.main
returns the value returned byrun
.
-
appName
Returns the value ofappName
that is passed tomain
(which is also the the value ofIce.ProgramName
). This method is useful mainly for error messages that include the application name. BecauseappName
is a static method, it is available from anywhere in the program.- Returns:
- The name of the application.
-
communicator
Returns the communicator for the application. Becausecommunicator
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 ofApplication
in a program.- Returns:
- The communicator for the application.
-
destroyOnInterrupt
public static void destroyOnInterrupt()InstructsApplication
to callCommunicator.destroy()
on receipt of a signal. This is default signal handling policy established by the default constructor.- See Also:
-
shutdownOnInterrupt
public static void shutdownOnInterrupt()InstructsApplication
to callCommunicator.shutdown()
on receipt of a signal.- See Also:
-
setInterruptHook
Installs a custom shutdown hook. The implementation of the shutdown hook can do whatever cleanup is necessary to shut down the application. The hook is unregistered oncerun
returns. Note that the hook must obey the rules for shutdown hooks; specifically, it must not callexit
.- Parameters:
newHook
- The Runnable to run on shutdown.- See Also:
-
defaultInterrupt
public static void defaultInterrupt()Clears any shutdown hooks, including any hook established withdestroyOnInterrupt()
orshutdownOnInterrupt()
. -
interrupted
public static boolean interrupted()Determines whether the application shut down intentionally or was forced to shut down by the JVM. This is useful for logging purposes.- Returns:
true
if a shutdown hook caused the communicator to shut down; false otherwise.
-