abdera-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jmsn...@apache.org
Subject svn commit: r510091 - /incubator/abdera/java/trunk/protocol/src/main/java/org/apache/abdera/protocol/util/PoolManager.java
Date Wed, 21 Feb 2007 16:36:17 GMT
Author: jmsnell
Date: Wed Feb 21 08:36:17 2007
New Revision: 510091

URL: http://svn.apache.org/viewvc?view=rev&rev=510091
Log:
Allow the max size to be set on the PoolManager

Modified:
    incubator/abdera/java/trunk/protocol/src/main/java/org/apache/abdera/protocol/util/PoolManager.java

Modified: incubator/abdera/java/trunk/protocol/src/main/java/org/apache/abdera/protocol/util/PoolManager.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/protocol/src/main/java/org/apache/abdera/protocol/util/PoolManager.java?view=diff&rev=510091&r1=510090&r2=510091
==============================================================================
--- incubator/abdera/java/trunk/protocol/src/main/java/org/apache/abdera/protocol/util/PoolManager.java
(original)
+++ incubator/abdera/java/trunk/protocol/src/main/java/org/apache/abdera/protocol/util/PoolManager.java
Wed Feb 21 08:36:17 2007
@@ -22,22 +22,33 @@
 /**
  * Implements a simple pool manager.
  * 
- * An upper limit to the pool is set at 25 entries.  
+ * By default, an upper limit to the pool is set at 25 entries.  
  * New items can always be created. 
  */
 public abstract class PoolManager<T> {
 
-  private static final int SIZE = 25;
+  private static final int DEFAULT_SIZE = 25;
+  private final Stack<T> pool;
   
-  private final Stack<T> pool = new Stack<T>() {
-    private static final long serialVersionUID = -6647024253014661104L;
-    @Override
-    public T push(T item) {
-      T obj = super.push(item);
-      if (this.size() > SIZE) this.removeElementAt(0);
-      return obj;
-    }
-  };
+  protected PoolManager() {
+    this(DEFAULT_SIZE);
+  }
+  
+  protected PoolManager(int max) {
+    this.pool = initStack(max);
+  }
+  
+  private Stack<T> initStack(final int max) {
+    return new Stack<T>() {
+      private static final long serialVersionUID = -6647024253014661104L;
+      @Override
+      public T push(T item) {
+        T obj = super.push(item);
+        if (this.size() > max) this.removeElementAt(0);
+        return obj;
+      }
+    };
+  }
   
   protected synchronized T getInstance() {
     return (!pool.empty()) ? pool.pop() : internalNewInstance();



Mime
View raw message