1 package org.shiftone.cache.decorator.stat; 2 3 4 5 import org.shiftone.cache.util.Log; 6 7 import java.util.ArrayList ; 8 import java.util.List ; 9 10 11 15 public class ShutdownHook extends Thread 16 { 17 18 private static final Log LOG = new Log(ShutdownHook.class); 19 private static final Runtime RUNTIME = Runtime.getRuntime(); 20 private final List cacheList = new ArrayList (); 21 private int maxCaches; 22 private String title = "[unnamed]"; 23 24 public ShutdownHook() 25 { 26 RUNTIME.addShutdownHook(this); 27 } 28 29 30 public void run() 31 { 32 33 LOG.info("shutdown : " + title); 34 35 for (int i = 0; i < getCacheCount(); i++) 36 { 37 getStatCache(i).printStats(); 38 } 39 } 40 41 42 public void setTitle(String title) 43 { 44 this.title = title; 45 } 46 47 48 public void setMaxCaches(int maxCaches) 49 { 50 this.maxCaches = maxCaches; 51 } 52 53 54 public void addStatCache(StatCache statCache) 55 { 56 57 if (getCacheCount() <= maxCaches) 58 { 59 cacheList.add(statCache); 60 } 61 } 62 63 64 public int getCacheCount() 65 { 66 return cacheList.size(); 67 } 68 69 70 public StatCache getStatCache(int index) 71 { 72 return (StatCache) cacheList.get(index); 73 } 74 } 75 | Popular Tags |