Class Application
Applications must create a derived class that implements the
createSession()
and runWithSession(java.lang.String[])
methods.
The base class invokes createSession()
to create a new
Glacier2 session and then invokes runWithSession(java.lang.String[])
in
which the subclass performs its application logic. The base class
automatically destroys the session when runWithSession(java.lang.String[])
returns.
If runWithSession(java.lang.String[])
calls restart()
or raises any of
the exceptions com.zeroc.Ice.ConnectionRefusedException,
com.zeroc.Ice.ConnectionLostException, com.zeroc.Ice.UnknownLocalException,
com.zeroc.Ice.RequestFailedException, or com.zeroc.Ice.TimeoutException, the base
class destroys the current session and restarts the application
with another call to createSession()
followed by
runWithSession(java.lang.String[])
.
The application can optionally override the sessionDestroyed()
callback method if it needs to take action when connectivity with
the Glacier2 router is lost.
A program can contain only one instance of this class.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
This exception is raised if the session should be restarted. -
Constructor Summary
ConstructorsConstructorDescriptionInitializes an instance that callsCommunicator.shutdown()
if a signal is received.Application
(SignalPolicy signalPolicy) Initializes an instance that handles signals according to the signal policy. -
Method Summary
Modifier and TypeMethodDescriptionstatic ObjectPrx
addWithUUID
(Object servant) Adds a servant to the callback object adapter's Active Servant Map with a UUID.static String
Returns the category to be used in the identities of all of the client's callback objects.static Identity
createCallbackIdentity
(String name) Create a new Ice identity for callback objects with the given identity name field.abstract SessionPrx
Creates a new Glacier2 session.protected int
doMain
(String[] args, InitializationData initData) static ObjectAdapter
Creates an object adapter for callback objects.static void
restart()
Called to restart the application's Glacier2 session.static RouterPrx
router()
Returns the Glacier2 router proxyfinal int
Run should not be overridden for com.zeroc.Glacier2.Application.abstract int
runWithSession
(String[] args) Called once the communicator has been initialized and the Glacier2 session has been established.static SessionPrx
session()
Returns the Glacier2 session proxyvoid
Called when the session refresh thread detects that the session has been destroyed.Methods inherited from class com.zeroc.Ice.Application
appName, communicator, defaultInterrupt, destroyOnInterrupt, interrupted, main, main, main, setInterruptHook, shutdownOnInterrupt
-
Constructor Details
-
Application
public Application()Initializes an instance that callsCommunicator.shutdown()
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
-
createSession
Creates a new Glacier2 session. A call tocreateSession
always precedes a call torunWithSession
. Ifcom.zeroc.Ice.LocalException
is thrown from this method, the application is terminated.- Returns:
- The Glacier2 session.
-
runWithSession
Called once the communicator has been initialized and the Glacier2 session has been established. A derived class must implementrunWithSession
, 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
runWithSession
method should return zero for successful termination, and non-zero otherwise.Application.main
returns the value returned byrunWithSession
. - Throws:
Application.RestartSessionException
- If the session should be restarted.
-
sessionDestroyed
public void sessionDestroyed()Called when the session refresh thread detects that the session has been destroyed. A subclass can override this method to take action after the loss of connectivity with the Glacier2 router. This method is called according to the Ice invocation dipsatch rules (in other words, it uses the same rules as an servant upcall or AMI callback). -
run
Run should not be overridden for com.zeroc.Glacier2.Application. InsteadrunWithSession
should be used.- Specified by:
run
in classApplication
- 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
.
-
restart
Called to restart the application's Glacier2 session. This method never returns. The exception produce an application restart when called from the Application main thread.- Throws:
Application.RestartSessionException
- This exception is always thrown.
-
router
Returns the Glacier2 router proxy- Returns:
- The router proxy.
-
session
Returns the Glacier2 session proxy- Returns:
- The session proxy.
-
categoryForClient
Returns the category to be used in the identities of all of the client's callback objects. Clients must use this category for the router to forward callback requests to the intended client.- Returns:
- The category.
- Throws:
SessionNotExistException
- No session exists.
-
createCallbackIdentity
Create a new Ice identity for callback objects with the given identity name field.- Parameters:
name
- The identity name.- Returns:
- The identity with the given name and a unique category.
- Throws:
SessionNotExistException
- No session exists.
-
addWithUUID
Adds a servant to the callback object adapter's Active Servant Map with a UUID.- Parameters:
servant
- The servant to add.- Returns:
- The proxy for the servant.
- Throws:
SessionNotExistException
- No session exists.
-
objectAdapter
Creates an object adapter for callback objects.- Returns:
- The object adapter.
- Throws:
SessionNotExistException
- No session exists.
-
doMain
- Overrides:
doMain
in classApplication
-