1 18 package org.objectweb.perseus.cache; 19 20 import org.objectweb.perseus.cache.api.CacheManager; 21 import org.objectweb.perseus.cache.api.CacheEntry; 22 import org.objectweb.perseus.cache.api.CacheAttributeController; 23 import org.objectweb.util.monolog.Monolog; 24 import org.objectweb.util.monolog.api.LoggerFactory; 25 import org.objectweb.util.monolog.api.Logger; 26 import org.objectweb.util.monolog.api.BasicLevel; 27 28 import java.util.HashMap ; 29 30 34 public class Application { 35 public static void main(String [] args) throws Exception { 36 Logger logger = Monolog.initialize().getLogger(Application.class.getName()); 37 38 39 logger.log(BasicLevel.INFO, "CacheManager instance fetched."); 40 CacheManager cm = CacheManagerFactory.getCacheManager(); 41 42 logger.log(BasicLevel.INFO, "Change the maximal cache size to 50 000"); 43 CacheAttributeController cac = CacheManagerFactory.getCacheAttributeController(cm); 44 cac.setMaxObjects(50000); 45 46 HashMap o1 = new HashMap (); 48 o1.put("k1", new long[]{345234}); 49 logger.log(BasicLevel.INFO, "bind (\"id1\", " + o1 + ") to the cache"); 50 cm.bind("id1", o1); 51 52 logger.log(BasicLevel.INFO, "bind (\"id2\", \"value1\") to the cache"); 53 cm.bind("id2", "value1"); 54 55 logger.log(BasicLevel.INFO, "Currently there are " + cac.getCurrentSize() + " entries"); 56 57 CacheEntry ce = cm.lookup("id1"); 59 if (ce == null) { 60 throw new Exception ("Error in the cache: no entry matching id1"); 61 } 62 logger.log(BasicLevel.INFO, "lookup(\"id1\"): " + cm.lookup("id1").getCeObject()); 63 if (ce.getCeObject() != o1) { 64 throw new Exception ( 65 "Error in the cache: bad entry for the identifier id1: " 66 + ce.getCeObject()); 67 } 68 69 ce = cm.lookup("id2"); 70 if (ce == null) { 71 throw new Exception ("Error in the cache: no entry matching id2"); 72 } 73 logger.log(BasicLevel.INFO, "lookup(\"id2\"): " + cm.lookup("id2").getCeObject()); 74 if (!"value1".equals(ce.getCeObject())) { 75 throw new Exception ( 76 "Error in the cache: bad entry for the identifier id2: " 77 + ce.getCeObject()); 78 } 79 } 80 } 81 | Popular Tags |