java.lang.Object
net.i2p.app.ClientAppManagerImpl
net.i2p.router.startup.RouterAppManager
All Implemented Interfaces:
ClientAppManager

public class RouterAppManagerextends ClientAppManagerImpl
Notify the router of events, and provide methods for client apps to find each other.
  • Field Details

    • _log

      private final Log _log
      Logger for this class.
    • _clients

      private final ConcurrentHashMap<ClientApp, String[]> _clients
      Client apps to the arguments they were started with. This assumes the clients do not override equals().
  • Constructor Details

    • RouterAppManager

      public RouterAppManager(RouterContext ctx)
      Opens the client map and registers a shutdown task.
      Parameters:
      ctx - router context supplying the log manager and shutdown task registration
  • Method Details

    • addAndStart

      public boolean addAndStart(ClientApp app, String[] args)
      Add and start a client application.
      Parameters:
      app - the client application to track and start
      args - the args that were used to instantiate the app, non-null, may be zero-length
      Returns:
      true if the app started; false if startup() threw, in which case it is dropped again
      Throws:
      IllegalArgumentException - if already added
    • getClientApp

      public ClientApp getClientApp(String className, String[] args)
      First known ClientApp with this class name and exact arguments. Caller may then retrieve or control the state of the returned client. A client will generally be found only if it is running or transitioning; after it is stopped it will not be tracked by the manager.
      Parameters:
      className - fully qualified class name of the client application to find
      args - non-null, may be zero-length
      Returns:
      client app or null
    • notify

      public void notify(ClientApp app, ClientAppState state, String message, Exception e)
      Must be called on all state transitions except from UNINITIALIZED to INITIALIZED.
      Specified by:
      notify in interface ClientAppManager
      Overrides:
      notify in class ClientAppManagerImpl
      Parameters:
      app - non-null
      state - non-null
      message - may be null
      e - may be null
    • register

      public boolean register(ClientApp app)
      Register with the manager under the given name, so that other clients may find it. Only required for apps used by other apps.
      Specified by:
      register in interface ClientAppManager
      Overrides:
      register in class ClientAppManagerImpl
      Parameters:
      app - non-null
      Returns:
      true if successful, false if duplicate name
    • unregister

      public void unregister(ClientApp app)
      Unregister with the manager. Name must be the same as that from register(ClientApp). Only required for apps used by other apps.
      Specified by:
      unregister in interface ClientAppManager
      Overrides:
      unregister in class ClientAppManagerImpl
      Parameters:
      app - non-null
    • shutdown

      public void shutdown()
      Shut down all running client applications.
    • getDebugCounts

      public int[] getDebugCounts()
      Debug overview counts as {tracked, running, registered}.
      Returns:
      the counts, never null
    • renderStatusHTML

      public void renderStatusHTML(Writer out) throws IOException
      Table of registered and running router apps with state dots.
      Parameters:
      out - writer to write HTML output to
      Throws:
      IOException - if writing to output fails
    • buildRows

      static List<String[]> buildRows(Map<ClientApp, String[]> clients, Map<String, ClientApp> registered)
      Merge the tracked and registered app maps into one row set of {state, name, class, args}, sorted by name. Tracked apps report their live state and launch args; registered apps that were never tracked report "Registered" with no args. Pure, for unit tests.
      Parameters:
      clients - tracked apps to their launch args
      registered - all registered apps by name
      Returns:
      one row per app, never null
    • dotClass

      static String dotClass(String state)
      Map an app state to its status dot colour: green running, yellow in transition, red failed, grey stopped or never started.
      Parameters:
      state - the app state name
      Returns:
      a shared.css .appdot colour class, never null