net.i2p.router.tasks

## Class OOMListener

- java.lang.Object
- - net.i2p.router.tasks.OOMListener

- All Implemented Interfaces:
    I2PThread.OOMEventListener

      public class OOMListener
      extends Object
      implements I2PThread.OOMEventListener

  Out-of-memory error handler for emergency router shutdown. This listener is registered with the I2PThread system to handle OutOfMemoryError events. When the JVM runs out of memory, this class attempts to perform an orderly shutdown of the router to prevent data corruption and hung processes. The handler is designed to be resilient against additional OOM errors during the shutdown process and will make best-effort attempts to:
  - Clear caches to free memory
  - Log diagnostic information
  - Generate thread dumps for debugging
  - Shutdown the router with appropriate exit code

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `OOMListener(RouterContext ctx)` Create a new out-of-memory event listener.

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `static String` | `getWrapperConfigPath(RouterContext ctx)` Get the best guess path for wrapper.config file.
    `void` | `outOfMemory(OutOfMemoryError oom)` Handle out-of-memory error by shutting down router gracefully.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### OOMListener

          public OOMListener(RouterContext ctx)

      Create a new out-of-memory event listener.
      Parameters:
        `ctx` - the router context for accessing router services

  - ### Method Detail

    - #### getWrapperConfigPath

          public static String getWrapperConfigPath(RouterContext ctx)

      Get the best guess path for wrapper.config file. This method attempts to determine the location of the wrapper configuration file based on the installation type and platform. Since there's no system property that provides the actual path, this method makes educated guesses based on common installation patterns. The path determination follows these rules:
      - Linux service: /etc/i2p/wrapper.config (or /usr/share/i2p for Gentoo)
      - Debian package: /etc/i2p/wrapper.config
      - Other installations: {baseDir}/wrapper.config
      Note: The returned path may not exist - this is just the best guess for where the file should be located.
      Parameters:
        `ctx` - the router context for determining installation type
      Returns:
        the probable path to wrapper.config file

    - #### outOfMemory

          public void outOfMemory(OutOfMemoryError oom)

      Handle out-of-memory error by shutting down router gracefully. This method is called when the JVM runs out of memory. It attempts to perform emergency cleanup and shutdown the router to prevent further corruption or hangs. The method is designed to be resilient against additional OOM errors during the shutdown process and will attempt to:
      - Prevent multiple parallel shutdowns
      - Increase thread priority to aid shutdown
      - Clear caches to free memory
      - Log memory status and configuration hints
      - Generate thread dump for debugging
      - Log the event to event log
      - Shutdown router with OOM exit code
      Specified by:
        `outOfMemory` in interface `I2PThread.OOMEventListener`
      Parameters:
        `oom` - the out-of-memory error that triggered this handler