OSDN Git Service

リポジトリ内改行コードのLFへの修正
[charactermanaj/CharacterManaJ.git] / src / main / java / charactermanaj / graphics / io / ImageCacheMBeanImpl.java
1 package charactermanaj.graphics.io;
2
3 import java.lang.management.ManagementFactory;
4
5 import javax.management.JMException;
6 import javax.management.MBeanServer;
7 import javax.management.ObjectName;
8 import javax.management.StandardMBean;
9
10 public final class ImageCacheMBeanImpl implements ImageCacheMBean {
11
12     private static ImageCacheMBeanImpl singleton = new ImageCacheMBeanImpl();
13
14     private ImageCacheMBeanImpl() {
15         super();
16     }
17
18     public static ImageCacheMBeanImpl getSingleton() {
19         return singleton;
20     }
21
22     public static void setupMBean() throws JMException {
23         MBeanServer srv = ManagementFactory.getPlatformMBeanServer();
24         srv.registerMBean(
25                 new StandardMBean(singleton, ImageCacheMBean.class),
26                 new ObjectName("CharacterManaJ:type=ImageCache,name=Singleton"));
27     }
28
29     private long readCount;
30
31     private long cacheHitCount;
32
33     private long totalBytes;
34
35     private long maxBytes;
36
37     private int totalCount;
38
39     private int instanceCount;
40
41     public synchronized long getReadCount() {
42         return readCount;
43     }
44
45     public synchronized void setReadCount(long readCount) {
46         this.readCount = readCount;
47     }
48
49     public synchronized long getCacheHitCount() {
50         return cacheHitCount;
51     }
52
53     public synchronized void setCacheHitCount(long cacheHitCount) {
54         this.cacheHitCount = cacheHitCount;
55     }
56
57     public synchronized long getTotalBytes() {
58         return totalBytes;
59     }
60
61     public synchronized void setTotalBytes(long totalBytes) {
62         this.totalBytes = totalBytes;
63     }
64
65     public synchronized long getMaxBytes() {
66         return maxBytes;
67     }
68
69     public synchronized void setMaxBytes(long maxBytes) {
70         this.maxBytes = maxBytes;
71     }
72
73     public synchronized void incrementReadCount(boolean cacheHit) {
74         readCount++;
75         if (cacheHit) {
76             cacheHitCount++;
77         }
78     }
79
80     public synchronized void cacheIn(long bytes) {
81         totalCount++;
82         totalBytes += bytes;
83         if (totalBytes > maxBytes) {
84             maxBytes = totalBytes;
85         }
86     }
87
88     public synchronized void cacheOut(long bytes) {
89         totalCount--;
90         totalBytes -= bytes;
91     }
92
93     public synchronized int getTotalCount() {
94         return totalCount;
95     }
96
97     public synchronized int getInstanceCount() {
98         return instanceCount;
99     }
100
101     public synchronized void incrementInstance() {
102         instanceCount++;
103     }
104
105     public synchronized void decrementInstance() {
106         instanceCount--;
107     }
108
109     public synchronized void reset() {
110         cacheHitCount = 0;
111         readCount = 0;
112         totalCount = 0;
113         totalBytes = 0;
114         maxBytes = 0;
115     }
116
117     @Override
118     public String toString() {
119         synchronized (this) {
120             StringBuilder buf = new StringBuilder();
121             buf.append("imageCacheMBean ");
122             buf.append(cacheHitCount);
123             buf.append("/");
124             buf.append(readCount);
125             return buf.toString();
126         }
127     }
128 }