1 14 package org.compiere.util; 15 16 import java.util.*; 17 18 24 public class CacheMgt 25 { 26 30 public static CacheMgt get() 31 { 32 if (s_cache == null) 33 s_cache = new CacheMgt(); 34 return s_cache; 35 } 37 38 private static CacheMgt s_cache = null; 39 40 43 private CacheMgt() 44 { 45 } 47 private ArrayList m_instances = new ArrayList(); 48 private Logger log = Logger.getCLogger(getClass()); 49 50 51 52 57 public boolean register (CacheInterface instance) 58 { 59 if (instance == null) 60 return false; 61 return m_instances.add (instance); 62 } 64 69 public boolean unregister (CacheInterface instance) 70 { 71 if (instance == null) 72 return false; 73 boolean found = false; 74 for (int i = m_instances.size()-1; i >= 0; i--) 76 { 77 CacheInterface stored = (CacheInterface)m_instances.get(i); 78 if (instance.equals(stored)) 79 { 80 m_instances.remove(i); 81 found = true; 82 } 83 } 84 return found; 85 } 87 88 89 92 public void reset() 93 { 94 int counter = 0; 95 int total = 0; 96 for (int i = 0; i < m_instances.size(); i++) 97 { 98 CacheInterface stored = (CacheInterface)m_instances.get(i); 99 if (stored != null) 100 { 101 log.debug("reset - " + stored); 102 total += stored.reset(); 103 counter++; 104 } 105 } 106 log.info("reset #" + counter + " (" + total + ")"); 107 } 109 } | Popular Tags |