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