1 15 package org.apache.tapestry.services.impl; 16 17 import java.util.HashMap ; 18 import java.util.LinkedList ; 19 import java.util.List ; 20 import java.util.Map ; 21 22 import org.apache.tapestry.event.ResetEventListener; 23 import org.apache.tapestry.services.ObjectPool; 24 25 36 public class ObjectPoolImpl implements ObjectPool, ResetEventListener 37 { 38 41 private Map _pool = new HashMap (); 42 43 public synchronized Object get(Object key) 44 { 45 List pooled = (List ) _pool.get(key); 46 47 if (pooled == null || pooled.isEmpty()) 48 return null; 49 50 return pooled.remove(0); 51 } 52 53 public synchronized void store(Object key, Object value) 54 { 55 List pooled = (List ) _pool.get(key); 56 57 if (pooled == null) 58 { 59 pooled = new LinkedList (); 60 _pool.put(key, pooled); 61 } 62 63 pooled.add(value); 64 } 65 66 public synchronized void resetEventDidOccur() 67 { 68 _pool.clear(); 69 } 70 71 } 72 | Popular Tags |