1 2 3 package org.enhydra.shark.caching; 4 5 import org.enhydra.shark.api.internal.caching.*; 6 import org.enhydra.shark.api.internal.working.WfProcessInternal; 7 import org.enhydra.shark.api.RootException; 8 import org.enhydra.shark.utilities.LRUMap; 9 10 import org.enhydra.shark.api.internal.working.CallbackUtilities; 11 12 import java.util.*; 13 14 19 public class LRUProcessCache implements ProcessCache { 20 private final int defaultCacheSize=100; 21 22 25 protected LRUMap cache; 26 27 34 public void configure (CallbackUtilities cus) throws RootException { 35 cus.getProperties(); 36 String procCacheSize=cus.getProperty("LRUProcessCache.Size"); 37 try { 38 int cacheSize=Integer.parseInt(procCacheSize.trim()); 39 cache = new LRUMap(cacheSize); 40 } catch (Exception ex){ 41 cache = new LRUMap(defaultCacheSize); 42 } 43 cus.info("Process Cache configured - max. size is "+cache.getMaximumSize()); 44 } 45 46 54 public void add (String procId, WfProcessInternal proc) throws RootException { 55 synchronized(this) { 56 cache.put(procId, proc); 58 } 59 } 60 61 68 public void remove (String procId) throws RootException { 69 synchronized(this) { 70 cache.remove(procId); 71 } 72 } 73 74 82 public WfProcessInternal get (String procId) throws RootException { 83 WfProcessInternal proc = null; 84 synchronized(this) { 85 proc=(WfProcessInternal)cache.get(procId); 86 } 87 return proc; 88 } 89 90 98 public void setSize (int size) throws RootException { 99 if (size<0) throw new RootException("Can't set negative process cache size"); 100 synchronized(this) { 101 cache.setMaximumSize(size); 102 } 103 } 104 105 111 public int getSize () throws RootException { 112 return cache.getMaximumSize(); 113 } 114 115 public int howManyEntries() throws RootException { 116 return cache.size(); 117 } 118 119 125 public java.util.List getAll() throws RootException { 126 if (cache.size()>0) { 127 synchronized(this) { 128 return new ArrayList(cache.values()); 129 } 130 } else { 131 return new ArrayList(); 132 } 133 } 134 135 } 136 137 | Popular Tags |