1 package charactermanaj.graphics.io;
3 import java.lang.management.ManagementFactory;
5 import javax.management.JMException;
6 import javax.management.MBeanServer;
7 import javax.management.ObjectName;
8 import javax.management.StandardMBean;
10 public final class ImageCacheMBeanImpl implements ImageCacheMBean {
12 private static ImageCacheMBeanImpl singleton = new ImageCacheMBeanImpl();
14 private ImageCacheMBeanImpl() {
18 public static ImageCacheMBeanImpl getSingleton() {
22 public static void setupMBean() throws JMException {
23 MBeanServer srv = ManagementFactory.getPlatformMBeanServer();
25 new StandardMBean(singleton, ImageCacheMBean.class),
26 new ObjectName("CharacterManaJ:type=ImageCache,name=Singleton"));
29 private long readCount;
31 private long cacheHitCount;
33 private long totalBytes;
35 private long maxBytes;
37 private int totalCount;
39 private int instanceCount;
41 public synchronized long getReadCount() {
45 public synchronized void setReadCount(long readCount) {
46 this.readCount = readCount;
49 public synchronized long getCacheHitCount() {
53 public synchronized void setCacheHitCount(long cacheHitCount) {
54 this.cacheHitCount = cacheHitCount;
57 public synchronized long getTotalBytes() {
61 public synchronized void setTotalBytes(long totalBytes) {
62 this.totalBytes = totalBytes;
65 public synchronized long getMaxBytes() {
69 public synchronized void setMaxBytes(long maxBytes) {
70 this.maxBytes = maxBytes;
73 public synchronized void incrementReadCount(boolean cacheHit) {
80 public synchronized void cacheIn(long bytes) {
83 if (totalBytes > maxBytes) {
84 maxBytes = totalBytes;
88 public synchronized void cacheOut(long bytes) {
93 public synchronized int getTotalCount() {
97 public synchronized int getInstanceCount() {
101 public synchronized void incrementInstance() {
105 public synchronized void decrementInstance() {
109 public synchronized void reset() {
118 public String toString() {
119 synchronized (this) {
120 StringBuilder buf = new StringBuilder();
121 buf.append("imageCacheMBean ");
122 buf.append(cacheHitCount);
124 buf.append(readCount);
125 return buf.toString();