OF-3180: Refactor ConnectionCloseListener implementations for async dispatcher
The dispatcher for ConnectionCloseListener events was updated in a previous commit (for OF-3180) to ensure all listener invocations are executed asynchronously and offloaded from the calling thread. This change allows for significant simplification of the listener implementations, as they no longer need to manually wrap their logic in CompletableFuture.runAsync or thenRunAsync.
This commit removes redundant async wrapping in all ConnectionCloseListener implementations and uses the same executor for all async work.
OF-3179: Priority-based ConnectionCloseListener execution
Ensures consistency in listener execution. Critical cleanup runs before third-party listeners to prevent stale session state.
- Added `getPriority()` to `ConnectionCloseListener` (default: 0, built-in: 100)
- Updated `notifyCloseListeners()` to sort and execute listeners sequentially by priority
- Preserves insertion order for same-priority listeners
OF-3180: Offload ConnectionCloseListener invocation to a dedicated thread pool
Add a dedicated thread pool executor to ConnectionManagerImpl for processing connection events asynchronously.
The notifyCloseListeners() method in AbstractConnection now dispatches listener invocations on this executor rather than invoking them on the calling thread. This prevents blocking or long-running listener implementations (e.g., those performing database or network I/O) from interfering with connection shutdown or I/O processing.
While all connection types benefit, this is particularly important for Netty-based connections where blocking the event loop thread can cause widespread connection stalls.
The new thread pool is configurable via system properties:
- `xmpp.connectionmanager.eventexecutor.threads` (default: 16)
- `xmpp.connectionmanager.eventexecutor.timeout` (default: 60s)
Clarify connection close semantics in listener Javadoc
Expand the listener Javadoc to clearly document that a connection closure does not necessarily imply session closure. Add guidance warning implementers not to make this assumption and direct them to SessionEventListener for reliable session lifecycle events.
org.mockito.exceptions.misusing.WrongTypeOfReturnValue:
CertificateStoreManager cannot be returned by getConnectionManager()
getConnectionManager() should return ConnectionManager
***
If you're unsure why you're getting above error read on.
Due to the nature of the syntax above problem might occur because:
1. This exception *might* occur in wrongly written multi-threaded tests.
Please refer to Mockito FAQ on limitations of concurrency testing.
(58 more lines...)