CVS: Tapestry/framework/src/net/sf/tapestry/util/pool Pool.java,1.7,1.7.2.1

Howard Lewis Ship <[email protected]>
Newsgroups gmane.comp.java.tapestry.cvs
Message-ID <[email protected]>
Update of /cvsroot/tapestry/Tapestry/framework/src/net/sf/tapestry/util/pool
In directory sc8-pr-cvs1:/tmp/cvs-serv32677/framework/src/net/sf/tapestry/util/pool

Modified Files:
      Tag: hship-2-3
	Pool.java 
Log Message:
Finish up code and tests for dynamically locating page specifications and templates.

Index: Pool.java
===================================================================
RCS file: /cvsroot/tapestry/Tapestry/framework/src/net/sf/tapestry/util/pool/Pool.java,v
retrieving revision 1.7
retrieving revision 1.7.2.1
diff -C2 -d -r1.7 -r1.7.2.1
*** Pool.java	27 Nov 2002 17:58:47 -0000	1.7
--- Pool.java	12 Dec 2002 12:42:39 -0000	1.7.2.1
***************
*** 5,8 ****
--- 5,9 ----
  import java.util.Map;
  
+ import org.apache.commons.lang.builder.ToStringBuilder;
  import org.apache.commons.logging.Log;
  import org.apache.commons.logging.LogFactory;
***************
*** 43,47 ****
       **/
  
!     private int generation;
  
      /**
--- 44,48 ----
       **/
  
!     private int _generation;
  
      /**
***************
*** 52,56 ****
       **/
  
!     private int window = 10;
  
      /**
--- 53,57 ----
       **/
  
!     private int _window = 10;
  
      /**
***************
*** 59,63 ****
       **/
  
!     private int pooledCount;
  
      /**
--- 60,64 ----
       **/
  
!     private int _pooledCount;
  
      /**
***************
*** 66,70 ****
       **/
  
!     private Map map;
  
      /**
--- 67,71 ----
       **/
  
!     private Map _map;
  
      /**
***************
*** 117,121 ****
          this(useSharedJanitor);
  
!         map = new HashMap(mapSize);
      }
  
--- 118,122 ----
          this(useSharedJanitor);
  
!         _map = new HashMap(mapSize);
      }
  
***************
*** 131,135 ****
      public int getWindow()
      {
!         return window;
      }
  
--- 132,136 ----
      public int getWindow()
      {
!         return _window;
      }
  
***************
*** 148,152 ****
              throw new IllegalArgumentException("Pool window may not be less than 1.");
  
!         window = value;
      }
  
--- 149,153 ----
              throw new IllegalArgumentException("Pool window may not be less than 1.");
  
!         _window = value;
      }
  
***************
*** 163,170 ****
          Object result = null;
  
!         if (map == null)
!             map = new HashMap();
  
!         list = (PoolList) map.get(key);
  
          if (list != null)
--- 164,171 ----
          Object result = null;
  
!         if (_map == null)
!             _map = new HashMap();
  
!         list = (PoolList) _map.get(key);
  
          if (list != null)
***************
*** 172,176 ****
  
          if (result != null)
!             pooledCount--;
  
          if (LOG.isDebugEnabled())
--- 173,177 ----
  
          if (result != null)
!             _pooledCount--;
  
          if (LOG.isDebugEnabled())
***************
*** 197,214 ****
          }
  
!         if (map == null)
!             map = new HashMap();
  
!         list = (PoolList) map.get(key);
  
          if (list == null)
          {
              list = new PoolList();
!             map.put(key, list);
          }
  
!         count = list.store(generation, object);
  
!         pooledCount++;
  
          if (LOG.isDebugEnabled())
--- 198,215 ----
          }
  
!         if (_map == null)
!             _map = new HashMap();
  
!         list = (PoolList) _map.get(key);
  
          if (list == null)
          {
              list = new PoolList();
!             _map.put(key, list);
          }
  
!         count = list.store(_generation, object);
  
!         _pooledCount++;
  
          if (LOG.isDebugEnabled())
***************
*** 223,230 ****
      public synchronized void clear()
      {
!         if (map != null)
!             map.clear();
  
!         pooledCount = 0;
  
          if (LOG.isDebugEnabled())
--- 224,231 ----
      public synchronized void clear()
      {
!         if (_map != null)
!             _map.clear();
  
!         _pooledCount = 0;
  
          if (LOG.isDebugEnabled())
***************
*** 243,247 ****
      public int getPooledCount()
      {
!         return pooledCount;
      }
  
--- 244,248 ----
      public int getPooledCount()
      {
!         return _pooledCount;
      }
  
***************
*** 254,261 ****
      public synchronized int getKeyCount()
      {
!         if (map == null)
              return 0;
  
!         return map.size();
      }
  
--- 255,262 ----
      public synchronized int getKeyCount()
      {
!         if (_map == null)
              return 0;
  
!         return _map.size();
      }
  
***************
*** 269,273 ****
      public synchronized void executeCleanup()
      {
!         if (map == null)
              return;
  
--- 270,274 ----
      public synchronized void executeCleanup()
      {
!         if (_map == null)
              return;
  
***************
*** 275,286 ****
              LOG.debug("Executing cleanup of " + this);
  
!         generation++;
  
!         int oldestGeneration = generation - window;
  
          if (oldestGeneration < 0)
              return;
  
!         int oldCount = pooledCount;
          int culledKeys = 0;
  
--- 276,287 ----
              LOG.debug("Executing cleanup of " + this);
  
!         _generation++;
  
!         int oldestGeneration = _generation - _window;
  
          if (oldestGeneration < 0)
              return;
  
!         int oldCount = _pooledCount;
          int culledKeys = 0;
  
***************
*** 292,296 ****
          int newCount = 0;
  
!         Iterator i = map.entrySet().iterator();
          while (i.hasNext())
          {
--- 293,297 ----
          int newCount = 0;
  
!         Iterator i = _map.entrySet().iterator();
          while (i.hasNext())
          {
***************
*** 310,382 ****
          }
  
!         pooledCount = newCount;
  
          if (LOG.isDebugEnabled())
!             LOG.debug(
!                 "Culled "
!                     + (oldCount - pooledCount)
!                     + " pooled objects and "
!                     + culledKeys
!                     + " keys.");
      }
  
      public String toString()
      {
!         if (map == null)
!             return super.toString();
! 
!         StringBuffer buffer = new StringBuffer();
! 
!         buffer.append("Pool@");
!         buffer.append(Integer.toHexString(hashCode()));
! 
!         buffer.append("[Generation ");
!         buffer.append(generation);
! 
!         if (pooledCount > 0)
!         {
!             buffer.append(", ");
!             buffer.append(pooledCount);
!             buffer.append(" pooled");
!         }
! 
!         synchronized (this)
!         {
!             Iterator i = map.entrySet().iterator();
!             while (i.hasNext())
!             {
!                 Map.Entry entry = (Map.Entry) i.next();
!                 PoolList list = (PoolList) entry.getValue();
! 
!                 buffer.append(", ");
!                 buffer.append(entry.getKey());
!                 buffer.append('=');
!                 buffer.append(list.getPooledCount());
!             }
!         }
  
!         buffer.append(']');
  
!         return buffer.toString();
      }
  
      /** @since 1.0.6 **/
  
