From: fhanik Date: Mon, 12 Mar 2007 20:37:22 +0000 (+0000) Subject: Added in the skeleton for fairness logic, currently the tests for fairness are coming... X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=be2118b2d9f3e70b987fcfdf8afbca35b95d1c18;p=tomcat7.0 Added in the skeleton for fairness logic, currently the tests for fairness are coming out extremely fair, could it be that the Selector.selectedKeys() sorts the keys properly? Anyway, to implement a scheduler, I can use the "fairness" numbers added in here. Won't do it until I deem it necessary. git-svn-id: https://svn.apache.org/repos/asf/tomcat/tc6.0.x/trunk@517384 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/java/org/apache/tomcat/util/net/NioEndpoint.java b/java/org/apache/tomcat/util/net/NioEndpoint.java index c360302df..3d4ebd26a 100644 --- a/java/org/apache/tomcat/util/net/NioEndpoint.java +++ b/java/org/apache/tomcat/util/net/NioEndpoint.java @@ -47,6 +47,7 @@ import org.apache.tomcat.util.net.SecureNioChannel.ApplicationBufferHandler; import org.apache.tomcat.util.res.StringManager; import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.CountDownLatch; +import java.util.Comparator; /** * NIO tailored thread pool, providing the following services: @@ -1385,7 +1386,8 @@ public class NioEndpoint { }//for } } - + +// ----------------------------------------------------- Key Attachment Class public static class KeyAttachment { public KeyAttachment() { @@ -1400,6 +1402,7 @@ public class NioEndpoint { timeout = -1; error = false; fairness = 0; + lastRegistered = 0; } public void reset() { @@ -1435,6 +1438,9 @@ public class NioEndpoint { public int getFairness() { return fairness; } public void setFairness(int f) { fairness = f;} public void incFairness() { fairness++; } + public long getLastRegistered() { return lastRegistered; }; + public void setLastRegistered(long reg) { lastRegistered = reg; } + protected Object mutex = new Object(); protected long lastAccess = -1; protected boolean currentAccess = false; @@ -1444,6 +1450,28 @@ public class NioEndpoint { protected NioChannel channel = null; protected CountDownLatch latch = null; protected int fairness = 0; + protected long lastRegistered = 0; + } +// ----------------------------------------------------- Key Fairness Comparator + public static class KeyFairnessComparator implements Comparator { + public int compare(KeyAttachment ka1, KeyAttachment ka2) { + long lr1 = ka1.getLastRegistered(); + long lr2 = ka2.getLastRegistered(); + int f1 = ka1.getFairness(); + int f2 = ka2.getFairness(); + if ( f1 == f2 ) { + if ( lr1 == lr2 ) return 0; + //earlier objects have priorioty + else return lr1ka2.getFairness()?-1:1; + } + } + }