KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > nemesis > forum > webapp > admin > bean > CacheBean


1 /*
2  * Created on 27 mars 2003
3  *
4  * To change this generated comment go to
5  * Window>Preferences>Java>Code Generation>Code and Comments
6  */

7 package org.nemesis.forum.webapp.admin.bean;
8
9 import java.text.DecimalFormat JavaDoc;
10
11 import org.nemesis.forum.util.cache.Cache;
12
13
14 public class CacheBean{
15     
16     Cache cache;
17     int id;
18     String JavaDoc name;
19     
20     DecimalFormat JavaDoc formatter = new DecimalFormat JavaDoc("#0.00");
21     DecimalFormat JavaDoc formatter2 = new DecimalFormat JavaDoc("#0");
22
23     public CacheBean( int _id, String JavaDoc _name,Cache _cache) {
24         this.cache=_cache;
25         
26         this.id=_id;
27         this.name=_name;
28         
29     }
30     
31     public String JavaDoc getMoFormattedSize(){
32         double totalMem = (double)cache.getMaxSize()/(1024*1024);
33         return formatter.format(totalMem)+" MB";
34     }
35     public String JavaDoc getKoSize(){
36             double totalMem = (double)cache.getMaxSize()/1024;
37             return formatter2.format(totalMem);
38         }
39     public String JavaDoc getPercentFree(){
40         double memUsed = (double)cache.getSize()/(1024*1024);
41         double totalMem = (double)cache.getMaxSize()/(1024*1024);
42         double freeMem = 100 - 100*memUsed/totalMem;
43         
44         return formatter.format(freeMem)+" %";
45     }
46     
47     public String JavaDoc getEffectiveness(){
48         double hitPercent;
49         if (cache.getCacheHits() + cache.getCacheMisses() == 0) { hitPercent = 0.0; }
50         else { hitPercent = 100*(double)cache.getCacheHits()/(cache.getCacheHits()+cache.getCacheMisses()); }
51         return formatter.format(hitPercent)+" %";
52     }
53
54     /**
55      * @return int
56      */

57     public String JavaDoc getHits() {
58         return ""+cache.getCacheHits();
59     }
60
61     /**
62      * @return int
63      */

64     public int getId() {
65         return id;
66     }
67
68     /**
69      * @return int
70      */

71     public String JavaDoc getMisses() {
72         return cache.getCacheMisses()+"";
73     }
74
75     /**
76      * @return String
77      */

78     public String JavaDoc getName() {
79         return name;
80     }
81
82     /**
83      * @return int
84      */

85     public int getNumber() {
86         return cache.getNumElements();
87     }
88
89     
90
91 }
Popular Tags