Class Application

java.lang.Object
com.zeroc.Ice.Application
com.zeroc.Glacier2.Application

public abstract class Application extends Application
An extension of com.zeroc.Ice.Application that makes it easy to write Glacier2 applications.

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.

See Also:
  • Constructor Details

    • Application

      public Application()
      Initializes an instance that calls Communicator.shutdown() if a signal is received.
    • Application

      public Application(SignalPolicy signalPolicy)
      Initializes an instance that handles signals according to the signal policy.
      Parameters:
      signalPolicy - Determines how to respond to signals.
      See Also:
  • Method Details

    • createSession

      public abstract SessionPrx createSession()
      Creates a new Glacier2 session. A call to createSession always precedes a call to runWithSession. If com.zeroc.Ice.LocalException is thrown from this method, the application is terminated.
      Returns:
      The Glacier2 session.
    • runWithSession

      public abstract int runWithSession(String[] args) throws Application.RestartSessionException
      Called once the communicator has been initialized and the Glacier2 session has been established. A derived class must implement runWithSession, which is the application's starting method.
      Parameters:
      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.
      Returns:
      The runWithSession method should return zero for successful termination, and non-zero otherwise. Application.main returns the value returned by runWithSession.
      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

      public final int run(String[] args)
      Run should not be overridden for com.zeroc.Glacier2.Application. Instead runWithSession should be used.
      Specified by:
      run in class Application
      Parameters:
      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.
      Returns:
      The run method should return zero for successful termination, and non-zero otherwise. Application.main returns the value returned by run.
    • restart

      public static void restart() throws Application.RestartSessionException
      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

      public static RouterPrx router()
      Returns the Glacier2 router proxy
      Returns:
      The router proxy.
    • session

      public static SessionPrx session()
      Returns the Glacier2 session proxy
      Returns:
      The session proxy.
    • categoryForClient

      public static String categoryForClient() throws SessionNotExistException
      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

      public static Identity createCallbackIdentity(String name) throws SessionNotExistException
      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

      public static ObjectPrx addWithUUID(Object servant) throws SessionNotExistException
      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

      public static ObjectAdapter objectAdapter() throws SessionNotExistException
      Creates an object adapter for callback objects.
      Returns:
      The object adapter.
      Throws:
      SessionNotExistException - No session exists.
    • doMain

      protected int doMain(String[] args, InitializationData initData)
      Overrides:
      doMain in class Application