/** * Does the same as modifyInterestOps(), but does not call * wakeup on the selector. Allows adding more modifications * before we wake up the selector. * * @return Returns a <code>this</code> reference for chaining */ public Listener modifyInterestOpsBatch(SelectionKey key, int op, boolean set) { synchronized (modifyInterestOpsQueue) { modifyInterestOpsQueue.addLast(new UpdateInterest(key, op, set)); } return this; }
/** * Process enqueued changes to SelectionKeys. Also see * modifyInterestOps(). */ private void processModifyInterestOps() { synchronized (modifyInterestOpsQueue) { while (!modifyInterestOpsQueue.isEmpty()) { UpdateInterest u = modifyInterestOpsQueue.removeFirst(); u.doUpdate(); } } }
/** * Enqueue change to interest set of SelectionKey. This is a workaround * for an NIO design error that makes it impossible to update interest * sets for a SelectionKey while a select is in progress -- and sometimes * you actually want to do this from other threads, which will then * block. Hence, we make it possible to enqueue requests for * SelectionKey modification in the thread where select runs. * * @return Returns a <code>this</code> reference for chaining */ public Listener modifyInterestOps(SelectionKey key, int op, boolean set) { synchronized (modifyInterestOpsQueue) { modifyInterestOpsQueue.addLast(new UpdateInterest(key, op, set)); } selector.wakeup(); return this; }