Author: markt Date: Thu Apr 6 19:43:16 2017 New Revision: 1790443 URL: http://svn.apache.org/viewvc?rev=1790443&view=rev Log: Partial fix for https://bz.apache.org/bugzilla/show_bug.cgi?id=47214 Replace explicitly referenced anonymous inner classes in NioBlockingSelector.BlockPoller with named inner classes.
Modified: tomcat/trunk/java/org/apache/catalina/security/SecurityClassLoad.java tomcat/trunk/java/org/apache/tomcat/util/net/NioBlockingSelector.java Modified: tomcat/trunk/java/org/apache/catalina/security/SecurityClassLoad.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/security/SecurityClassLoad.java?rev=1790443&r1=1790442&r2=1790443&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/catalina/security/SecurityClassLoad.java (original) +++ tomcat/trunk/java/org/apache/catalina/security/SecurityClassLoad.java Thu Apr 6 19:43:16 2017 @@ -186,9 +186,9 @@ public final class SecurityClassLoad { // net loader.loadClass(basePackage + "util.net.Constants"); loader.loadClass(basePackage + "util.net.DispatchType"); - loader.loadClass(basePackage + "util.net.NioBlockingSelector$BlockPoller$1"); - loader.loadClass(basePackage + "util.net.NioBlockingSelector$BlockPoller$2"); - loader.loadClass(basePackage + "util.net.NioBlockingSelector$BlockPoller$3"); + loader.loadClass(basePackage + "util.net.NioBlockingSelector$BlockPoller$RunnableAdd"); + loader.loadClass(basePackage + "util.net.NioBlockingSelector$BlockPoller$RunnableCancel"); + loader.loadClass(basePackage + "util.net.NioBlockingSelector$BlockPoller$RunnableRemove"); // security loader.loadClass(basePackage + "util.security.PrivilegedGetTccl"); loader.loadClass(basePackage + "util.security.PrivilegedSetTccl"); Modified: tomcat/trunk/java/org/apache/tomcat/util/net/NioBlockingSelector.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/net/NioBlockingSelector.java?rev=1790443&r1=1790442&r2=1790443&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/tomcat/util/net/NioBlockingSelector.java (original) +++ tomcat/trunk/java/org/apache/tomcat/util/net/NioBlockingSelector.java Thu Apr 6 19:43:16 2017 @@ -214,17 +214,12 @@ public class NioBlockingSelector { protected static class BlockPoller extends Thread { protected volatile boolean run = true; protected Selector selector = null; - protected final SynchronizedQueue<Runnable> events = - new SynchronizedQueue<>(); + protected final SynchronizedQueue<Runnable> events = new SynchronizedQueue<>(); public void disable() { run = false; selector.wakeup();} protected final AtomicInteger wakeupCounter = new AtomicInteger(0); + public void cancelKey(final SelectionKey key) { - Runnable r = new Runnable() { - @Override - public void run() { - key.cancel(); - } - }; + Runnable r = new RunnableCancel(key); events.offer(r); wakeup(); } @@ -248,26 +243,7 @@ public class NioBlockingSelector { final SocketChannel ch = nch.getIOChannel(); if ( ch == null ) return; - Runnable r = new Runnable() { - @Override - public void run() { - SelectionKey sk = ch.keyFor(selector); - try { - if (sk == null) { - sk = ch.register(selector, ops, key); - ref.key = sk; - } else if (!sk.isValid()) { - cancel(sk,key,ops); - } else { - sk.interestOps(sk.interestOps() | ops); - } - }catch (CancelledKeyException cx) { - cancel(sk,key,ops); - }catch (ClosedChannelException cx) { - cancel(sk,key,ops); - } - } - }; + Runnable r = new RunnableAdd(ch, key, ops, ref); events.offer(r); wakeup(); } @@ -278,41 +254,11 @@ public class NioBlockingSelector { final SocketChannel ch = nch.getIOChannel(); if ( ch == null ) return; - Runnable r = new Runnable() { - @Override - public void run() { - SelectionKey sk = ch.keyFor(selector); - try { - if (sk == null) { - if (SelectionKey.OP_WRITE==(ops&SelectionKey.OP_WRITE)) countDown(key.getWriteLatch()); - if (SelectionKey.OP_READ==(ops&SelectionKey.OP_READ))countDown(key.getReadLatch()); - } else { - if (sk.isValid()) { - sk.interestOps(sk.interestOps() & (~ops)); - if (SelectionKey.OP_WRITE==(ops&SelectionKey.OP_WRITE)) countDown(key.getWriteLatch()); - if (SelectionKey.OP_READ==(ops&SelectionKey.OP_READ))countDown(key.getReadLatch()); - if (sk.interestOps()==0) { - sk.cancel(); - sk.attach(null); - } - }else { - sk.cancel(); - sk.attach(null); - } - } - }catch (CancelledKeyException cx) { - if (sk!=null) { - sk.cancel(); - sk.attach(null); - } - } - } - }; + Runnable r = new RunnableRemove(ch, key, ops); events.offer(r); wakeup(); } - public boolean events() { boolean result = false; Runnable r = null; @@ -398,8 +344,103 @@ public class NioBlockingSelector { if ( latch == null ) return; latch.countDown(); } + + + private class RunnableAdd implements Runnable { + + private final SocketChannel ch; + private final NioSocketWrapper key; + private final int ops; + private final KeyReference ref; + + public RunnableAdd(SocketChannel ch, NioSocketWrapper key, int ops, KeyReference ref) { + this.ch = ch; + this.key = key; + this.ops = ops; + this.ref = ref; + } + + @Override + public void run() { + SelectionKey sk = ch.keyFor(selector); + try { + if (sk == null) { + sk = ch.register(selector, ops, key); + ref.key = sk; + } else if (!sk.isValid()) { + cancel(sk, key, ops); + } else { + sk.interestOps(sk.interestOps() | ops); + } + } catch (CancelledKeyException cx) { + cancel(sk, key, ops); + } catch (ClosedChannelException cx) { + cancel(sk, key, ops); + } + } + } + + + private class RunnableRemove implements Runnable { + + private final SocketChannel ch; + private final NioSocketWrapper key; + private final int ops; + + public RunnableRemove(SocketChannel ch, NioSocketWrapper key, int ops) { + this.ch = ch; + this.key = key; + this.ops = ops; + } + + @Override + public void run() { + SelectionKey sk = ch.keyFor(selector); + try { + if (sk == null) { + if (SelectionKey.OP_WRITE==(ops&SelectionKey.OP_WRITE)) countDown(key.getWriteLatch()); + if (SelectionKey.OP_READ==(ops&SelectionKey.OP_READ))countDown(key.getReadLatch()); + } else { + if (sk.isValid()) { + sk.interestOps(sk.interestOps() & (~ops)); + if (SelectionKey.OP_WRITE==(ops&SelectionKey.OP_WRITE)) countDown(key.getWriteLatch()); + if (SelectionKey.OP_READ==(ops&SelectionKey.OP_READ))countDown(key.getReadLatch()); + if (sk.interestOps()==0) { + sk.cancel(); + sk.attach(null); + } + }else { + sk.cancel(); + sk.attach(null); + } + } + }catch (CancelledKeyException cx) { + if (sk!=null) { + sk.cancel(); + sk.attach(null); + } + } + } + + } + + + public static class RunnableCancel implements Runnable { + + private final SelectionKey key; + + public RunnableCancel(SelectionKey key) { + this.key = key; + } + + @Override + public void run() { + key.cancel(); + } + } } + public static class KeyReference { SelectionKey key = null; --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org