001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: package org.apache.harmony.lang.management;
019:
020: import java.lang.management.ClassLoadingMXBean;
021: import java.lang.management.ManagementPermission;
022:
023: /**
024: * Runtime type for {@link ClassLoadingMXBean}.
025: * <p>
026: * There is only ever one instance of this class in a virtual machine.
027: * </p>
028: *
029: * @since 1.5
030: */
031: public final class ClassLoadingMXBeanImpl extends DynamicMXBeanImpl
032: implements ClassLoadingMXBean {
033:
034: private static ClassLoadingMXBeanImpl instance = new ClassLoadingMXBeanImpl();
035:
036: /**
037: * Constructor intentionally private to prevent instantiation by others.
038: * Sets the metadata for this bean.
039: */
040: private ClassLoadingMXBeanImpl() {
041: setMBeanInfo(ManagementUtils
042: .getMBeanInfo(ClassLoadingMXBean.class.getName()));
043: }
044:
045: /**
046: * Singleton accessor method.
047: *
048: * @return the <code>ClassLoadingMXBeanImpl</code> singleton.
049: */
050: static ClassLoadingMXBeanImpl getInstance() {
051: return instance;
052: }
053:
054: /**
055: * @return the number of loaded classes
056: * @see #getLoadedClassCount()
057: */
058: private native int getLoadedClassCountImpl();
059:
060: /*
061: * (non-Javadoc)
062: *
063: * @see java.lang.management.ClassLoadingMXBean#getLoadedClassCount()
064: */
065: public int getLoadedClassCount() {
066: return this .getLoadedClassCountImpl();
067: }
068:
069: /**
070: * @return the total number of classes that have been loaded
071: * @see #getTotalLoadedClassCount()
072: */
073: private native long getTotalLoadedClassCountImpl();
074:
075: /*
076: * (non-Javadoc)
077: *
078: * @see java.lang.management.ClassLoadingMXBean#getTotalLoadedClassCount()
079: */
080: public long getTotalLoadedClassCount() {
081: return this .getTotalLoadedClassCountImpl();
082: }
083:
084: /**
085: * @return the total number of unloaded classes
086: * @see #getUnloadedClassCount()
087: */
088: private native long getUnloadedClassCountImpl();
089:
090: /*
091: * (non-Javadoc)
092: *
093: * @see java.lang.management.ClassLoadingMXBean#getUnloadedClassCount()
094: */
095: public long getUnloadedClassCount() {
096: return this .getUnloadedClassCountImpl();
097: }
098:
099: /**
100: * @return true if running in verbose mode
101: * @see #isVerbose()
102: */
103: private native boolean isVerboseImpl();
104:
105: /*
106: * (non-Javadoc)
107: *
108: * @see java.lang.management.ClassLoadingMXBean#isVerbose()
109: */
110: public boolean isVerbose() {
111: return this .isVerboseImpl();
112: }
113:
114: /**
115: * @param value
116: * true to put the class loading system into verbose mode, false
117: * to take the class loading system out of verbose mode.
118: * @see #setVerbose(boolean)
119: */
120: private native void setVerboseImpl(boolean value);
121:
122: /*
123: * (non-Javadoc)
124: *
125: * @see java.lang.management.ClassLoadingMXBean#setVerbose(boolean)
126: */
127: public void setVerbose(boolean value) {
128: SecurityManager security = System.getSecurityManager();
129: if (security != null) {
130: security
131: .checkPermission(new ManagementPermission("control"));
132: }
133: this.setVerboseImpl(value);
134: }
135: }
|