Author: markt Date: Thu Aug 29 22:23:04 2013 New Revision: 1518846 URL: http://svn.apache.org/r1518846 Log: Refactor SocketWrapper - make fields private - add reset() method to wrapper - distribute resetting of values between SocketWrapper and KeyAttachment so each resets its own fields
Modified: tomcat/trunk/java/org/apache/tomcat/util/net/AprEndpoint.java tomcat/trunk/java/org/apache/tomcat/util/net/NioEndpoint.java tomcat/trunk/java/org/apache/tomcat/util/net/SocketWrapper.java Modified: tomcat/trunk/java/org/apache/tomcat/util/net/AprEndpoint.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/net/AprEndpoint.java?rev=1518846&r1=1518845&r2=1518846&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/tomcat/util/net/AprEndpoint.java (original) +++ tomcat/trunk/java/org/apache/tomcat/util/net/AprEndpoint.java Thu Aug 29 22:23:04 2013 @@ -1050,7 +1050,7 @@ public class AprEndpoint extends Abstrac waitingRequests.iterator(); while (sockets.hasNext()) { SocketWrapper<Long> socket = sockets.next(); - if (socket.async) { + if (socket.isAsync()) { long access = socket.getLastAccess(); if (socket.getTimeout() > 0 && (now-access)>socket.getTimeout()) { @@ -2218,7 +2218,7 @@ public class AprEndpoint extends Abstrac socket = null; } else if (state == Handler.SocketState.LONG) { socket.access(); - if (socket.async) { + if (socket.isAsync()) { waitingRequests.add(socket); } } @@ -2277,10 +2277,10 @@ public class AprEndpoint extends Abstrac if (state == Handler.SocketState.CLOSED) { // Close socket and pool destroySocket(socket.getSocket().longValue()); - socket.socket = null; + socket.reset(null, 1); } else if (state == Handler.SocketState.LONG) { socket.access(); - if (socket.async) { + if (socket.isAsync()) { waitingRequests.add(socket); } } else if (state == Handler.SocketState.ASYNC_END) { Modified: tomcat/trunk/java/org/apache/tomcat/util/net/NioEndpoint.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/net/NioEndpoint.java?rev=1518846&r1=1518845&r2=1518846&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/tomcat/util/net/NioEndpoint.java (original) +++ tomcat/trunk/java/org/apache/tomcat/util/net/NioEndpoint.java Thu Aug 29 22:23:04 2013 @@ -1376,13 +1376,11 @@ public class NioEndpoint extends Abstrac } public void reset(Poller poller, NioChannel channel, long soTimeout) { - this.socket = channel; + super.reset(channel, soTimeout); + + cometNotify = false; + interestOps = 0; this.poller = poller; - lastAccess = System.currentTimeMillis(); - setComet(false); - setTimeout(soTimeout); - setWriteTimeout(soTimeout); - error = false; sendfileData = null; if (readLatch != null) { try { @@ -1393,6 +1391,7 @@ public class NioEndpoint extends Abstrac } } readLatch = null; + sendfileData = null; if (writeLatch != null) { try { for (int i = 0; i < (int) writeLatch.getCount(); i++) { @@ -1402,10 +1401,7 @@ public class NioEndpoint extends Abstrac } } writeLatch = null; - cometNotify = false; - sendfileData = null; - keepAliveLeft = 100; - async = false; + setWriteTimeout(soTimeout); } public void reset() { @@ -1417,7 +1413,6 @@ public class NioEndpoint extends Abstrac public void setCometNotify(boolean notify) { this.cometNotify = notify; } public boolean getCometNotify() { return cometNotify; } public NioChannel getChannel() { return getSocket();} - public void setChannel(NioChannel channel) { this.socket = channel;} public int interestOps() { return interestOps;} public int interestOps(int ops) { this.interestOps = ops; return ops; } public CountDownLatch getReadLatch() { return readLatch; } Modified: tomcat/trunk/java/org/apache/tomcat/util/net/SocketWrapper.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/net/SocketWrapper.java?rev=1518846&r1=1518845&r2=1518846&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/tomcat/util/net/SocketWrapper.java (original) +++ tomcat/trunk/java/org/apache/tomcat/util/net/SocketWrapper.java Thu Aug 29 22:23:04 2013 @@ -25,25 +25,25 @@ import java.util.concurrent.locks.Reentr public class SocketWrapper<E> { - protected volatile E socket; + private volatile E socket; - protected volatile long lastAccess = -1; + private volatile long lastAccess = -1; private long timeout = -1; - protected boolean error = false; - protected volatile int keepAliveLeft = 100; + private boolean error = false; + private volatile int keepAliveLeft = 100; private boolean comet = false; - protected boolean async = false; - protected boolean keptAlive = false; + private boolean async = false; + private boolean keptAlive = false; private boolean upgraded = false; /* * Following cached for speed / reduced GC */ - private int localPort = -1; - private String localName = null; private String localAddr = null; - private int remotePort = -1; - private String remoteHost = null; + private String localName = null; + private int localPort = -1; private String remoteAddr = null; + private String remoteHost = null; + private int remotePort = -1; /* * Used if block/non-blocking is set at the socket level. The client is * responsible for the thread-safe use of this field via the locks provided. @@ -68,7 +68,7 @@ public class SocketWrapper<E> { this.socket = socket; ReentrantReadWriteLock lock = new ReentrantReadWriteLock(); this.blockingStatusReadLock = lock.readLock(); - this.blockingStatusWriteLock =lock.writeLock(); + this.blockingStatusWriteLock = lock.writeLock(); } public E getSocket() { @@ -128,4 +128,23 @@ public class SocketWrapper<E> { } return result; } + + public void reset(E socket, long timeout) { + async = false; + blockingStatus = true; + comet = false; + dispatches.clear(); + error = false; + keepAliveLeft = 100; + lastAccess = System.currentTimeMillis(); + localAddr = null; + localName = null; + localPort = -1; + remoteAddr = null; + remoteHost = null; + remotePort = -1; + this.socket = socket; + this.timeout = timeout; + upgraded = false; + } } --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org