Clover coverage report - Code Coverage for tapestry release 4.0.1
Coverage timestamp: Fri Mar 31 2006 09:12:14 EST
file stats: LOC: 109   Methods: 5
NCLOC: 58   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
ObjectPoolImpl.java 100% 91.3% 80% 91.2%
coverage coverage
 1    // Copyright 2004, 2005 The Apache Software Foundation
 2    //
 3    // Licensed under the Apache License, Version 2.0 (the "License");
 4    // you may not use this file except in compliance with the License.
 5    // You may obtain a copy of the License at
 6    //
 7    // http://www.apache.org/licenses/LICENSE-2.0
 8    //
 9    // Unless required by applicable law or agreed to in writing, software
 10    // distributed under the License is distributed on an "AS IS" BASIS,
 11    // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 12    // See the License for the specific language governing permissions and
 13    // limitations under the License.
 14   
 15    package org.apache.tapestry.services.impl;
 16   
 17    import java.util.HashMap;
 18    import java.util.Iterator;
 19    import java.util.LinkedList;
 20    import java.util.List;
 21    import java.util.Map;
 22   
 23    import org.apache.tapestry.event.ReportStatusEvent;
 24    import org.apache.tapestry.event.ReportStatusListener;
 25    import org.apache.tapestry.event.ResetEventListener;
 26    import org.apache.tapestry.services.ObjectPool;
 27   
 28    /**
 29    * Implementation of the {@link org.apache.tapestry.services.ObjectPool} interface.
 30    * <p>
 31    * This ia a minimal implementation, one that has no concept of automatically removing unused pooled
 32    * objects. Eventually, it will also register for notifications about general cache cleaning.
 33    *
 34    * @author Howard Lewis Ship
 35    * @since 4.0
 36    */
 37    public class ObjectPoolImpl implements ObjectPool, ResetEventListener, ReportStatusListener
 38    {
 39    private String _serviceId;
 40   
 41    private int _count = 0;
 42   
 43    /**
 44    * Pool of Lists (of pooled objects), keyed on arbitrary key.
 45    */
 46    private Map _pool = new HashMap();
 47   
 48  628 public synchronized Object get(Object key)
 49    {
 50  628 List pooled = (List) _pool.get(key);
 51   
 52  628 if (pooled == null || pooled.isEmpty())
 53  346 return null;
 54   
 55  282 _count--;
 56   
 57  282 return pooled.remove(0);
 58    }
 59   
 60  602 public synchronized void store(Object key, Object value)
 61    {
 62  602 List pooled = (List) _pool.get(key);
 63   
 64  602 if (pooled == null)
 65    {
 66  314 pooled = new LinkedList();
 67  314 _pool.put(key, pooled);
 68    }
 69   
 70  602 pooled.add(value);
 71   
 72  602 _count++;
 73    }
 74   
 75  0 public synchronized void resetEventDidOccur()
 76    {
 77  0 _pool.clear();
 78   
 79  0 _count = 0;
 80    }
 81   
 82  68 public synchronized void reportStatus(ReportStatusEvent event)
 83    {
 84  68 event.title(_serviceId);
 85   
 86  68 event.property("total count", _count);
 87   
 88  68 event.section("Count by Key");
 89   
 90  68 Iterator i = _pool.entrySet().iterator();
 91   
 92  68 while (i.hasNext())
 93    {
 94  88 Map.Entry entry = (Map.Entry) i.next();
 95   
 96  88 String key = entry.getKey().toString();
 97   
 98  88 List pooled = (List) entry.getValue();
 99   
 100  88 event.property(key, pooled.size());
 101    }
 102    }
 103   
 104  156 public void setServiceId(String serviceId)
 105    {
 106  156 _serviceId = serviceId;
 107    }
 108   
 109    }