- All Implemented Interfaces:
I2PThread.OOMEventListener
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
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final RouterContextThe router context to log and act on.private final AtomicBooleanTrue once the listener has fired.Constructor Summary
ConstructorsMethod Summary
Modifier and TypeMethodDescriptionstatic StringThe best guess path for the wrapper.config file.private static booleanBest guess if running from a Debian package.voidHandle out-of-memory error by shutting down router gracefully.
Field Details
_context
The router context to log and act on._wasCalled
True once the listener has fired.
Constructor Details
OOMListener
Create a new out-of-memory event listener.- Parameters:
ctx- the router context for accessing router services
Method Details
outOfMemory
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:
outOfMemoryin interfaceI2PThread.OOMEventListener- Parameters:
oom- the out-of-memory error that triggered this handler
isDebianPackage
Best guess if running from a Debian package.- Parameters:
ctx- the router context, used for the base directory and the update property- Returns:
- true if the install directory and settings match a Debian package install
getWrapperConfigPath
The best guess path for the 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