From 30b77b086c0e7f959431000d303acc0014271581 Mon Sep 17 00:00:00 2001 From: fhanik Date: Fri, 9 Mar 2007 23:38:29 +0000 Subject: [PATCH] added fairness counter, using this counter, I will be able to make sure that connections are treated evenly in my next revision of the NioEndpoint. No point in having 20k connections if only half get love. git-svn-id: https://svn.apache.org/repos/asf/tomcat/tc6.0.x/trunk@516602 13f79535-47bb-0310-9956-ffa450edef68 --- java/org/apache/tomcat/util/net/NioEndpoint.java | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/java/org/apache/tomcat/util/net/NioEndpoint.java b/java/org/apache/tomcat/util/net/NioEndpoint.java index 4747be913..c360302df 100644 --- a/java/org/apache/tomcat/util/net/NioEndpoint.java +++ b/java/org/apache/tomcat/util/net/NioEndpoint.java @@ -1095,6 +1095,8 @@ public class NioEndpoint { } else { final SelectionKey key = socket.getIOChannel().keyFor(socket.getPoller().getSelector()); final KeyAttachment att = (KeyAttachment) key.attachment(); + //we are registering the key to start with, reset the fairness counter. + att.setFairness(0); try { if (key != null) { key.interestOps(interestOps); @@ -1304,6 +1306,8 @@ public class NioEndpoint { if (!processSocket(channel, SocketStatus.OPEN)) processSocket(channel, SocketStatus.DISCONNECT); } else { + //increase the fairness counter + attachment.incFairness(); //reregister it attachment.interestOps(interestOps); sk.interestOps(interestOps); @@ -1319,6 +1323,8 @@ public class NioEndpoint { channel.getIOChannel().socket().close(); } } else { + //increase the fairness counter + attachment.incFairness(); //reregister it attachment.interestOps(interestOps); sk.interestOps(interestOps); @@ -1393,6 +1399,7 @@ public class NioEndpoint { comet = false; timeout = -1; error = false; + fairness = 0; } public void reset() { @@ -1425,6 +1432,9 @@ public class NioEndpoint { if ( latch == null || latch.getCount() == 0 ) this.latch = new CountDownLatch(cnt); else throw new IllegalStateException("Latch must be at count 0 or null."); } + public int getFairness() { return fairness; } + public void setFairness(int f) { fairness = f;} + public void incFairness() { fairness++; } protected Object mutex = new Object(); protected long lastAccess = -1; protected boolean currentAccess = false; @@ -1433,7 +1443,7 @@ public class NioEndpoint { protected boolean error = false; protected NioChannel channel = null; protected CountDownLatch latch = null; - + protected int fairness = 0; } -- 2.11.0