tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject svn commit: r1132451 - in /tomcat/trunk/java/org/apache/coyote: AbstractProtocol.java ajp/AjpAprProtocol.java ajp/AjpNioProtocol.java ajp/AjpProtocol.java http11/Http11AprProtocol.java http11/Http11NioProtocol.java http11/Http11Protocol.java
Date Sun, 05 Jun 2011 16:32:32 GMT
Author: markt
Date: Sun Jun  5 16:32:31 2011
New Revision: 1132451

URL: http://svn.apache.org/viewvc?rev=1132451&view=rev
Log:
Create a new RecycledProcessors inner class and use it in the Processor implementations rather
than redefining the same thing 6 times.

Modified:
    tomcat/trunk/java/org/apache/coyote/AbstractProtocol.java
    tomcat/trunk/java/org/apache/coyote/ajp/AjpAprProtocol.java
    tomcat/trunk/java/org/apache/coyote/ajp/AjpNioProtocol.java
    tomcat/trunk/java/org/apache/coyote/ajp/AjpProtocol.java
    tomcat/trunk/java/org/apache/coyote/http11/Http11AprProtocol.java
    tomcat/trunk/java/org/apache/coyote/http11/Http11NioProtocol.java
    tomcat/trunk/java/org/apache/coyote/http11/Http11Protocol.java

Modified: tomcat/trunk/java/org/apache/coyote/AbstractProtocol.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/coyote/AbstractProtocol.java?rev=1132451&r1=1132450&r2=1132451&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/coyote/AbstractProtocol.java (original)
+++ tomcat/trunk/java/org/apache/coyote/AbstractProtocol.java Sun Jun  5 16:32:31 2011
@@ -17,7 +17,9 @@
 package org.apache.coyote;
 
 import java.net.InetAddress;
+import java.util.concurrent.ConcurrentLinkedQueue;
 import java.util.concurrent.Executor;
+import java.util.concurrent.atomic.AtomicInteger;
 import java.util.concurrent.atomic.AtomicLong;
 
 import javax.management.MBeanRegistration;
@@ -517,4 +519,52 @@ public abstract class AbstractProtocol i
             }
         }
     }
+    
+    protected static class RecycledProcessors<P extends AbstractProcessor>
+            extends ConcurrentLinkedQueue<P> {
+
+        private static final long serialVersionUID = 1L;
+        private AbstractConnectionHandler handler;
+        protected AtomicInteger size = new AtomicInteger(0);
+
+        public RecycledProcessors(AbstractConnectionHandler handler) {
+            this.handler = handler;
+        }
+
+        @Override
+        public boolean offer(P processor) {
+            int cacheSize = handler.getProtocol().getProcessorCache();
+            boolean offer = cacheSize == -1 ? true : size.get() < cacheSize;
+            //avoid over growing our cache or add after we have stopped
+            boolean result = false;
+            if (offer) {
+                result = super.offer(processor);
+                if (result) {
+                    size.incrementAndGet();
+                }
+            }
+            if (!result) handler.unregister(processor);
+            return result;
+        }
+    
+        @Override
+        public P poll() {
+            P result = super.poll();
+            if (result != null) {
+                size.decrementAndGet();
+            }
+            return result;
+        }
+    
+        @Override
+        public void clear() {
+            P next = poll();
+            while (next != null) {
+                handler.unregister(next);
+                next = poll();
+            }
+            super.clear();
+            size.set(0);
+        }
+    }
 }

Modified: tomcat/trunk/java/org/apache/coyote/ajp/AjpAprProtocol.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/coyote/ajp/AjpAprProtocol.java?rev=1132451&r1=1132450&r2=1132451&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/coyote/ajp/AjpAprProtocol.java (original)
+++ tomcat/trunk/java/org/apache/coyote/ajp/AjpAprProtocol.java Sun Jun  5 16:32:31 2011
@@ -18,8 +18,6 @@
 package org.apache.coyote.ajp;
 
 import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.ConcurrentLinkedQueue;
-import java.util.concurrent.atomic.AtomicInteger;
 
 import org.apache.coyote.AbstractProtocol;
 import org.apache.juli.logging.Log;
@@ -109,45 +107,8 @@ public class AjpAprProtocol extends Abst
         protected ConcurrentHashMap<SocketWrapper<Long>, AjpAprProcessor> connections
=
             new ConcurrentHashMap<SocketWrapper<Long>, AjpAprProcessor>();
 
