import org.apache.tomcat.util.IntrospectionUtils;
import org.apache.tomcat.util.net.SecureNioChannel.ApplicationBufferHandler;
import org.apache.tomcat.util.res.StringManager;
+import org.apache.tomcat.util.net.NioEndpoint.KeyAttachment;
/**
* NIO tailored thread pool, providing the following services:
protected ConcurrentLinkedQueue<NioChannel> nioChannels = new ConcurrentLinkedQueue<NioChannel>() {
- public boolean offer(NioChannel o) {
+ public boolean offer(NioChannel socket) {
+ Poller pol = socket.getPoller();
+ Selector sel = pol!=null?pol.getSelector():null;
+ SelectionKey key = sel!=null?socket.getIOChannel().keyFor(sel):null;
+ KeyAttachment att = key!=null?(KeyAttachment)key.attachment():null;
+ if ( att!=null ) att.reset();
+ if ( key!=null ) key.cancel();
//avoid over growing our cache or add after we have stopped
- if ( running && (!paused) && (size() < curThreads) ) return super.offer(o);
+ if ( running && (!paused) && (size() < socketProperties.getDirectBufferPool()) ) return super.offer(socket);
else return false;
}
+
+ public NioChannel poll() {
+ return super.poll();
+ }
};
public KeyAttachment(Poller poller) {
this.poller = poller;
}
+ public void reset() {
+ //mutex = new Object();
+ wakeUp = false;
+ lastAccess = System.currentTimeMillis();
+ currentAccess = false;
+ comet = false;
+ timeout = -1;
+ error = false;
+ channel = null;
+ }
public Poller getPoller() { return poller;}
public void setPoller(Poller poller){this.poller = poller;}
public long getLastAccess() { return lastAccess; }
if ((status != null) && (handler.event(socket, status) == Handler.SocketState.CLOSED)) {
// Close socket and pool
try {
-
try {socket.close();}catch (Exception ignore){}
if ( socket.isOpen() ) socket.close(true);
nioChannels.offer(socket);
} else if ((status == null) && (handler.process(socket) == Handler.SocketState.CLOSED)) {
// Close socket and pool
try {
-
try {socket.close();}catch (Exception ignore){}
if ( socket.isOpen() ) socket.close(true);
nioChannels.offer(socket);
protected boolean directBuffer = true;
protected int rxBufSize = 25188;
protected int txBufSize = 43800;
+ protected int directBufferPool = 500;
+
protected boolean tcpNoDelay = false;
protected boolean soKeepAlive = false;
protected boolean ooBInline = true;
protected int performanceConnectionTime = 1;
protected int performanceLatency = 0;
protected int performanceBandwidth = 1;
- private Socket properties;
+
public void setProperties(Socket socket) throws SocketException{
socket.setReceiveBufferSize(rxBufSize);
return performanceLatency;
}
- public Socket getProperties() {
- return properties;
- }
-
public int getRxBufSize() {
return rxBufSize;
}
return txBufSize;
}
+ public int getDirectBufferPool() {
+ return directBufferPool;
+ }
+
public void setPerformanceConnectionTime(int performanceConnectionTime) {
this.performanceConnectionTime = performanceConnectionTime;
}
this.soLingerOn = soLingerOn;
}
+ public void setDirectBufferPool(int directBufferPool) {
+ this.directBufferPool = directBufferPool;
+ }
+
}
\ No newline at end of file