KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > shiftone > cache > decorator > stat > ShutdownHook


1 package org.shiftone.cache.decorator.stat;
2
3
4
5 import org.shiftone.cache.util.Log;
6
7 import java.util.ArrayList JavaDoc;
8 import java.util.List JavaDoc;
9
10
11 /**
12  * @version $Revision: 1.4 $
13  * @author $Author: jeffdrost $
14  */

15 public class ShutdownHook extends Thread JavaDoc
16 {
17
18     private static final Log LOG = new Log(ShutdownHook.class);
19     private static final Runtime JavaDoc RUNTIME = Runtime.getRuntime();
20     private final List JavaDoc cacheList = new ArrayList JavaDoc();
21     private int maxCaches;
22     private String JavaDoc 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 JavaDoc 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