!     public void renderDescription(IMarkupWriter writer)
      {
!         writer.print("Pool[Generation = ");
!         writer.print(generation);
!         writer.print(" Pooled = ");
!         writer.print(pooledCount);
!         writer.print("]");
! 
!         if (map == null)
!             return;
  
!         boolean first = true;
  
!         synchronized (this)
          {
!             Iterator i = map.entrySet().iterator();
  
              while (i.hasNext())
--- 311,349 ----
          }
  
!         _pooledCount = newCount;
  
          if (LOG.isDebugEnabled())
!             LOG.debug("Culled " + (oldCount - _pooledCount) + " pooled objects and " + culledKeys + " keys.");
      }
  
      public String toString()
      {
!         ToStringBuilder builder = new ToStringBuilder(this);
  
!         builder.append("generation", _generation);
!         builder.append("pooledCount", _pooledCount);
  
!         return builder.toString();
      }
  
      /** @since 1.0.6 **/
  
!     public synchronized void renderDescription(IMarkupWriter writer)
      {
!         writer.begin("table");
!         writer.attribute("border", "1");
!         writer.println();
  
!         writer.begin("tr");
!         writer.begin("th");
!         writer.attribute("colspan", "2");
!         writer.print(toString());
!         writer.end();
!         writer.end();
!         writer.println();
  
!         if (_map != null)
          {
!             Iterator i = _map.entrySet().iterator();
  
              while (i.hasNext())
***************
*** 385,405 ****
                  PoolList list = (PoolList) entry.getValue();
  
!                 if (first)
!                 {
!                     writer.begin("ul");
!                     first = false;
!                 }
! 
!                 writer.begin("li");
                  writer.print(entry.getKey().toString());
!                 writer.print(" = ");
                  writer.print(list.getPooledCount());
-                 writer.println();
                  writer.end();
              }
          }
- 
-         if (!first)
-             writer.end(); // <ul>		
      }
  }
--- 352,367 ----
                  PoolList list = (PoolList) entry.getValue();
  
!                 writer.begin("tr");
!                 writer.begin("td");
                  writer.print(entry.getKey().toString());
!                 writer.end();
!                 writer.begin("td");
                  writer.print(list.getPooledCount());
                  writer.end();
+                 writer.end();
+ 
+                 writer.println();
              }
          }
      }
  }



-------------------------------------------------------
This sf.net email is sponsored by:
With Great Power, Comes Great Responsibility 
Learn to use your power at OSDN's High Performance Computing Channel
http://hpc.devchannel.org/
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.