/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
* Class for processing command line arguments and providing method
* level access to arguments.
*
* @author Brian Doherty
* @since 1.5
*/
public class Arguments {
private static final boolean showUnsupported =
private int headerRate;
private boolean help;
private boolean list;
private boolean options;
private boolean constants;
private boolean constantsOnly;
private boolean strings;
private boolean timestamp;
private boolean snap;
private boolean verbose;
// undocumented options:
// -list [<vmid>] - list counter names
// -snap <vmid> - snapshot counter values as name=value pairs
// -name <pattern> - output counters matching given pattern
// -a - sort in ascending order (default)
// -d - sort in descending order
// -v - verbose output (-snap)
// -constants - output constants with -name output
// -strings - output strings with -name output
}
// least specific
String valueString = s;
if (index > 0) {
break;
}
}
try {
return value;
return value * 1000;
} else {
throw new IllegalArgumentException(
"Unknow time unit: " + unitString);
}
} catch (NumberFormatException e) {
throw new IllegalArgumentException(
"Could not convert interval: " + s);
}
}
int argc = 0;
throw new IllegalArgumentException("invalid argument count");
}
help = true;
return;
options = true;
return;
list = true;
throw new IllegalArgumentException("invalid argument count");
}
// list can take one arg - a vmid - fall through for arg processing
argc++;
}
comparator = new AscendingMonitorComparator();
comparator = new DescendingMonitorComparator();
timestamp = true;
verbose = true;
constants = true;
strings = true;
} else {
argc++;
throw new IllegalArgumentException(
"-h requires an integer argument");
}
}
try {
} catch (NumberFormatException e) {
headerRate = -1;
}
if (headerRate < 0) {
throw new IllegalArgumentException(
"illegal -h argument: " + value);
}
} else {
argc++;
throw new IllegalArgumentException(
"option argument expected");
}
}
} else {
/*
* there are scenarios here: special jstat_options file option
* or the rare case of a negative lvmid. The negative lvmid
* can occur in some operating environments (such as Windows
* 95/98/ME), so we provide for this case here by checking if
* the argument has any numerical characters. This assumes that
* there are no special jstat_options that contain numerical
* characters in their name.
*/
// extract the lvmid part of possible lvmid@host.domain:port
if (at_index < 0) {
} else {
}
// try to parse the lvmid part as an integer
try {
// it parsed, assume a negative lvmid and continue
break;
} catch (NumberFormatException nfe) {
// it didn't parse. check for the -snap or jstat_options
// file options.
snap = true;
} else if (argc == 0) {
} else {
throw new IllegalArgumentException(
}
}
}
}
// prevent 'jstat <pid>' from being accepted as a valid argument
throw new IllegalArgumentException("-<option> required");
}
case 3:
if (snap) {
throw new IllegalArgumentException("invalid argument count");
}
try {
} catch (NumberFormatException e) {
throw new IllegalArgumentException("illegal count value: "
}
break;
case 2:
if (snap) {
throw new IllegalArgumentException("invalid argument count");
}
break;
case 1:
break;
case 0:
if (!list) {
throw new IllegalArgumentException("invalid argument count");
}
break;
default:
throw new IllegalArgumentException("invalid argument count");
}
// set count and interval to their default values if not set above.
// default is for a single sample
count = 1;
interval = 0;
}
// validate arguments
if (comparator == null) {
comparator = new AscendingMonitorComparator();
}
// allow ',' characters to separate names, convert to '|' chars
// verify that the given pattern parses without errors
try {
} catch (PatternSyntaxException e) {
throw new IllegalArgumentException("Bad name pattern: "
+ e.getMessage());
}
// verify that the special option is valid and get it's formatter
if (specialOption != null) {
if (optionFormat == null) {
throw new IllegalArgumentException("Unknown option: -"
+ specialOption);
}
}
// verify that the vm identifier is valied
try {
} catch (URISyntaxException e) {
"Malformed VM Identifier: " + vmIdString);
throw iae;
}
}
return comparator;
}
public boolean isHelp() {
return help;
}
public boolean isList() {
return list;
}
public boolean isSnap() {
return snap;
}
public boolean isOptions() {
return options;
}
public boolean isVerbose() {
return verbose;
}
public boolean printConstants() {
return constants;
}
public boolean isConstantsOnly() {
return constantsOnly;
}
public boolean printStrings() {
return strings;
}
public boolean showUnsupported() {
return showUnsupported;
}
public int headerRate() {
return headerRate;
}
return names;
}
return vmId;
}
return vmIdString;
}
public int sampleInterval() {
return interval;
}
public int sampleCount() {
return count;
}
public boolean isTimestamp() {
return timestamp;
}
public boolean isSpecialOption() {
return specialOption != null;
}
return specialOption;
}
return optionFormat;
}
int i = 0;
try {
} catch (Exception e) {
if (debug) {
e.printStackTrace();
}
throw new IllegalArgumentException("Internal Error: Bad URL: "
+ e.getMessage());
}
assert u != null;
if (showUnsupported) {
assert u != null;
}
return sources;
}
}