Details
-
Bug
-
Status: Resolved
-
Minor
-
Resolution: Won't Fix
-
None
-
None
-
None
Description
If two ExecutionFilter's with default executors are placed in filter chain, for example to separate inbound and outbound events processing, both ExecutorFilters will use same task queue.
acceptor.getFilterChain().addLast("inboundExecutor", new ExecutorFilter(IoEventType.MESSAGE_RECEIVED, IoEventType.SESSION_OPENED, IoEventType.SESSION_CLOSED, IoEventType.MESSAGE_SENT)); acceptor.getFilterChain().addLast("codec", new SomeCodecFilter()); acceptor.getFilterChain().addLast("outboundExecutor", new ExecutorFilter(IoEventType.CLOSE, IoEventType.WRITE));
OrderedThreadPoolExecutor uses TASKS_QUEUE key to get task queue from session attributes. TASKS_QUEUE behaves such way that different OrderedThreadPoolExecutor's refer to the same task queue stored in session attributes.
private final AttributeKey TASKS_QUEUE = new AttributeKey(getClass(), "tasksQueue");
I'm not sure if it's OrderedThreadPoolExecutor or AttributeKey bug.
As a result only one ExecutorFilter processes task originating from both ExecutorFilters.
Workaround is to inherit Executor classes from OrderedThreadPoolExecutor and pass its instances to ExecutorFilter constructor, e.g.:
class InboundExecutor extends OrderedThreadPoolExecutor { } class OutboundExecutor extends OrderedThreadPoolExecutor { } acceptor.getFilterChain().addLast("inboundExecutor", new ExecutorFilter(new InvoundExecutor(), IoEventType.MESSAGE_RECEIVED, IoEventType.SESSION_OPENED, IoEventType.SESSION_CLOSED, IoEventType.MESSAGE_SENT)); acceptor.getFilterChain().addLast("outboundExecutor", new ExecutorFilter(new OuboundExecutor(), IoEventType.CLOSE, IoEventType.WRITE));