1:
37:
38: package ;
39:
40: import ;
41:
42: import ;
43: import ;
44: import ;
45:
46: import ;
47:
48:
58: public final class MemoryPoolMXBeanImpl
59: extends BeanImpl
60: implements MemoryPoolMXBean
61: {
62:
63:
66: private String name;
67:
68:
71: private static final String COLLECTION_USAGE_THRESHOLD =
72: "gnu.java.lang.management.CollectionUsageThresholdSupport";
73:
74:
77: private static final String USAGE_THRESHOLD =
78: "gnu.java.lang.management.UsageThresholdSupport";
79:
80:
89: public MemoryPoolMXBeanImpl(String name)
90: throws NotCompliantMBeanException
91: {
92: super(MemoryPoolMXBean.class);
93: this.name = name;
94: }
95:
96: public MemoryUsage getCollectionUsage()
97: {
98: return VMMemoryPoolMXBeanImpl.getCollectionUsage(name);
99: }
100:
101: public long getCollectionUsageThreshold()
102: {
103: if (isCollectionUsageThresholdSupported())
104: return VMMemoryPoolMXBeanImpl.getCollectionUsageThreshold(name);
105: else
106: throw new UnsupportedOperationException("A collection usage "+
107: "threshold is not supported.");
108: }
109:
110: public long getCollectionUsageThresholdCount()
111: {
112: if (isCollectionUsageThresholdSupported())
113: return VMMemoryPoolMXBeanImpl.getCollectionUsageThresholdCount(name);
114: else
115: throw new UnsupportedOperationException("A collection usage "+
116: "threshold is not supported.");
117: }
118:
119: public String[] getMemoryManagerNames()
120: {
121: return VMMemoryPoolMXBeanImpl.getMemoryManagerNames(name);
122: }
123:
124: public String getName()
125: {
126: return name;
127: }
128:
129: public MemoryUsage getPeakUsage()
130: {
131: if (isValid())
132: return VMMemoryPoolMXBeanImpl.getPeakUsage(name);
133: else
134: return null;
135: }
136:
137: public MemoryType getType()
138: {
139: return
140: MemoryType.valueOf(VMMemoryPoolMXBeanImpl.getType(name));
141: }
142:
143: public MemoryUsage getUsage()
144: {
145: if (isValid())
146: return VMMemoryPoolMXBeanImpl.getUsage(name);
147: else
148: return null;
149: }
150:
151: public long getUsageThreshold()
152: {
153: if (isUsageThresholdSupported())
154: return VMMemoryPoolMXBeanImpl.getUsageThreshold(name);
155: else
156: throw new UnsupportedOperationException("A usage threshold " +
157: "is not supported.");
158: }
159:
160: public long getUsageThresholdCount()
161: {
162: if (isUsageThresholdSupported())
163: return VMMemoryPoolMXBeanImpl.getUsageThresholdCount(name);
164: else
165: throw new UnsupportedOperationException("A usage threshold " +
166: "is not supported.");
167: }
168:
169: public boolean isCollectionUsageThresholdExceeded()
170: {
171: return getCollectionUsage().getUsed() >= getCollectionUsageThreshold();
172: }
173:
174: public boolean isCollectionUsageThresholdSupported()
175: {
176: return SystemProperties.getProperty(COLLECTION_USAGE_THRESHOLD) != null;
177: }
178:
179: public boolean isUsageThresholdExceeded()
180: {
181: return getUsage().getUsed() >= getUsageThreshold();
182: }
183:
184: public boolean isUsageThresholdSupported()
185: {
186: return SystemProperties.getProperty(USAGE_THRESHOLD) != null;
187: }
188:
189: public boolean isValid()
190: {
191: return VMMemoryPoolMXBeanImpl.isValid(name);
192: }
193:
194: public void resetPeakUsage()
195: {
196: checkControlPermissions();
197: VMMemoryPoolMXBeanImpl.resetPeakUsage(name);
198: }
199:
200: public void setCollectionUsageThreshold(long threshold)
201: {
202: checkControlPermissions();
203: if (threshold < 0)
204: throw new IllegalArgumentException("Threshold of " + threshold +
205: "is less than zero.");
206: if (isCollectionUsageThresholdSupported())
207: VMMemoryPoolMXBeanImpl.setCollectionUsageThreshold(name, threshold);
208: else
209: throw new UnsupportedOperationException("A collection usage "+
210: "threshold is not supported.");
211: }
212:
213: public void setUsageThreshold(long threshold)
214: {
215: checkControlPermissions();
216: if (threshold < 0)
217: throw new IllegalArgumentException("Threshold of " + threshold +
218: "is less than zero.");
219: if (isUsageThresholdSupported())
220: VMMemoryPoolMXBeanImpl.setUsageThreshold(name, threshold);
221: else
222: throw new UnsupportedOperationException("A usage threshold " +
223: "is not supported.");
224: }
225:
226: }