001: /*
002: * Copyright 2003-2005 Sun Microsystems, Inc. All Rights Reserved.
003: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004: *
005: * This code is free software; you can redistribute it and/or modify it
006: * under the terms of the GNU General Public License version 2 only, as
007: * published by the Free Software Foundation. Sun designates this
008: * particular file as subject to the "Classpath" exception as provided
009: * by Sun in the LICENSE file that accompanied this code.
010: *
011: * This code is distributed in the hope that it will be useful, but WITHOUT
012: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
014: * version 2 for more details (a copy is included in the LICENSE file that
015: * accompanied this code).
016: *
017: * You should have received a copy of the GNU General Public License version
018: * 2 along with this work; if not, write to the Free Software Foundation,
019: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020: *
021: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022: * CA 95054 USA or visit www.sun.com if you need additional information or
023: * have any questions.
024: */
025:
026: package sun.management;
027:
028: import java.util.*;
029: import com.sun.management.VMOption;
030: import com.sun.management.VMOption.Origin;
031:
032: /**
033: * Flag class is a helper class for constructing a VMOption.
034: * It has the static methods for getting the Flag objects, each
035: * corresponds to one VMOption.
036: *
037: */
038: class Flag {
039: private String name;
040: private Object value;
041: private Origin origin;
042: private boolean writeable;
043: private boolean external;
044:
045: Flag(String name, Object value, boolean writeable,
046: boolean external, Origin origin) {
047: this .name = name;
048: this .value = value;
049: this .origin = origin;
050: this .writeable = writeable;
051: this .external = external;
052: }
053:
054: Object getValue() {
055: return value;
056: }
057:
058: boolean isWriteable() {
059: return writeable;
060: }
061:
062: boolean isExternal() {
063: return external;
064: }
065:
066: VMOption getVMOption() {
067: return new VMOption(name, value.toString(), writeable, origin);
068: }
069:
070: static Flag getFlag(String name) {
071: Flag[] fs = new Flag[1];
072: String[] names = new String[1];
073: names[0] = name;
074: int count = getFlags(names, fs, 1);
075: if (count == 1) {
076: return fs[0];
077: } else {
078: return null;
079: }
080: }
081:
082: static List<Flag> getAllFlags() {
083: int numFlags = getInternalFlagCount();
084: Flag[] fs = new Flag[numFlags];
085:
086: // Get all internal flags with names = null
087: int count = getFlags(null, fs, numFlags);
088: return Arrays.asList(fs);
089: }
090:
091: private static native String[] getAllFlagNames();
092:
093: private static native int getFlags(String[] names, Flag[] flags,
094: int count);
095:
096: private static native int getInternalFlagCount();
097:
098: // These set* methods are synchronized on the class object
099: // to avoid multiple threads updating the same flag at the same time.
100: static synchronized native void setLongValue(String name, long value);
101:
102: static synchronized native void setBooleanValue(String name,
103: boolean value);
104:
105: static synchronized native void setStringValue(String name,
106: String value);
107:
108: static {
109: initialize();
110: }
111:
112: private static native void initialize();
113: }
|