-        protected ConcurrentLinkedQueue<AjpAprProcessor> recycledProcessors = 
-                new ConcurrentLinkedQueue<AjpAprProcessor>() {
-            private static final long serialVersionUID = 1L;
-            protected AtomicInteger size = new AtomicInteger(0);
-            @Override
-            public boolean offer(AjpAprProcessor processor) {
-                boolean offer = (proto.processorCache == -1) ? true : (size.get() < proto.processorCache);
-                //avoid over growing our cache or add after we have stopped
-                boolean result = false;
-                if ( offer ) {
-                    result = super.offer(processor);
-                    if ( result ) {
-                        size.incrementAndGet();
-                    }
-                }
-                if (!result) unregister(processor);
-                return result;
-            }
-            
-            @Override
-            public AjpAprProcessor poll() {
-                AjpAprProcessor result = super.poll();
-                if ( result != null ) {
-                    size.decrementAndGet();
-                }
-                return result;
-            }
-            
-            @Override
-            public void clear() {
-                AjpAprProcessor next = poll();
-                while ( next != null ) {
-                    unregister(next);
-                    next = poll();
-                }
-                super.clear();
-                size.set(0);
-            }
-        };
+        protected RecycledProcessors<AjpAprProcessor> recycledProcessors =
+            new RecycledProcessors<AjpAprProcessor>(this);
 
         public AjpConnectionHandler(AjpAprProtocol proto) {
             this.proto = proto;

Modified: tomcat/trunk/java/org/apache/coyote/ajp/AjpNioProtocol.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/coyote/ajp/AjpNioProtocol.java?rev=1132451&r1=1132450&r2=1132451&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/coyote/ajp/AjpNioProtocol.java (original)
+++ tomcat/trunk/java/org/apache/coyote/ajp/AjpNioProtocol.java Sun Jun  5 16:32:31 2011
@@ -20,8 +20,6 @@ package org.apache.coyote.ajp;
 import java.nio.channels.SocketChannel;
 import java.util.Iterator;
 import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.ConcurrentLinkedQueue;
-import java.util.concurrent.atomic.AtomicInteger;
 
 import org.apache.coyote.AbstractProtocol;
 import org.apache.juli.logging.Log;
@@ -98,45 +96,8 @@ public class AjpNioProtocol extends Abst
         protected ConcurrentHashMap<NioChannel, AjpNioProcessor> connections =
             new ConcurrentHashMap<NioChannel, AjpNioProcessor>();
 
-        protected ConcurrentLinkedQueue<AjpNioProcessor> recycledProcessors = 
-                new ConcurrentLinkedQueue<AjpNioProcessor>() {
-            private static final long serialVersionUID = 1L;
-            protected AtomicInteger size = new AtomicInteger(0);
-            @Override
-            public boolean offer(AjpNioProcessor processor) {
-                boolean offer = (proto.processorCache == -1) ? true : (size.get() < proto.processorCache);
-                //avoid over growing our cache or add after we have stopped
-                boolean result = false;
-                if ( offer ) {
-                    result = super.offer(processor);
-                    if ( result ) {
-                        size.incrementAndGet();
-                    }
-                }
-                if (!result) unregister(processor);
-                return result;
-            }
-            
-            @Override
-            public AjpNioProcessor poll() {
-                AjpNioProcessor result = super.poll();
-                if ( result != null ) {
-                    size.decrementAndGet();
-                }
-                return result;
-            }
-            
-            @Override
-            public void clear() {
-                AjpNioProcessor next = poll();
-                while ( next != null ) {
-                    unregister(next);
-                    next = poll();
-                }
-                super.clear();
-                size.set(0);
-            }
-        };
+        protected RecycledProcessors<AjpNioProcessor> recycledProcessors =
+            new RecycledProcessors<AjpNioProcessor>(this);
 
         public AjpConnectionHandler(AjpNioProtocol proto) {
             this.proto = proto;

Modified: tomcat/trunk/java/org/apache/coyote/ajp/AjpProtocol.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/coyote/ajp/AjpProtocol.java?rev=1132451&r1=1132450&r2=1132451&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/coyote/ajp/AjpProtocol.java (original)
+++ tomcat/trunk/java/org/apache/coyote/ajp/AjpProtocol.java Sun Jun  5 16:32:31 2011
@@ -19,8 +19,6 @@ package org.apache.coyote.ajp;
 
 import java.net.Socket;
 import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.ConcurrentLinkedQueue;
-import java.util.concurrent.atomic.AtomicInteger;
 
 import org.apache.coyote.AbstractProtocol;
 import org.apache.juli.logging.Log;
@@ -98,47 +96,9 @@ public class AjpProtocol extends Abstrac
         protected ConcurrentHashMap<SocketWrapper<Socket>, AjpProcessor> connections
=
             new ConcurrentHashMap<SocketWrapper<Socket>, AjpProcessor>();
 
-        protected ConcurrentLinkedQueue<AjpProcessor> recycledProcessors = 
-                new ConcurrentLinkedQueue<AjpProcessor>() {
-            private static final long serialVersionUID = 1L;
-            protected AtomicInteger size = new AtomicInteger(0);
-            @Override
-            public boolean offer(AjpProcessor processor) {
-                boolean offer = (proto.processorCache == -1) ? true : (size.get() < proto.processorCache);
-                //avoid over growing our cache or add after we have stopped
-                boolean result = false;
-                if ( offer ) {
-                    result = super.offer(processor);
-                    if ( result ) {
-                        size.incrementAndGet();
-                    }
-                }
-                if (!result) unregister(processor);
-                return result;
-            }
-            
-            @Override
-            public AjpProcessor poll() {
-                AjpProcessor result = super.poll();
-                if ( result != null ) {
-                    size.decrementAndGet();
-                }
-                return result;
-            }
-            
-            @Override
-            public void clear() {
-                AjpProcessor next = poll();
-                while ( next != null ) {
-                    unregister(next);
-                    next = poll();
-                }
-                super.clear();
-                size.set(0);
-            }
-        };
+        protected RecycledProcessors<AjpProcessor> recycledProcessors =
+            new RecycledProcessors<AjpProcessor>(this);
 
-        
         public AjpConnectionHandler(AjpProtocol proto) {
             this.proto = proto;
         }

Modified: tomcat/trunk/java/org/apache/coyote/http11/Http11AprProtocol.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/coyote/http11/Http11AprProtocol.java?rev=1132451&r1=1132450&r2=1132451&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/coyote/http11/Http11AprProtocol.java (original)
+++ tomcat/trunk/java/org/apache/coyote/http11/Http11AprProtocol.java Sun Jun  5 16:32:31
2011
@@ -18,8 +18,6 @@
 package org.apache.coyote.http11;
 
 import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.ConcurrentLinkedQueue;
-import java.util.concurrent.atomic.AtomicInteger;
 
 import org.apache.coyote.AbstractProtocol;
 import org.apache.juli.logging.Log;
@@ -191,46 +189,8 @@ public class Http11AprProtocol extends A
         protected ConcurrentHashMap<Long, Http11AprProcessor> connections =
             new ConcurrentHashMap<Long, Http11AprProcessor>();
 
-        protected ConcurrentLinkedQueue<Http11AprProcessor> recycledProcessors = 
-            new ConcurrentLinkedQueue<Http11AprProcessor>() {
-            private static final long serialVersionUID = 1L;
-            protected AtomicInteger size = new AtomicInteger(0);
-            @Override
-            public boolean offer(Http11AprProcessor processor) {
-                boolean offer = proto.getProcessorCache() == -1 ? true : size.get() <
proto.getProcessorCache();
-                //avoid over growing our cache or add after we have stopped
-                boolean result = false;
-                if ( offer ) {
-                    result = super.offer(processor);
-                    if ( result ) {
-                        size.incrementAndGet();
-                    }
-                }
-                if (!result) unregister(processor);
-                return result;
-            }
-            
-            @Override
-            public Http11AprProcessor poll() {
-                Http11AprProcessor result = super.poll();
-                if ( result != null ) {
-                    size.decrementAndGet();
-                }
-                return result;
-            }
-            
-            @Override
-            public void clear() {
-                Http11AprProcessor next = poll();
-                while ( next != null ) {
-                    unregister(next);
-                    next = poll();
-                }
-                super.clear();
-                size.set(0);
-            }
-        };
-
+        protected RecycledProcessors<Http11AprProcessor> recycledProcessors =
+            new RecycledProcessors<Http11AprProcessor>(this);
 
         Http11ConnectionHandler(Http11AprProtocol proto) {
             this.proto = proto;

Modified: tomcat/trunk/java/org/apache/coyote/http11/Http11NioProtocol.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/coyote/http11/Http11NioProtocol.java?rev=1132451&r1=1132450&r2=1132451&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/coyote/http11/Http11NioProtocol.java (original)
+++ tomcat/trunk/java/org/apache/coyote/http11/Http11NioProtocol.java Sun Jun  5 16:32:31
2011
@@ -21,8 +21,6 @@ import java.nio.channels.SelectionKey;
 import java.nio.channels.SocketChannel;
 import java.util.Iterator;
 import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.ConcurrentLinkedQueue;
-import java.util.concurrent.atomic.AtomicInteger;
 
 import org.apache.coyote.AbstractProtocol;
 import org.apache.juli.logging.Log;
@@ -159,45 +157,8 @@ public class Http11NioProtocol extends A
         protected ConcurrentHashMap<NioChannel, Http11NioProcessor> connections =
             new ConcurrentHashMap<NioChannel, Http11NioProcessor>();
 
-        protected ConcurrentLinkedQueue<Http11NioProcessor> recycledProcessors =
-                new ConcurrentLinkedQueue<Http11NioProcessor>() {
-            private static final long serialVersionUID = 1L;
-            protected AtomicInteger size = new AtomicInteger(0);
-            @Override
-            public boolean offer(Http11NioProcessor processor) {
-                boolean offer = proto.getProcessorCache() == -1 ? true : size.get() <
proto.getProcessorCache();
-                //avoid over growing our cache or add after we have stopped
-                boolean result = false;
-                if ( offer ) {
-                    result = super.offer(processor);
-                    if ( result ) {
-                        size.incrementAndGet();
-                    }
-                }
-                if (!result) unregister(processor);
-                return result;
-            }
-            
-            @Override
-            public Http11NioProcessor poll() {
-                Http11NioProcessor result = super.poll();
-                if ( result != null ) {
-                    size.decrementAndGet();
-                }
-                return result;
-            }
-            
-            @Override
-            public void clear() {
-                Http11NioProcessor next = poll();
-                while ( next != null ) {
-                    unregister(next);
-                    next = poll();
-                }
-                super.clear();
-                size.set(0);
-            }
-        };
+        protected RecycledProcessors<Http11NioProcessor> recycledProcessors =
+            new RecycledProcessors<Http11NioProcessor>(this);
 
         Http11ConnectionHandler(Http11NioProtocol proto) {
             this.proto = proto;

Modified: tomcat/trunk/java/org/apache/coyote/http11/Http11Protocol.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/coyote/http11/Http11Protocol.java?rev=1132451&r1=1132450&r2=1132451&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/coyote/http11/Http11Protocol.java (original)
+++ tomcat/trunk/java/org/apache/coyote/http11/Http11Protocol.java Sun Jun  5 16:32:31 2011
@@ -19,8 +19,6 @@ package org.apache.coyote.http11;
 
 import java.net.Socket;
 import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.ConcurrentLinkedQueue;
-import java.util.concurrent.atomic.AtomicInteger;
 
 import org.apache.coyote.AbstractProtocol;
 import org.apache.juli.logging.Log;
@@ -110,45 +108,8 @@ public class Http11Protocol extends Abst
         protected ConcurrentHashMap<SocketWrapper<Socket>, Http11Processor> connections
=
             new ConcurrentHashMap<SocketWrapper<Socket>, Http11Processor>();
 
-        protected ConcurrentLinkedQueue<Http11Processor> recycledProcessors = 
-                new ConcurrentLinkedQueue<Http11Processor>() {
-            private static final long serialVersionUID = 1L;
-            protected AtomicInteger size = new AtomicInteger(0);
-            @Override
-            public boolean offer(Http11Processor processor) {
-                boolean offer = proto.getProcessorCache() == -1 ? true : size.get() <
proto.getProcessorCache();
-                //avoid over growing our cache or add after we have stopped
-                boolean result = false;
-                if ( offer ) {
-                    result = super.offer(processor);
-                    if ( result ) {
-                        size.incrementAndGet();
-                    }
-                }
-                if (!result) unregister(processor);
-                return result;
-            }
-            
-            @Override
-            public Http11Processor poll() {
-                Http11Processor result = super.poll();
-                if ( result != null ) {
-                    size.decrementAndGet();
-                }
-                return result;
-            }
-            
-            @Override
-            public void clear() {
-                Http11Processor next = poll();
-                while ( next != null ) {
-                    unregister(next);
-                    next = poll();
-                }
-                super.clear();
-                size.set(0);
-            }
-        };
+        protected RecycledProcessors<Http11Processor> recycledProcessors =
+            new RecycledProcessors<Http11Processor>(this);
 
         Http11ConnectionHandler(Http11Protocol proto) {
             this.proto = proto;



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


Mime
View raw message