01: /*
02: * All content copyright (c) 2003-2007 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
03: */
04: package com.tc.runtime;
05:
06: class Jdk15MemoryUsage implements MemoryUsage {
07:
08: private final long max;
09: private final long free;
10: private final long used;
11: private final int usedPercentage;
12: private final String desc;
13: private final long collectionCount;
14:
15: public Jdk15MemoryUsage(java.lang.management.MemoryUsage stats,
16: String desc, long collectionCount) {
17: long statsMax = stats.getMax();
18: if (statsMax <= 0) {
19: this .max = stats.getCommitted();
20: } else {
21: this .max = statsMax;
22: }
23: this .used = stats.getUsed();
24: this .free = this .max - this .used;
25: this .usedPercentage = (int) (this .used * 100 / this .max);
26: this .desc = desc;
27: this .collectionCount = collectionCount;
28: }
29:
30: // CollectionCount is not supported
31: public Jdk15MemoryUsage(java.lang.management.MemoryUsage usage,
32: String desc) {
33: this (usage, desc, -1);
34: }
35:
36: public String getDescription() {
37: return desc;
38: }
39:
40: public long getFreeMemory() {
41: return free;
42: }
43:
44: public int getUsedPercentage() {
45: return usedPercentage;
46: }
47:
48: public long getMaxMemory() {
49: return max;
50: }
51:
52: public long getUsedMemory() {
53: return used;
54: }
55:
56: public String toString() {
57: return "Jdk15MemoryUsage ( max = " + max + ", used = " + used
58: + ", free = " + free + ", used % = " + usedPercentage
59: + ", collectionCount = " + collectionCount + " )";
60: }
61:
62: public long getCollectionCount() {
63: return collectionCount;
64: }
65: }
|