Uploaded image for project: 'MINA'
  1. MINA
  2. DIRMINA-912

Different instances of OrderedThreadPoolExecutor may use same task queue

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Minor
    • Resolution: Won't Fix
    • Affects Version/s: None
    • Fix Version/s: 2.0.8
    • Component/s: None
    • Labels:
      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));
      

        Activity

        Hide
        elecharny Emmanuel Lecharny added a comment -

        Changing the way the executor filter works would be complicated. Typically, we would have to define an instance based task queue.

        The workaround seems good enough for the rare case where you need 2 executor filters.

        This behaviour is likely to evolve in MINA3.

        Show
        elecharny Emmanuel Lecharny added a comment - Changing the way the executor filter works would be complicated. Typically, we would have to define an instance based task queue. The workaround seems good enough for the rare case where you need 2 executor filters. This behaviour is likely to evolve in MINA3.

          People

          • Assignee:
            Unassigned
            Reporter:
            asitnikov Anton Sitnikov
          • Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development