feat(jdk8): move files to new folder to avoid resources compiled.

This commit is contained in:
2025-09-07 15:25:52 +08:00
parent 3f0047bf6f
commit 8c35cfb1c0
17415 changed files with 217 additions and 213 deletions

View File

@@ -0,0 +1,130 @@
/*
* Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* 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.
*/
package sun.jvmstat.monitor;
/**
* The base class for Instrumentation Monitoring Objects. This base class
* provides implementations of the {@link Monitor} methods that are common
* to all classes implementing the Monitor interface..
*
* @author Brian Doherty
* @since 1.5
*/
public abstract class AbstractMonitor implements Monitor {
protected String name;
protected Units units;
protected Variability variability;
protected int vectorLength;
protected boolean supported;
/**
* Create a vector instrumentation monitoring object with the given
* name and attributes.
*
* @param name the name to assign to this instrumentation object.
* @param units the units of measure attribute
* @param variability the variability attribute
* @param supported support level indicator
* @param vectorLength the length of the vector, or 0 if not a vector type.
*/
protected AbstractMonitor(String name, Units units, Variability variability,
boolean supported, int vectorLength) {
this.name = name;
this.units = units;
this.variability = variability;
this.vectorLength = vectorLength;
this.supported = supported;
}
/**
* Create a scalar instrumentation monitoring object with the given
* name and attributes.
*
* @param name the name to assign to this instrumentation object.
* @param units the units of measure attribute
* @param variability the variability attribute
* @param supported support level indicator
*/
protected AbstractMonitor(String name, Units units, Variability variability,
boolean supported) {
this(name, units, variability, supported, 0);
}
/**
* {@inheritDoc}
*/
public String getName() {
return name;
}
/**
* {@inheritDoc}
*/
public String getBaseName() {
int baseIndex = name.lastIndexOf(".")+1;
return name.substring(baseIndex);
}
/**
* {@inheritDoc}
*/
public Units getUnits() {
return units;
}
/**
* {@inheritDoc}
*/
public Variability getVariability() {
return variability;
}
/**
* {@inheritDoc}
*/
public boolean isVector() {
return vectorLength > 0;
}
/**
* {@inheritDoc}
*/
public int getVectorLength() {
return vectorLength;
}
/**
* {@inheritDoc}
*/
public boolean isSupported() {
return supported;
}
/**
* {@inheritDoc}
*/
public abstract Object getValue();
}

View File

@@ -0,0 +1,57 @@
/*
* Copyright (c) 2004, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* 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.
*/
package sun.jvmstat.monitor;
/**
* Interface for Monitoring ByteArrayInstrument objects.
*
* This interface is provided to support the StringMonitor interface. No
* instrumentation objects of this direct type can currently be created
* or monitored.
*
* @author Brian Doherty
* @since 1.5
* @see sun.jvmstat.instrument.ByteArrayInstrument
*/
public interface ByteArrayMonitor extends Monitor {
/**
* Get a copy of the current values of the elements of the
* ByteArrayInstrument object.
*
* @return byte[] - a copy of the bytes in the associated
* instrumenattion object.
*/
public byte[] byteArrayValue();
/**
* Get the current value of an element of the ByteArrayInstrument object.
*
* @return byte - the byte value at the specified index in the
* associated instrumentation object.
*/
public byte byteAt(int index);
}

View File

@@ -0,0 +1,574 @@
/*
* Copyright (c) 2004, 2020, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* 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.
*/
package sun.jvmstat.monitor;
import java.net.*;
/**
* An abstraction that identifies a target host and communications
* protocol. The HostIdentifier, or hostid, provides a convenient string
* representation of the information needed to locate and communicate with
* a target host. The string, based on a {@link URI}, may specify the
* the communications protocol, host name, and protocol specific information
* for a target host. The format for a HostIdentifier string is:
* <pre>
* [<I>protocol</I>:][[<I>//</I>]<I>hostname</I>][<I>:port</I>][<I>/servername</I>]
* </pre>
* There are actually no required components of this string, as a null string
* is interpreted to mean a local connection to the local host and is equivalent
* to the string <em>local://localhost</em>. The components of the
* HostIdentifier are:
* <ul>
* <li><p><tt>protocol</tt> - The communications protocol. If omitted,
* and a hostname is not specified, then default local protocol,
* <em>local:</em>, is assumed. If the protocol is omitted and a
* hostname is specified then the default remote protocol,
* <em>rmi:</em> is assumed.
* </p></li>
* <li><p><tt>hostname</tt> - The hostname. If omitted, then
* <em>localhost</em> is assumed. If the protocol is also omitted,
* then default local protocol <em>local:</em> is also assumed.
* If the hostname is not omitted but the protocol is omitted,
* then the default remote protocol, <em>rmi:</em> is assumed.
* </p></li>
* <li><p><tt>port</tt> - The port for the communications protocol.
* Treatment of the <tt>port</tt> parameter is implementation
* (protocol) specific. It is unused by the default local protocol,
* <em>local:</em>. For the default remote protocol, <em>rmi:</em>,
* <tt>port</tt> indicates the port number of the <em>rmiregistry</em>
* on the target host and defaults to port 1099.
* </p></li>
* <li><p><tt>servername</tt> - The treatment of the Path, Query, and
* Fragment components of the HostIdentifier are implementation
* (protocol) dependent. These components are ignored by the
* default local protocol, <em>local:</em>. For the default remote
* protocol, <em>rmi</em>, the Path component is interpreted as
* the name of the RMI remote object. The Query component may
* contain an access mode specifier <em>?mode=</em> specifying
* <em>"r"</em> or <em>"rw"</em> access (write access currently
* ignored). The Fragment part is ignored.
* </p></li>
* </ul>
* <p>
* All HostIdentifier objects are represented as absolute, hierarchical URIs.
* The constructors accept relative URIs, but these will generally be
* transformed into an absolute URI specifying a default protocol. A
* HostIdentifier differs from a URI in that certain contractions and
* illicit syntactical constructions are allowed. The following are all
* valid HostIdentifier strings:
*
* <ul>
* <li><p>&lt null &gt - transformed into "//localhost"</p></li>
* <li><p>localhost - transformed into "//localhost"</p></li>
* <li><p>hostname - transformed into "//hostname"</p></li>
* <li><p>hostname:port - transformed into "//hostname:port"</p></li>
* <li><p>proto:hostname - transformed into "proto://hostname"</p></li>
* <li><p>proto:hostname:port - transformed into
* "proto://hostname:port"</p></li>
* <li><p>proto://hostname:port</p></li>
* </ul>
* </p>
*
* @see URI
* @see VmIdentifier
*
* @author Brian Doherty
* @since 1.5
*/
public class HostIdentifier {
private URI uri;
/**
* creates a canonical representation of the uriString. This method
* performs certain translations depending on the type of URI generated
* by the string.
*/
private URI canonicalize(String uriString) throws URISyntaxException {
if ((uriString == null) || (uriString.compareTo("localhost") == 0)) {
uriString = "//localhost";
return new URI(uriString);
}
if (Character.isDigit(uriString.charAt(0))) {
// may be hostname or hostname:port since it starts with digits
uriString = "//" + uriString;
}
URI u = new URI(uriString);
if (u.isAbsolute()) {
if (u.isOpaque()) {
/*
* this code is here to deal with a special case. For ease of
* use, we'd like to be able to handle the case where the user
* specifies hostname:port, not requiring the scheme part.
* This introduces some subtleties.
* hostname:port - scheme = hostname
* - schemespecificpart = port
* - hostname = null
* - userinfo=null
* however, someone could also enter scheme:hostname:port and
* get into this code. the strategy is to consider this
* syntax illegal and provide some code to defend against it.
* Basically, we test that the string contains only one ":"
* and that the ssp is numeric. If we get two colons, we will
* attempt to insert the "//" after the first colon and then
* try to create a URI from the resulting string.
*/
String scheme = u.getScheme();
String ssp = u.getSchemeSpecificPart();
String frag = u.getFragment();
URI u2 = null;
int c1index = uriString.indexOf(":");
int c2index = uriString.lastIndexOf(":");
if (c2index != c1index) {
/*
* this is the scheme:hostname:port case. Attempt to
* transform this to scheme://hostname:port. If a path
* part is part of the original strings, it will be
* included in the SchemeSpecificPart. however, the
* fragment part must be handled separately.
*/
if (frag == null) {
u2 = new URI(scheme + "://" + ssp);
} else {
u2 = new URI(scheme + "://" + ssp + "#" + frag);
}
return u2;
}
/*
* here we have the <string>:<string> case, possibly with
* optional path and fragment components. we assume that
* the part following the colon is a number. we don't check
* this condition here as it will get detected later anyway.
*/
u2 = new URI("//" + uriString);
return u2;
} else {
return u;
}
} else {
/*
* This is the case where we were given a hostname followed
* by a path part, fragment part, or both a path and fragment
* part. The key here is that no scheme part was specified.
* For this case, if the scheme specific part does not begin
* with "//", then we prefix the "//" to the given string and
* attempt to create a URI from the resulting string.
*/
String ssp = u.getSchemeSpecificPart();
if (ssp.startsWith("//")) {
return u;
} else {
return new URI("//" + uriString);
}
}
}
/**
* Create a HostIdentifier instance from a string value.
*
* @param uriString a string representing a target host. The syntax of
* the string must conform to the rules specified in the
* class documentation.
*
* @throws URISyntaxException Thrown when the uriString or its canonical
* form is poorly formed. This exception may
* get encapsulated into a MonitorException in
* a future version.
*
*/
public HostIdentifier(String uriString) throws URISyntaxException {
uri = canonicalize(uriString);
}
/**
* Create a HostIdentifier instance from component parts of a URI.
*
* @param scheme the {@link URI#getScheme} component of a URI.
* @param authority the {@link URI#getAuthority} component of a URI.
* @param path the {@link URI#getPath} component of a URI.
* @param query the {@link URI#getQuery} component of a URI.
* @param fragment the {@link URI#getFragment} component of a URI.
*
* @throws URISyntaxException Thrown when the uriString or its canonical
* form is poorly formed. This exception may
* get encapsulated into a MonitorException in
* a future version.
* @see URI
*/
public HostIdentifier(String scheme, String authority, String path,
String query, String fragment)
throws URISyntaxException {
uri = new URI(scheme, authority, path, query, fragment);
}
/**
* Create a HostIdentifier instance from a VmIdentifier.
*
* The necessary components of the VmIdentifier are extracted and
* reassembled into a HostIdentifier. If a "file:" scheme (protocol)
* is specified, the the returned HostIdentifier will always be
* equivalent to HostIdentifier("file://localhost").
*
* @param vmid the VmIdentifier use to construct the HostIdentifier.
*/
public HostIdentifier(VmIdentifier vmid) {
/*
* Extract all components of the VmIdentifier URI except the
* user-info part of the authority (the lvmid).
*/
StringBuilder sb = new StringBuilder();
String scheme = vmid.getScheme();
String host = vmid.getHost();
String authority = vmid.getAuthority();
// check for 'file:' VmIdentifiers and handled as a special case.
if ((scheme != null) && (scheme.compareTo("file") == 0)) {
try {
uri = new URI("file://localhost");
} catch (URISyntaxException e) { };
return;
}
if ((host != null) && (host.compareTo(authority) == 0)) {
/*
* this condition occurs when the VmIdentifier specifies only
* the authority (i.e. the lvmid ), and not a host name.
*/
host = null;
}
if (scheme == null) {
if (host == null) {
scheme = "local"; // default local scheme
} else {
/*
* rmi is the default remote scheme. if the VmIdentifier
* specifies some other protocol, this default is overridden.
*/
scheme = "rmi";
}
}
sb.append(scheme).append("://");
if (host == null) {
sb.append("localhost"); // default host name
} else {
sb.append(host);
}
int port = vmid.getPort();
if (port != -1) {
sb.append(":").append(port);
}
String path = vmid.getPath();
if ((path != null) && (path.length() != 0)) {
sb.append(path);
}
String query = vmid.getQuery();
if (query != null) {
sb.append("?").append(query);
}
String frag = vmid.getFragment();
if (frag != null) {
sb.append("#").append(frag);
}
try {
uri = new URI(sb.toString());
} catch (URISyntaxException e) {
// shouldn't happen, as we were passed a valid VmIdentifier
throw new RuntimeException("Internal Error", e);
}
}
/**
* Resolve a VmIdentifier with this HostIdentifier. A VmIdentifier, such
* as <em>1234</em> or <em>1234@hostname</em> or any other string that
* omits certain components of the URI string may be valid, but is certainly
* incomplete. They are missing critical information for identifying the
* the communications protocol, target host, or other parameters. A
* VmIdentifier of this form is considered <em>unresolved</em>. This method
* uses components of the HostIdentifier to resolve the missing components
* of the VmIdentifier.
* <p>
* Specified components of the unresolved VmIdentifier take precedence
* over their HostIdentifier counterparts. For example, if the VmIdentifier
* indicates <em>1234@hostname:2099</em> and the HostIdentifier indicates
* <em>rmi://hostname:1099/</em>, then the resolved VmIdentifier will
* be <em>rmi://1234@hostname:2099</em>. Any component not explicitly
* specified or assumed by the HostIdentifier, will remain unresolved in
* resolved VmIdentifier.
* <p>
* A VmIdentifier specifying a <em>file:</em> scheme (protocol), is
* not changed in any way by this method.
*
* @param vmid the unresolved VmIdentifier.
* @return VmIdentifier - the resolved VmIdentifier. If vmid was resolved
* on entry to this method, then the returned
* VmIdentifier will be equal, but not identical, to
* vmid.
*/
public VmIdentifier resolve(VmIdentifier vmid)
throws URISyntaxException, MonitorException {
String scheme = vmid.getScheme();
String host = vmid.getHost();
String authority = vmid.getAuthority();
if ((scheme != null) && (scheme.compareTo("file") == 0)) {
// don't attempt to resolve a file based VmIdentifier.
return vmid;
}
if ((host != null) && (host.compareTo(authority) == 0)) {
/*
* this condition occurs when the VmIdentifier specifies only
* the authority (i.e. an lvmid), and not a host name.
*/
host = null;
}
if (scheme == null) {
scheme = getScheme();
}
URI nuri = null;
StringBuffer sb = new StringBuffer();
sb.append(scheme).append("://");
String userInfo = vmid.getUserInfo();
if (userInfo != null) {
sb.append(userInfo);
} else {
sb.append(vmid.getAuthority());
}
if (host == null) {
host = getHost();
}
sb.append("@").append(host);
int port = vmid.getPort();
if (port == -1) {
port = getPort();
}
if (port != -1) {
sb.append(":").append(port);
}
String path = vmid.getPath();
if ((path == null) || (path.length() == 0)) {
path = getPath();
}
if ((path != null) && (path.length() > 0)) {
sb.append(path);
}
String query = vmid.getQuery();
if (query == null) {
query = getQuery();
}
if (query != null) {
sb.append("?").append(query);
}
String fragment = vmid.getFragment();
if (fragment == null) {
fragment = getFragment();
}
if (fragment != null) {
sb.append("#").append(fragment);
}
String s = sb.toString();
return new VmIdentifier(s);
}
/**
* Return the Scheme, or protocol, portion of this HostIdentifier.
*
* @return String - the scheme for this HostIdentifier.
* @see URI#getScheme()
*/
public String getScheme() {
return uri.isAbsolute() ? uri.getScheme() : null;
}
/**
* Return the Scheme Specific Part of this HostIdentifier.
*
* @return String - the scheme specific part for this HostIdentifier.
* @see URI#getSchemeSpecificPart()
*/
public String getSchemeSpecificPart() {
return uri.getSchemeSpecificPart();
}
/**
* Return the User Info part of this HostIdentifier.
*
* @return String - the user info part for this HostIdentifier.
* @see URI#getUserInfo()
*/
public String getUserInfo() {
return uri.getUserInfo();
}
/**
* Return the Host part of this HostIdentifier.
*
* @return String - the host part for this HostIdentifier, or
* "localhost" if the URI.getHost() returns null.
* @see URI#getUserInfo()
*/
public String getHost() {
return (uri.getHost() == null) ? "localhost" : uri.getHost();
}
/**
* Return the Port for of this HostIdentifier.
*
* @return String - the port for this HostIdentifier
* @see URI#getPort()
*/
public int getPort() {
return uri.getPort();
}
/**
* Return the Path part of this HostIdentifier.
*
* @return String - the path part for this HostIdentifier.
* @see URI#getPath()
*/
public String getPath() {
return uri.getPath();
}
/**
* Return the Query part of this HostIdentifier.
*
* @return String - the query part for this HostIdentifier.
* @see URI#getQuery()
*/
public String getQuery() {
return uri.getQuery();
}
/**
* Return the Fragment part of this HostIdentifier.
*
* @return String - the fragment part for this HostIdentifier.
* @see URI#getFragment()
*/
public String getFragment() {
return uri.getFragment();
}
/**
* Return the mode indicated in this HostIdentifier.
*
* @return String - the mode string. If no mode is specified, then "r"
* is returned. otherwise, the specified mode is returned.
*/
public String getMode() {
String query = getQuery();
if (query != null) {
String[] queryArgs = query.split("\\+");
for (int i = 0; i < queryArgs.length; i++) {
if (queryArgs[i].startsWith("mode=")) {
int index = queryArgs[i].indexOf('=');
return queryArgs[i].substring(index+1);
}
}
}
return "r";
}
/**
* Return the URI associated with the HostIdentifier.
*
* @return URI - the URI.
* @see URI
*/
public URI getURI() {
return uri;
}
/**
* Return the hash code for this HostIdentifier. The hash code is
* identical to the hash code for the contained URI.
*
* @return int - the hashcode.
* @see URI#hashCode()
*/
public int hashCode() {
return uri.hashCode();
}
/**
* Test for quality with other objects.
*
* @param object the object to be test for equality.
* @return boolean - returns true if the given object is of type
* HostIdentifier and its URI field is equal to this
* object's URI field. Otherwise, returns false.
*
* @see URI#equals(Object)
*/
public boolean equals(Object object) {
if (object == this) {
return true;
}
if (!(object instanceof HostIdentifier)) {
return false;
}
return uri.equals(((HostIdentifier)object).uri);
}
/**
* Convert to a string representation. Conversion is identical to
* calling getURI().toString(). This may change in a future release.
*
* @return String - a String representation of the HostIdentifier.
*
* @see URI#toString()
*/
public String toString() {
return uri.toString();
}
}

View File

@@ -0,0 +1,48 @@
/*
* Copyright (c) 2004, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* 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.
*/
package sun.jvmstat.monitor;
/**
* Interface for Monitoring Integer Instrument Objects.
*
* The IntegerMonitor interface does not currently have a IntInstrument
* counterpart. It is used in limited situations to expose certain
* implementation specifics as performance counters. Typically,
* a LongInstrument serves as a reasonable replacement for the
* an IntInstrument class.
*
* @author Brian Doherty
* @since 1.5
*/
public interface IntegerMonitor extends Monitor {
/**
* Get the value of this Integer Instrumentation Object
*
* return int - the current value of this instrumentation object
*/
public int intValue();
}

View File

@@ -0,0 +1,43 @@
/*
* Copyright (c) 2004, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* 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.
*/
package sun.jvmstat.monitor;
/**
* Interface for Monitoring LongInstrument objects.
*
* @author Brian Doherty
* @since 1.5
* @see sun.jvmstat.instrument.LongInstrument
*/
public interface LongMonitor extends Monitor {
/**
* Get the current value of this LongInstrument object.
*
* @return long - the current value of the associated LongInstrument object.
*/
public long longValue();
}

View File

@@ -0,0 +1,93 @@
/*
* Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* 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.
*/
package sun.jvmstat.monitor;
/**
* Interface provided by Instrumentation Monitoring Objects.
*
* @author Brian Doherty
* @since 1.5
*/
public interface Monitor {
/**
* Returns the name of this instrumentation object.
*
* @return String - the name assigned to this instrumentation monitoring
* object
*/
String getName();
/**
* Returns the base name of this instrumentation object.
* The base name is the component of the name following the last
* "." character in the name.
*
* @return String - the base name of the name assigned to this
* instrumentation monitoring object.
*/
String getBaseName();
/**
* Returns the Units for this instrumentation monitoring object.
*
* @return Units - the units of measure attribute
*/
Units getUnits();
/**
* Returns the Variability for this instrumentation object.
*
*@return Variability - the variability attribute
*/
Variability getVariability();
/**
* Test if the instrumentation object is a vector type.
*
* @return boolean - true if this instrumentation object is a vector type,
* false otherwise.
*/
boolean isVector();
/**
* Return the length of the vector.
* @return int - the length of the vector or zero if this instrumentation
* object is a scalar type.
*/
int getVectorLength();
/**
* Test if the instrumentation object is supported.
*/
boolean isSupported();
/**
* Return an Object that encapsulates this instrumentation object's
* current data value.
*/
Object getValue();
}

View File

@@ -0,0 +1,71 @@
/*
* Copyright (c) 2004, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* 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.
*/
package sun.jvmstat.monitor;
/**
* Base class for exceptions that occur while interfacing with the
* Monitoring interfaces.
*
* @author Brian Doherty
* @since 1.5
*/
public class MonitorException extends Exception {
/**
* Create a MonitorException
*/
public MonitorException() {
super();
}
/**
* Create a MonitorException with the given message.
*
* @param message the message to associate with the exception.
*/
public MonitorException(String message) {
super(message);
}
/**
* Create a MonitorException with the given message and cause.
*
* @param message the message to associate with the exception.
* @param cause the exception causing this exception.
*/
public MonitorException(String message, Throwable cause) {
super(message, cause);
}
/**
* Create an InstrumentationException with the given cause.
*
* @param cause the exception causing this exception.
*/
public MonitorException(Throwable cause) {
super(cause);
}
}

View File

@@ -0,0 +1,422 @@
/*
* Copyright (c) 2004, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* 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.
*/
package sun.jvmstat.monitor;
import java.util.*;
import java.net.*;
import java.lang.reflect.*;
import sun.jvmstat.monitor.event.HostListener;
/**
* An abstraction for a host that contains instrumented Java Virtual
* Machines. The class provides abstract factory methods for creating
* concrete instances of this class and factory methods for creating
* {@link MonitoredVm} instances. Concrete implementations of this class
* provide methods for managing the communications protocols and provide
* for event notification.
*
* @author Brian Doherty
* @since 1.5
*
* @see HostIdentifier
* @see VmIdentifier
* @see MonitoredVm
* @see HostListener
*/
public abstract class MonitoredHost {
private static Map<HostIdentifier, MonitoredHost> monitoredHosts =
new HashMap<HostIdentifier, MonitoredHost>();
/*
* The monitoring implementation override mechanism. The value of
* this property is used as the class name for the concrete MonitoredHost
* subclass that implements the monitoring APIs. Setting this property
* will cause the remaining override mechanisms to be ignored. When
* this mechanism is used, the HostIdentifier scheme name, which
* indicates the communications protocol, is not used to locate a
* the protocol specific package. However, the HostIdentifier is
* still passed to the corresponding single arg constructor.
* This property is not expected to be set in normal circumstances.
*/
private static final String IMPL_OVERRIDE_PROP_NAME =
"sun.jvmstat.monitor.MonitoredHost";
/*
* The monitoring package name override mechanism. The value
* the this property is used as base package name for the
* monitoring implementation package. This property is not
* expected to be set under normal circumstances.
*/
private static final String IMPL_PKG_PROP_NAME =
"sun.jvmstat.monitor.package";
private static final String IMPL_PACKAGE =
System.getProperty(IMPL_PKG_PROP_NAME, "sun.jvmstat.perfdata");
/*
* The default optimized local protocol override mechanism. The value
* of this property is used to construct the default package name
* for the default optimized local protocol as follows:
* <IMPL_PACKAGE>.monitor.<LOCAL_PROTOCOL>
* This property is not expected to be set under normal circumstances.
*/
private static final String LOCAL_PROTOCOL_PROP_NAME =
"sun.jvmstat.monitor.local";
private static final String LOCAL_PROTOCOL =
System.getProperty(LOCAL_PROTOCOL_PROP_NAME, "local");
/*
* The default remote protocol override mechanism. The value of
* this property is used to construct the default package name
* for the default remote protocol protocol as follows:
* <IMPL_PACKAGE>.monitor.protocol.<REMOTE_PROTOCOL>
* This property is not expected to be set under normal circumstances.
*/
private static final String REMOTE_PROTOCOL_PROP_NAME =
"sun.jvmstat.monitor.remote";
private static final String REMOTE_PROTOCOL =
System.getProperty(REMOTE_PROTOCOL_PROP_NAME, "rmi");
/*
* The default class name of the MonitoredHost implementation subclass.
* There is no override mechanism for this variable, other than the
* IMPL_OVERRIDE_PROP_NAME override, which is larger in scope. A concrete
* instance of this class is expected to be found in:
* <IMPL_PACKAGE>.monitor.protocol.<protocol>.<MONITORED_HOST_CLASS>
*/
private static final String MONITORED_HOST_CLASS = "MonitoredHostProvider";
/**
* The HostIdentifier for this MonitoredHost instance.
*/
protected HostIdentifier hostId;
/**
* The polling interval, in milliseconds, for this MonitoredHost instance.
*/
protected int interval;
/**
* The last Exception encountered while polling this MonitoredHost.
*/
protected Exception lastException;
/**
* Factory method to construct MonitoredHost instances to manage
* connections to the host indicated by <tt>hostIdString</tt>
*
* @param hostIdString a String representation of a {@link HostIdentifier}
* @return MonitoredHost - the MonitoredHost instance for communicating
* with the indicated host using the protocol
* specified in hostIdString.
* @throws MonitorException Thrown if monitoring errors occur.
* @throws URISyntaxException Thrown when the hostIdString is poorly
* formed. This exception may get encapsulated
* into MonitorException in a future revision.
*/
public static MonitoredHost getMonitoredHost(String hostIdString)
throws MonitorException, URISyntaxException {
HostIdentifier hostId = new HostIdentifier(hostIdString);
return getMonitoredHost(hostId);
}
/**
* Factory method to construct a MonitoredHost instance to manage the
* connection to the Java Virtual Machine indicated by <tt>vmid</tt>.
*
* This method provide a convenient short cut for attaching to a specific
* instrumented Java Virtual Machine. The information in the VmIdentifier
* is used to construct a corresponding HostIdentifier, which in turn is
* used to create the MonitoredHost instance.
*
* @param vmid The identifier for the target Java Virtual Machine.
* @return MonitoredHost - The MonitoredHost object needed to attach to
* the target Java Virtual Machine.
*
* @throws MonitorException Thrown if monitoring errors occur.
*/
public static MonitoredHost getMonitoredHost(VmIdentifier vmid)
throws MonitorException {
// use the VmIdentifier to construct the corresponding HostIdentifier
HostIdentifier hostId = new HostIdentifier(vmid);
return getMonitoredHost(hostId);
}
/**
* Factory method to construct a MonitoredHost instance to manage the
* connection to the host indicated by <tt>hostId</tt>.
*
* @param hostId the identifier for the target host.
* @return MonitoredHost - The MonitoredHost object needed to attach to
* the target host.
*
* @throws MonitorException Thrown if monitoring errors occur.
*/
public static MonitoredHost getMonitoredHost(HostIdentifier hostId)
throws MonitorException {
/*
* determine the class name to load. If the system property is set,
* use the indicated class. otherwise, use the default class.
*/
String classname = System.getProperty(IMPL_OVERRIDE_PROP_NAME);
MonitoredHost mh = null;
synchronized(monitoredHosts) {
mh = monitoredHosts.get(hostId);
if (mh != null) {
if (mh.isErrored()) {
monitoredHosts.remove(hostId);
} else {
return mh;
}
}
}
hostId = resolveHostId(hostId);
if (classname == null) {
// construct the class name
classname = IMPL_PACKAGE + ".monitor.protocol."
+ hostId.getScheme() + "." + MONITORED_HOST_CLASS;
}
try {
// run the constructor taking a single String parameter.
Class<?> c = Class.forName(classname);
Constructor cons = c.getConstructor(
new Class[] { hostId.getClass() }
);
mh = (MonitoredHost)cons.newInstance(new Object[] { hostId } );
synchronized(monitoredHosts) {
monitoredHosts.put(mh.hostId, mh);
}
return mh;
} catch (ClassNotFoundException e) {
// from Class.forName();
throw new IllegalArgumentException("Could not find " + classname
+ ": " + e.getMessage(), e);
} catch (NoSuchMethodException e) {
// from Class.getConstructor();
throw new IllegalArgumentException(
"Expected constructor missing in " + classname + ": "
+ e.getMessage(), e);
} catch (IllegalAccessException e) {
// from Constructor.newInstance()
throw new IllegalArgumentException(
"Unexpected constructor access in " + classname + ": "
+ e.getMessage(), e);
} catch (InstantiationException e) {
throw new IllegalArgumentException(classname + "is abstract: "
+ e.getMessage(), e);
} catch (InvocationTargetException e) {
Throwable cause = e.getCause();
if (cause instanceof MonitorException) {
throw (MonitorException)cause;
}
throw new RuntimeException("Unexpected exception", e);
}
}
/**
* Method to resolve unspecified components of the given HostIdentifier
* by constructing a new HostIdentifier that replaces the unspecified
* components with the default values.
*
* @param hostId the unresolved HostIdentifier.
* @return HostIdentifier - a resolved HostIdentifier.
*
* @throws MonitorException Thrown if monitoring errors occur.
*/
protected static HostIdentifier resolveHostId(HostIdentifier hostId)
throws MonitorException {
String hostname = hostId.getHost();
String scheme = hostId.getScheme();
StringBuffer sb = new StringBuffer();
assert hostname != null;
if (scheme == null) {
if (hostname.compareTo("localhost") == 0) {
scheme = LOCAL_PROTOCOL;
} else {
scheme = REMOTE_PROTOCOL;
}
}
sb.append(scheme).append(":").append(hostId.getSchemeSpecificPart());
String frag = hostId.getFragment();
if (frag != null) {
sb.append("#").append(frag);
}
try {
return new HostIdentifier(sb.toString());
} catch (URISyntaxException e) {
// programming error - HostIdentifier was valid.
assert false;
throw new IllegalArgumentException("Malformed URI created: "
+ sb.toString());
}
}
/**
* Return the resolved HostIdentifier for this MonitoredHost.
*
* @return HostIdentifier - the resolved HostIdentifier.
*/
public HostIdentifier getHostIdentifier() {
return hostId;
}
/* ---- Methods to support polled MonitoredHost Implementations ----- */
/**
* Set the polling interval for this MonitoredHost.
*
* @param interval the polling interval, in milliseconds
*/
public void setInterval(int interval) {
this.interval = interval;
}
/**
* Get the polling interval.
*
* @return int - the polling interval in milliseconds for this MonitoredHost
*/
public int getInterval() {
return interval;
}
/**
* Set the last exception encountered while polling this MonitoredHost.
*
* @param lastException the last exception encountered;
*/
public void setLastException(Exception lastException) {
this.lastException = lastException;
}
/**
* Get the last exception encountered while polling this MonitoredHost.
*
* @return Exception - the last exception occurred while polling this
* MonitoredHost, or <tt>null</tt> if no exception
* has occurred or the exception has been cleared,
*/
public Exception getLastException() {
return lastException;
}
/**
* Clear the last exception.
*/
public void clearLastException() {
lastException = null;
}
/**
* Test if this MonitoredHost is in the errored state. If this method
* returns true, then the Exception returned by getLastException()
* indicates the Exception that caused the error condition.
*
* @return boolean - true if the MonitoredHost instance has experienced
* an error, or false if it hasn't or if any past
* error has been cleared.
*/
public boolean isErrored() {
return lastException != null;
}
/**
* Get the MonitoredVm for the given Java Virtual Machine. The default
* sampling interval is used for the MonitoredVm instance.
*
* @param id the VmIdentifier specifying the target Java Virtual Machine.
* @return MonitoredVm - the MonitoredVm instance for the target Java
* Virtual Machine.
* @throws MonitorException Thrown if monitoring errors occur.
*/
public abstract MonitoredVm getMonitoredVm(VmIdentifier id)
throws MonitorException;
/**
* Get the MonitoredVm for the given Java Virtual Machine. The sampling
* interval is set to the given interval.
*
* @param id the VmIdentifier specifying the target Java Virtual Machine.
* @param interval the sampling interval for the target Java Virtual Machine.
* @return MonitoredVm - the MonitoredVm instance for the target Java
* Virtual Machine.
* @throws MonitorException Thrown if monitoring errors occur.
*/
public abstract MonitoredVm getMonitoredVm(VmIdentifier id, int interval)
throws MonitorException;
/**
* Detach from the indicated MonitoredVm.
*
* @param vm the monitored Java Virtual Machine.
* @throws MonitorException Thrown if monitoring errors occur.
*/
public abstract void detach(MonitoredVm vm) throws MonitorException;
/**
* Add a HostListener. The given listener is added to the list
* of HostListener objects to be notified of MonitoredHost related events.
*
* @param listener the HostListener to add.
* @throws MonitorException Thrown if monitoring errors occur.
*/
public abstract void addHostListener(HostListener listener)
throws MonitorException;
/**
* Remove a HostListener. The given listener is removed from the list
* of HostListener objects to be notified of MonitoredHost related events.
*
* @param listener the HostListener to add.
* @throws MonitorException Thrown if monitoring errors occur.
*/
public abstract void removeHostListener(HostListener listener)
throws MonitorException;
/**
* Return the current set of active Java Virtual Machines for this
* MonitoredHost. The returned Set contains {@link Integer} instances
* holding the local virtual machine identifier, or <em>lvmid</em>
* for each instrumented Java Virtual Machine currently available.
*
* @return Set - the current set of active Java Virtual Machines associated
* with this MonitoredHost, or the empty set of none.
* @throws MonitorException Thrown if monitoring errors occur.
*/
public abstract Set<Integer> activeVms() throws MonitorException;
}

View File

@@ -0,0 +1,192 @@
/*
* Copyright (c) 2004, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* 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.
*/
package sun.jvmstat.monitor;
import java.util.List;
import sun.jvmstat.monitor.event.VmListener;
/**
* Interface for interacting with a monitorable Java Virtual Machine.
* The MonitoredVm interface provides methods for discovery of exported
* instrumentation, for attaching event listeners, and for overall
* maintenance of the connection to the target.
*
* @author Brian Doherty
* @since 1.5
*/
public interface MonitoredVm {
/**
* Get the VmIdentifier associated with this MonitoredVm
*
* @return VmIdentifier - the fully resolved Vm identifier associated
* with this MonitoredVm.
*/
VmIdentifier getVmIdentifier();
/**
* Find a named Instrumentation object.
*
* This method will look for the named instrumentation object in the
* instrumentation exported by this Java Virtual Machine. If an
* instrumentation object with the given name exists, a Monitor interface
* to that object will be return. Otherwise, the method returns
* <tt>null</tt>.
*
* @param name the name of the Instrumentation object to find.
* @return Monitor - the {@link Monitor} object that can be used to
* monitor the the named instrumentation object, or
* <tt>null</tt> if the named object doesn't exist.
* @throws MonitorException Thrown if an error occurs while communicating
* with the target Java Virtual Machine.
*/
Monitor findByName(String name) throws MonitorException;
/**
* Find all Instrumentation objects with names matching the given pattern.
*
* This method returns a {@link List} of Monitor objects such that
* the name of each object matches the given pattern.
*
* @param patternString a string containing a pattern as described in
* {@link java.util.regex.Pattern}.
* @return List<Monitor> - a List of {@link Monitor} objects that can be used to
* monitor the instrumentation objects whose names match
* the given pattern. If no instrumentation objects have`
* names matching the given pattern, then an empty List
* is returned.
* @throws MonitorException Thrown if an error occurs while communicating
* with the target Java Virtual Machine.
* @see java.util.regex.Pattern
*/
List<Monitor> findByPattern(String patternString) throws MonitorException;
/**
* Detach from target Java Virtual Machine.
*
* After calling this method, updates of the instrumentation data values
* may be halted. All event notifications are halted. Further interactions
* with this object should be avoided.
*/
void detach();
/* ---- Methods to support polled MonitoredVm Implementations ---- */
/**
* Set the polling interval to <code>interval</code> milliseconds.
*
* Polling based monitoring implementations need to refresh the
* instrumentation data on a periodic basis. This interface allows
* the interval to override the implementation specific default
* interval.
*
* @param interval the polling interval in milliseconds
*/
void setInterval(int interval);
/**
* Get the polling interval.
*
* @return int - the current polling interval in milliseconds.
* @see #setInterval
*/
int getInterval();
/**
* Set the last exception encountered while polling this MonitoredVm.
*
* Polling implementations may choose to poll asynchronously. This
* method allows an asynchronous task to communicate any polling related
* exceptions with the application. When an a non-null exception is reported
* through this interface, the MonitoredVm instance is considered to
* be in the <em>errored</em> state.
*
* @param cause the exception to record.
* @see #isErrored
*/
void setLastException(Exception cause);
/**
* Get the last exception encountered while polling this MonitoredVm.
*
* Returns the last exception observed by the implementation dependent
* polling task or <tt>null</tt> if no such error has occurred.
*
* @return Exception - the last exception that occurred during polling
* or <tt>null</tt> if no error condition exists.
* @see #isErrored
* @see #setLastException
*/
Exception getLastException();
/**
* Clear the last exception.
*
* Calling this method will clear the <em>errored</em> state of this
* MonitoredVm. However, there is no guarantee that clearing the
* the errored state return the asynchronous polling task to an
* operational state.
*
*/
void clearLastException();
/**
* Test if this MonitoredVm is in the errored state.
* The errored state exists only if an error was reported with
* call to {@link #setLastException} and only if the parameter to
* that call was non-null and no subsequent calls are made to
* {@link #clearLastException}.
*
* @return boolean - true if the instance has a non-null error condition
* set, false otherwise.
*
* @see #setLastException
* @see #getLastException
*/
boolean isErrored();
/**
* Add a VmListener. The given listener is added to the list of
* VmListener objects to be notified of MonitoredVm related events.
*
* @param listener the VmListener to add.
* @throws MonitorException Thrown if any problems occur while attempting
* to add this listener.
*/
void addVmListener(VmListener listener) throws MonitorException;
/**
* Remove a VmListener. The given listener is removed from the list of
* VmListener objects to be notified of MonitoredVm related events.
*
* @param listener the VmListener to be removed.
* @throws MonitorException Thrown if any problems occur while attempting
* to remove this listener.
*/
void removeVmListener(VmListener listener) throws MonitorException;
}

View File

@@ -0,0 +1,182 @@
/*
* Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* 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.
*/
package sun.jvmstat.monitor;
/**
* Utility class proving concenience methods for extracting various
* information from an MonitoredVm object.
*
* @author Brian Doherty
* @since 1.5
*/
public class MonitoredVmUtil {
/**
* Private constructor - prevent instantiation.
*/
private MonitoredVmUtil() { }
/**
* Return the Java Virtual Machine Version.
*
* @param vm the target MonitoredVm
* @return String - contains the version of the target JVM or the
* the string "Unknown" if the version cannot be
* determined.
*/
public static String vmVersion(MonitoredVm vm) throws MonitorException {
StringMonitor ver =
(StringMonitor)vm.findByName("java.property.java.vm.version");
return (ver == null) ? "Unknown" : ver.stringValue();
}
/**
* Return the command line for the target Java application.
*
* @param vm the target MonitoredVm
* @return String - contains the command line of the target Java
* application or the the string "Unknown" if the
* command line cannot be determined.
*/
public static String commandLine(MonitoredVm vm) throws MonitorException {
StringMonitor cmd = (StringMonitor)vm.findByName("sun.rt.javaCommand");
return (cmd == null) ? "Unknown" : cmd.stringValue();
}
/**
* Return the arguments to the main class for the target Java application.
* Returns the arguments to the main class. If the arguments can't be
* found, the string "Unknown" is returned.
*
* @param vm the target MonitoredVm
* @return String - contains the arguments to the main class for the
* target Java application or the the string "Unknown"
* if the command line cannot be determined.
*/
public static String mainArgs(MonitoredVm vm) throws MonitorException {
String commandLine = commandLine(vm);
int firstSpace = commandLine.indexOf(' ');
if (firstSpace > 0) {
return commandLine.substring(firstSpace + 1);
} else if (commandLine.compareTo("Unknown") == 0) {
return commandLine;
} else {
return null;
}
}
/**
* Return the main class for the target Java application.
* Returns the main class or the name of the jar file if the application
* was started with the <em>-jar</em> option.
*
* @param vm the target MonitoredVm
* @param fullPath include the full path to Jar file, where applicable
* @return String - contains the main class of the target Java
* application or the the string "Unknown" if the
* command line cannot be determined.
*/
public static String mainClass(MonitoredVm vm, boolean fullPath)
throws MonitorException {
String commandLine = commandLine(vm);
String arg0 = commandLine;
int firstSpace = commandLine.indexOf(' ');
if (firstSpace > 0) {
arg0 = commandLine.substring(0, firstSpace);
}
if (!fullPath) {
/*
* can't use File.separator() here because the separator
* for the target jvm may be different than the separator
* for the monitoring jvm.
*/
int lastFileSeparator = arg0.lastIndexOf('/');
if (lastFileSeparator > 0) {
return arg0.substring(lastFileSeparator + 1);
}
lastFileSeparator = arg0.lastIndexOf('\\');
if (lastFileSeparator > 0) {
return arg0.substring(lastFileSeparator + 1);
}
int lastPackageSeparator = arg0.lastIndexOf('.');
if (lastPackageSeparator > 0) {
return arg0.substring(lastPackageSeparator + 1);
}
}
return arg0;
}
/**
* Return the JVM arguments for the target Java application.
*
* @param vm the target MonitoredVm
* @return String - contains the arguments passed to the JVM for the
* target Java application or the the string "Unknown"
* if the command line cannot be determined.
*/
public static String jvmArgs(MonitoredVm vm) throws MonitorException {
StringMonitor jvmArgs = (StringMonitor)vm.findByName("java.rt.vmArgs");
return (jvmArgs == null) ? "Unknown" : jvmArgs.stringValue();
}
/**
* Return the JVM flags for the target Java application.
*
* @param vm the target MonitoredVm
* @return String - contains the flags passed to the JVM for the
* target Java application or the the string "Unknown"
* if the command line cannot be determined.
*/
public static String jvmFlags(MonitoredVm vm) throws MonitorException {
StringMonitor jvmFlags =
(StringMonitor)vm.findByName("java.rt.vmFlags");
return (jvmFlags == null) ? "Unknown" : jvmFlags.stringValue();
}
// Index of the sun.rt.jvmCapabilities counter
private static int IS_ATTACHABLE = 0;
private static int IS_KERNEL_VM = 1;
/**
* Returns true if the VM supports attach-on-demand.
*
* @param vm the target MonitoredVm
*/
public static boolean isAttachable(MonitoredVm vm) throws MonitorException {
StringMonitor jvmCapabilities =
(StringMonitor)vm.findByName("sun.rt.jvmCapabilities");
if (jvmCapabilities == null) {
return false;
} else {
return jvmCapabilities.stringValue().charAt(IS_ATTACHABLE) == '1';
}
}
}

View File

@@ -0,0 +1,44 @@
/*
* Copyright (c) 2004, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* 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.
*/
package sun.jvmstat.monitor;
/**
* Interface for Monitoring StringInstrument objects.
*
* @author Brian Doherty
* @since 1.5
* @see sun.jvmstat.instrument.StringInstrument
*/
public interface StringMonitor extends Monitor {
/**
* Get a copy of the current value of the StringInstrument object.
*
* @return String - a String object containing a copy of the value of
* the associated StringInstrument.
*/
public String stringValue();
}

View File

@@ -0,0 +1,128 @@
/*
* Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* 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.
*/
package sun.jvmstat.monitor;
/**
* Provides a typesafe enumeration for describing units of measurement
* attribute for instrumentation objects.
*
* @author Brian Doherty
*/
public class Units implements java.io.Serializable {
/* The enumeration values for this typesafe enumeration must be
* kept in synchronization with the Units enum in the perfData.hpp file
* in the HotSpot source base.
*/
private static final int NUNITS=8;
private static Units[] map = new Units[NUNITS];
private final String name;
private final int value;
/**
* An Invalid Units value.
*/
public static final Units INVALID = new Units("Invalid", 0);
/**
* Units attribute representing unit-less quantities.
*/
public static final Units NONE = new Units("None", 1);
/**
* Units attribute representing Bytes.
*/
public static final Units BYTES = new Units("Bytes", 2);
/**
* Units attribute representing Ticks.
*/
public static final Units TICKS = new Units("Ticks", 3);
/**
* Units attribute representing a count of events.
*/
public static final Units EVENTS = new Units("Events", 4);
/**
* Units attribute representing String data. Although not really
* a unit of measure, this Units value serves to distinguish String
* instrumentation objects from instrumentation objects of other types.
*/
public static final Units STRING = new Units("String", 5);
/**
* Units attribute representing Hertz (frequency).
*/
public static final Units HERTZ = new Units("Hertz", 6);
/**
* Returns a string describing this Unit of measurement attribute
*
* @return String - a descriptive string for this enum.
*/
public String toString() {
return name;
}
/**
* Returns the integer representation of this Units attribute
*
* @return int - an integer representation of this Units attribute.
*/
public int intValue() {
return value;
}
/**
* Maps an integer value to its corresponding Units attribute.
* If the integer value does not have a corresponding Units enum
* value, then {@link Units#INVALID} is returned.
*
* @param value an integer representation of counter Units
* @return Units - the Units object for the given <code>value</code>
* or {@link Units#INVALID} if out of range.
*/
public static Units toUnits(int value) {
if (value < 0 || value >= map.length || map[value] == null) {
return INVALID;
}
return map[value];
}
private Units(String name, int value) {
this.name = name;
this.value = value;
map[value] = this;
}
private static final long serialVersionUID = 6992337162326171013L;
}

View File

@@ -0,0 +1,111 @@
/*
* Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* 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.
*/
package sun.jvmstat.monitor;
/**
* Provides a typesafe enumeration for the Variability attribute for
* instrumentation objects.
*
* @author Brian Doherty
*/
public class Variability implements java.io.Serializable {
/* The enumeration values for this typesafe enumeration must be
* kept in synchronization with the Variability enum in the perfData.hpp file
* in the HotSpot source base.
*/
private static final int NATTRIBUTES = 4;
private static Variability[] map = new Variability[NATTRIBUTES];
private String name;
private int value;
/**
* An invalid Variablity value.
*/
public static final Variability INVALID = new Variability("Invalid",0);
/**
* Variability attribute representing Constant counters.
*/
public static final Variability CONSTANT = new Variability("Constant",1);
/**
* Variability attribute representing a Monotonically changing counters.
*/
public static final Variability MONOTONIC = new Variability("Monotonic",2);
/**
* Variability attribute representing Variable counters.
*/
public static final Variability VARIABLE = new Variability("Variable",3);
/**
* Returns a string describing this Variability attribute.
*
* @return String - a descriptive string for this enum.
*/
public String toString() {
return name;
}
/**
* Returns the integer representation of this Variability attribute.
*
* @return int - an integer representation of this Variability attribute.
*/
public int intValue() {
return value;
}
/**
* Maps an integer value its corresponding Variability attribute.
* If the integer value does not have a corresponding Variability enum
* value, the {@link Variability#INVALID} is returned
*
* @param value an integer representation of a Variability attribute
* @return Variability - The Variability object for the given
* <code>value</code> or {@link Variability#INVALID}
* if out of range.
*/
public static Variability toVariability(int value) {
if (value < 0 || value >= map.length || map[value] == null) {
return INVALID;
}
return map[value];
}
private Variability(String name, int value) {
this.name = name;
this.value = value;
map[value]=this;
}
private static final long serialVersionUID = 6992337162326171013L;
}

View File

@@ -0,0 +1,453 @@
/*
* Copyright (c) 2004, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* 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.
*/
package sun.jvmstat.monitor;
import java.net.*;
/**
* An abstraction that identifies a target Java Virtual Machine.
* The VmIdentifier, or vmid, provides a convenient string representation
* of the information needed to locate and communicate with a target
* Java Virtual Machine. The string, based on a {@link URI}, may specify
* the communications protocol, host name, local vm identifier, and protocol
* specific information for a target Java Virtual Machine. The format for
* a VmIdentifier string is:
* <pre>
* [<I>protocol</I>:][<I>//</I>]<I><B>lvmid</B></I>[<I>@hostname</I>][<I>:port</I>][<I>/servername</I>]
* </pre>
* The only required component of this string is the Local Virtual Machine
* Identifier, or <tt>lvmid</tt>, which uniquely identifies the target
* Java Virtual Machine on a host. The optional components of the VmIdentifier
* include:
* <ul>
* <li><p><tt>protocol</tt> - The communications protocol. A VmIdentifier
* omitting the protocol must be resolved against a HostIdentifier
* using {@link HostIdentifier#resolve}.
* </p></li>
* <li><p><tt>hostname</tt> - A hostname or IP address indicating the target
* host. A VmIdentifier omitting the protocol must be resolved
* against a HostIdentifier using {@link HostIdentifier#resolve}.
* </p></li>
* <li><p><tt>port</tt> - The port for the communications protocol.
* Treatment of the <tt>port</tt> parameter is implementation
* (protocol) specific. A VmIdentifier omitting the protocol should
* be resolved against a HostIdentifier using
* {@link HostIdentifier#resolve}.
* </p></li>
* <li><p><tt>servername</tt> - The treatment of the Path, Query, and
* Fragment components of the VmIdentifier are implementation
* (protocol) dependent. A VmIdentifier omitting the protocol should
* be resolved against a HostIdentifier using
* {@link HostIdentifier#resolve}.
* </p></li>
* </ul>
* <p>
* All VmIdentifier instances are constructed as absolute, hierarchical URIs.
* The constructors will accept relative (and even some malformed,
* though convenient) URI strings. Such strings are transformed into
* legitimate, absolute URI strings.
* </p>
* <p>
* With the exception of <em>file:</em> based VmIdentifier strings, all
* VmIdentifier strings must include a <tt>lvmid</tt>. Attempting to construct
* a non-file based VmIdentifier that doesn't include a <tt>lvmid</tt>
* component will result in a <tt>MonitorException</tt>.
* </p>
* <p>
* Here are some examples of VmIdentifier strings.
* <ul>
* <li><p>Relative URIs</p></li>
* <ul>
* <li><p><em>1234</em> - Specifies the Java Virtual Machine
* identified by lvmid <em>1234</em> on an unnamed host.
* This string is transformed into the absolute form
* <em>//1234</em>, which must be resolved against a
* HostIdentifier.
* </p></li>
* <li><p><em>1234@hostname</em> - Specifies the Java Virtual
* Machine identified by lvmid <em>1234</em> on host
* <em>hostname</em> with an unnamed protocol.
* This string is transformed into the absolute form
* <em>//1234@hostname</em>, which must be resolved against
* a HostIdentifier.
* </p></li>
* <li><p><em>1234@hostname:2099</em> - Specifies the Java Virtual
* Machine identified by lvmid <em>1234</em> on host
* <em>hostname</em> with an unnamed protocol, but with
* port <em>2099</em>. This string is transformed into
* the absolute form <em>//1234@hostname:2099</em>, which
* must be resolved against a HostIdentifier.
* </p></li>
* </ul>
* <li><p>Absolute URIs</p></li>
* <ul>
* <li><p><em>rmi://1234@hostname:2099/remoteobjectname</em> -
* Specifies the Java Virtual Machine identified by lvmid
* <em>1234</em> on host <em>hostname</em> accessed
* using the <em>rmi:</em> protocol through the rmi remote
* object named <em>remoteobjectname</em> as registered with
* the <em>rmiserver</em> on port <em>2099</em> on host
* <em>hostname</em>.
* </p></li>
* <li><p><em>file:/path/file</em> - Identifies a Java Virtual Machine
* through accessing a special file based protocol to use as
* the communications mechanism.
* </p></li>
* </ul>
* </ul>
* </p>
*
* @see URI
* @see HostIdentifier
* @author Brian Doherty
* @since 1.5
*/
public class VmIdentifier {
private URI uri;
/**
* creates a canonical representation of the uriString. This method
* performs certain translations depending on the type of URI generated
* by the string.
*/
private URI canonicalize(String uriString) throws URISyntaxException {
if (uriString == null) {
uriString = "local://0@localhost";
return new URI(uriString);
}
URI u = new URI(uriString);
if (u.isAbsolute()) {
if (u.isOpaque()) {
/*
* rmi:1234@hostname/path#fragment converted to
* rmi://1234@hostname/path#fragment
*/
u = new URI(u.getScheme(), "//" + u.getSchemeSpecificPart(),
u.getFragment());
}
} else {
/*
* make the uri absolute, if possible. A relative URI doesn't
* specify the scheme part, so it's safe to prepend a "//" and
* try again.
*/
if (!uriString.startsWith("//")) {
if (u.getFragment() == null) {
u = new URI("//" + u.getSchemeSpecificPart());
} else {
u = new URI("//" + u.getSchemeSpecificPart() + "#"
+ u.getFragment());
}
}
}
return u;
}
/**
* check that the VmIdentifier includes a unique numerical identifier
* for the target JVM.
*/
private void validate() throws URISyntaxException {
// file:// uri, which is a special case where the lvmid is not required.
String s = getScheme();
if ((s != null) && (s.compareTo("file") == 0)) {
return;
}
if (getLocalVmId() == -1) {
throw new URISyntaxException(uri.toString(), "Local vmid required");
}
}
/**
* Create a VmIdentifier instance from a string value.
*
* @param uriString a string representing a target Java Virtual Machine.
* The syntax of the string must conforms to the rules
* specified in the class documentation.
* @throws URISyntaxException Thrown when the uriString or its canonical
* form is poorly formed.
*/
public VmIdentifier(String uriString) throws URISyntaxException {
URI u;
try {
u = canonicalize(uriString);
} catch (URISyntaxException e) {
/*
* a vmid of the form 1234@hostname:1098 causes an exception,
* so try again with a leading "//"
*/
if (uriString.startsWith("//")) {
throw e;
}
u = canonicalize("//"+uriString);
}
uri = u;
// verify that we have a valid lvmid
validate();
}
/**
* Create a VmIdentifier instance from a URI object.
*
* @param uri a well formed, absolute URI indicating the
* target Java Virtual Machine.
* @throws URISyntaxException Thrown if the URI is missing some
* required component.
*/
public VmIdentifier(URI uri) throws URISyntaxException {
this.uri = uri;
validate();
}
/**
* Return the corresponding HostIdentifier for this VmIdentifier.
* <p>
* This method constructs a HostIdentifier object from the VmIdentifier.
* If the VmIdentifier is not specific about the protocol or other
* components of the URI, then the resulting HostIdentifier will
* be constructed based on this missing information. Typically, the
* missing components will have result in the HostIdentifier assigning
* assumed defaults that allow the VmIdentifier to be resolved according
* to those defaults.
* </p>
* <p>
* For example, a VmIdentifier that specifies only a <tt>lvmid</tt>
* will result in a HostIdentifier for <em>localhost</em> utilizing
* the default local protocol, <em>local:</em>. A VmIdentifier that
* specifies both a <tt>vmid</tt> and a <tt>hostname</tt> will result
* in a HostIdentifier for the specified host with the default remote
* protocol, <em>rmi:</em>, using the protocol defaults for the
* <tt>port</tt> and <tt>servername</tt> components.
* </p>
*
* @return HostIdentifier - the host identifier for the host containing
* the Java Virtual Machine represented by this
* VmIdentifier.
* @throws URISyntaxException Thrown if a bad host URI is constructed.
* This exception may get encapsulated into
* a MonitorException in a future version.
*/
public HostIdentifier getHostIdentifier() throws URISyntaxException {
StringBuffer sb = new StringBuffer();
if (getScheme() != null) {
sb.append(getScheme()).append(":");
}
sb.append("//").append(getHost());
if (getPort() != -1) {
sb.append(":").append(getPort());
}
if (getPath() != null) {
sb.append(getPath());
}
return new HostIdentifier(sb.toString());
}
/**
* Return the Scheme, or protocol, portion of this VmIdentifier.
*
* @return String - the scheme for this VmIdentifier.
* @see URI#getScheme()
*/
public String getScheme() {
return uri.getScheme();
}
/**
* Return the Scheme Specific Part of this VmIdentifier.
*
* @return String - the Scheme Specific Part for this VmIdentifier.
* @see URI#getSchemeSpecificPart()
*/
public String getSchemeSpecificPart() {
return uri.getSchemeSpecificPart();
}
/**
* Return the UserInfo part of this VmIdentifier.
*
* @return String - the UserInfo part for this VmIdentifier.
* @see URI#getUserInfo()
*/
public String getUserInfo() {
return uri.getUserInfo();
}
/**
* Return the Host part of this VmIdentifier.
*
* @return String - the Host part for this VmIdentifier.
* @see URI#getHost()
*/
public String getHost() {
return uri.getHost();
}
/**
* Return the Port part of this VmIdentifier.
*
* @return int - the Port part for this VmIdentifier.
* @see URI#getPort()
*/
public int getPort() {
return uri.getPort();
}
/**
* Return the Authority part of this VmIdentifier.
*
* @return String - the Authority part for this VmIdentifier.
* @see URI#getAuthority()
*/
public String getAuthority() {
return uri.getAuthority();
}
/**
* Return the Path part of this VmIdentifier.
*
* @return String - the Path part for this VmIdentifier.
* @see URI#getPath()
*/
public String getPath() {
return uri.getPath();
}
/**
* Return the Query part of this VmIdentifier.
*
* @return String - the Query part for this VmIdentifier.
* @see URI#getQuery()
*/
public String getQuery() {
return uri.getQuery();
}
/**
* Return the Fragment part of this VmIdentifier.
*
* @return String - the Fragment part for this VmIdentifier.
* @see URI#getFragment()
*/
public String getFragment() {
return uri.getFragment();
}
/**
* Return the Local Virtual Machine Identifier for this VmIdentifier.
* The Local Virtual Machine Identifier is also known as the
* <em>lvmid</em>.
*
* @return int - the lvmid for this VmIdentifier.
*/
public int getLocalVmId() {
int result = -1;
try {
if (uri.getUserInfo() == null) {
result = Integer.parseInt(uri.getAuthority());
} else {
result = Integer.parseInt(uri.getUserInfo());
}
} catch (NumberFormatException e) { }
return result;
}
/**
* Return the mode indicated in this VmIdentifier.
*
* @return String - the mode string. If no mode is specified, then "r"
* is returned. otherwise, the specified mode is returned.
*/
public String getMode() {
String query = getQuery();
if (query != null) {
String[] queryArgs = query.split("\\+");
for (int i = 0; i < queryArgs.length; i++) {
if (queryArgs[i].startsWith("mode=")) {
int index = queryArgs[i].indexOf('=');
return queryArgs[i].substring(index+1);
}
}
}
return "r";
}
/**
* Return the URI associated with the VmIdentifier.
*
* @return URI - the URI.
* @see URI
*/
public URI getURI() {
return uri;
}
/**
* Return the hash code for this VmIdentifier. The hash code is
* identical to the hash code for the contained URI.
*
* @return int - the hashcode.
* @see URI#hashCode()
*/
public int hashCode() {
return uri.hashCode();
}
/**
* Test for quality with other objects.
*
* @param object the object to be test for equality.
* @return boolean - returns true if the given object is of type
* VmIdentifier and its URI field is equal to
* this object's URI field. Otherwise, return false.
*
* @see URI#equals(Object)
*/
public boolean equals(Object object) {
if (object == this) {
return true;
}
if (!(object instanceof VmIdentifier)) {
return false;
}
return uri.equals(((VmIdentifier)object).uri);
}
/**
* Convert to a string representation. Conversion is identical to
* calling getURI().toString(). This may change in a future release.
*
* @return String - a String representation of the VmIdentifier.
*
* @see URI#toString()
*/
public String toString() {
return uri.toString();
}
}

View File

@@ -0,0 +1,56 @@
/*
* Copyright (c) 2004, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* 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.
*/
package sun.jvmstat.monitor.event;
import java.util.EventObject;
import sun.jvmstat.monitor.MonitoredHost;
/**
* Base class for events emitted by a {@link MonitoredHost}.
*
* @author Brian Doherty
* @since 1.5
*/
public class HostEvent extends EventObject {
/**
* Construct a new HostEvent instance.
*
* @param host the MonitoredHost source of the event.
*/
public HostEvent(MonitoredHost host) {
super(host);
}
/**
* Return the MonitoredHost source of this event.
*
* @return MonitoredHost - the source of this event.
*/
public MonitoredHost getMonitoredHost() {
return (MonitoredHost)source;
}
}

View File

@@ -0,0 +1,53 @@
/*
* Copyright (c) 2004, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* 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.
*/
package sun.jvmstat.monitor.event;
import java.util.EventListener;
/**
* Interface for listeners of MonitoredHost events.
*
* @author Brian Doherty
* @since 1.5
* @see sun.jvmstat.monitor.MonitoredHost
*/
public interface HostListener extends EventListener {
/**
* Invoked when the status of Java Virtual Machine changes.
*
* @param event the object describing the event.
*/
void vmStatusChanged(VmStatusChangeEvent event);
/**
* Invoked when the connection to the MonitoredHost has disconnected
* due to communication errors.
*
* @param event the object describing the event.
*/
void disconnected(HostEvent event);
}

View File

@@ -0,0 +1,92 @@
/*
* Copyright (c) 2004, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* 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.
*/
package sun.jvmstat.monitor.event;
import java.util.List;
import sun.jvmstat.monitor.MonitoredVm;
/**
* Provides a description of a change in status of the instrumentation
* exported by the MonitoredVm.
*
* @author Brian Doherty
* @since 1.5
*/
public class MonitorStatusChangeEvent extends VmEvent {
/**
* List of instrumentation objects inserted since the last event.
* Elements of this list will always be of type Monitor.
*/
protected List inserted;
/**
* List of instrumentation objects removed since the last event.
* Elements of this list will always be of type Monitor.
*/
protected List removed;
/**
* Construct a new MonitorStatusChangeEvent.
*
* @param vm the MonitoredVm source of the event.
* @param inserted the list of instrumentation objects inserted since
* the last event.
* @param removed the list of instrumentation objects removed since
* the last event.
*/
public MonitorStatusChangeEvent(MonitoredVm vm, List inserted,
List removed) {
super(vm);
this.inserted = inserted;
this.removed = removed;
}
/**
* Return the list of instrumentation objects that were inserted
* since the last event notification.
*
* @return List - a List of Monitor objects that were inserted into the
* instrumentation exported by the MonitoredHost. If no
* new instrumentation was inserted, an emply List is
* returned.
*/
public List getInserted() {
return inserted;
}
/**
* Return the set of instrumentation objects that were removed
* since the last event notification.
*
* @return List - a List of Monitor objects that were removed from the
* instrumentation exported by the MonitoredHost. If no
* instrumentation was removed, an emply List is returned.
*/
public List getRemoved() {
return removed;
}
}

View File

@@ -0,0 +1,56 @@
/*
* Copyright (c) 2004, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* 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.
*/
package sun.jvmstat.monitor.event;
import java.util.EventObject;
import sun.jvmstat.monitor.MonitoredVm;
/**
* Base class for events emitted by a {@link MonitoredVm}.
*
* @author Brian Doherty
* @since 1.5
*/
public class VmEvent extends EventObject {
/**
* Construct a new VmEvent instance.
*
* @param vm the MonitoredVm source of the event.
*/
public VmEvent(MonitoredVm vm) {
super(vm);
}
/**
* Return the MonitoredVm source of this event.
*
* @return MonitoredVm - the source of this event.
*/
public MonitoredVm getMonitoredVm() {
return (MonitoredVm)source;
}
}

View File

@@ -0,0 +1,63 @@
/*
* Copyright (c) 2004, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* 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.
*/
package sun.jvmstat.monitor.event;
import java.util.EventListener;
/**
* Interface for listeners of MonitoredVm events.
*
* @author Brian Doherty
* @since 1.5
* @see sun.jvmstat.monitor.MonitoredVm
*/
public interface VmListener extends EventListener {
/**
* Invoked when instrumentation objects are inserted into or removed
* from the MonitoredVm.
*
* @param event the object describing the event.
*/
void monitorStatusChanged(MonitorStatusChangeEvent event);
/**
* Invoked when instrumentation objects are updated. This event is
* generated at a fixed interval as determined by the polling rate
* of the MonitoredVm that the VmListener is registered with.
*
* @param event the object describing the event.
*/
void monitorsUpdated(VmEvent event);
/**
* Invoked when the connection to the MonitoredVm has disconnected
* due to communication errors.
*
* @param event the object describing the event.
*/
void disconnected(VmEvent event);
}

View File

@@ -0,0 +1,125 @@
/*
* Copyright (c) 2004, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* 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.
*/
package sun.jvmstat.monitor.event;
import java.util.Set;
import sun.jvmstat.monitor.MonitoredHost;
/**
* Provides a description of a change in status of the Java Virtual Machines
* associated with a MonitoredHost.
*
* @author Brian Doherty
* @since 1.5
*/
public class VmStatusChangeEvent extends HostEvent {
/**
* The set of currently active Java Virtual Machines for the MonitoredHost.
* The set contains an Integer object holding the <em>lvmid</em> for each
* active Java Virtual Machine on the MonitoredHost. This Set will only
* contain Integer objects.
*/
protected Set active;
/**
* The set of Java Virtual Machines started on MonitoredHost since the
* previous event. The set contains an Integer object holding the
* <em>lvmid</em> for each Java Virtual Machine started on the
* MonitoredHost. This Set will only contain Integer objects.
*/
protected Set started;
/**
* The set of Java Virtual Machines terminated on MonitoredHost since the
* previous event. The set contains an Integer object holding the
* <em>lvmid</em> for each Java Virtual Machine started on the
* MonitoredHost. This Set will only contain Integer objects.
*/
protected Set terminated;
/**
* Construct a new VmStatusChangeEvent instance.
*
* @param host the MonitoredHost that is the source of the event.
* @param active the set of currently active Java Virtual Machines
* @param started the set of Java Virtual Machines started since the
* last event.
* @param terminated the set of Java Virtual Machines terminated since
* the last event.
*/
public VmStatusChangeEvent(MonitoredHost host, Set active,
Set started, Set terminated) {
super(host);
this.active = active;
this.started = started;
this.terminated = terminated;
}
/**
* Return the set of currently active Java Virtual Machines.
* The set contains an Integer object holding the <em>lvmid</em> for each
* active Java Virtual Machine on the MonitoredHost.
*
* @return Set - a set of Integer objects containing the <em>lvmid</em>
* of each active Java Virtual Machine on the host. If
* there are no active Java Virtual Machines on the host,
* an empty Set is returned.
*/
public Set getActive() {
return active;
}
/**
* Return the set of Java Virtual Machines started since the last
* event notification. The set contains an Integer object holding
* the <em>lvmid</em> for each Java Virtual Machine started on the
* MonitoredHost since the last event notification.
*
* @return Set - a set of Integer objects containing the <em>lvmid</em>
* of each Java Virtual Machine started on the host. If
* no Java Virtual Machines were recently started on the
* host, an empty Set is returned.
*/
public Set getStarted() {
return started;
}
/**
* Return the set of Java Virtual Machines terminated since the last
* event notification. The set contains an Integer object holding
* the <em>lvmid</em> for each Java Virtual Machine terminated on the
* MonitoredHost since the last event notification.
*
* @return Set - a set of Integer objects containing the <em>lvmid</em>
* of each Java Virtual Machine terminated on the host. If
* no Java Virtual Machines were recently terminated on the
* host, an empty Set is returned.
*/
public Set getTerminated() {
return terminated;
}
}

View File

@@ -0,0 +1,57 @@
/*
* Copyright (c) 2004, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* 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.
*/
package sun.jvmstat.monitor.remote;
import sun.jvmstat.monitor.*;
/**
* Interface to support asynchronous polling of the exported
* instrumentation of a target Java Virtual Machine.
*
* @author Brian Doherty
* @since 1.5
*/
public interface BufferedMonitoredVm extends MonitoredVm {
/**
* Interface to get the bytes associated with the instrumentation
* for the target Java Virtual Machine.
*
* @return byte[] - a byte array containing the current bytes
* for the instrumentation exported by the
* target Java Virtual Machine.
*/
byte[] getBytes();
/**
* Interface to get the the size of the instrumentation buffer
* for the target Java Virtual Machine.
*
* @return int - the size of the instrumentation buffer for the
* target Java Virtual Machine.
*/
int getCapacity();
}

View File

@@ -0,0 +1,85 @@
/*
* Copyright (c) 2004, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* 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.
*/
package sun.jvmstat.monitor.remote;
import sun.jvmstat.monitor.*;
import java.rmi.Remote;
import java.rmi.RemoteException;
import java.io.IOException;
/**
* Remote Interface for discovering and attaching to remote
* monitorable Java Virtual Machines.
*
* @author Brian Doherty
* @since 1.5
*/
public interface RemoteHost extends Remote {
/**
* Remote method to attach to a remote HotSpot Java Virtual Machine
* identified by <code>vmid</code>.
*
* @param vmid The identifier for the target virtual machine.
* @return RemoteVm - A remote object for accessing the remote Java
* Virtual Machine.
*
* @throws MonitorException Thrown when any other error is encountered
* while communicating with the target virtual
* machine.
* @throws RemoteException
*
*/
RemoteVm attachVm(int vmid, String mode) throws RemoteException,
MonitorException;
/**
* Remote method to detach from a remote HotSpot Java Virtual Machine
* identified by <code>vmid</code>.
*
* @param rvm The remote object for the target Java Virtual
* Machine.
*
* @throws MonitorException Thrown when any other error is encountered
* while communicating with the target virtual
* machine.
* @throws RemoteException
*/
void detachVm(RemoteVm rvm) throws RemoteException, MonitorException;
/**
* Get a list of Local Virtual Machine Identifiers for the active
* Java Virtual Machine the remote system. A Local Virtual Machine
* Identifier is also known as an <em>lvmid</em>.
*
* @return int[] - A array of <em>lvmid</em>s.
* @throws MonitorException Thrown when any other error is encountered
* while communicating with the target virtual
* machine.
* @throws RemoteException
*/
int[] activeVms() throws RemoteException, MonitorException;
}

View File

@@ -0,0 +1,76 @@
/*
* Copyright (c) 2004, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* 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.
*/
package sun.jvmstat.monitor.remote;
import java.rmi.Remote;
import java.rmi.RemoteException;
/**
* Interface for accessing the instrumentation exported by a
* Java Virtual Machine running on a remote host.
*
* @author Brian Doherty
* @since 1.5
*/
public interface RemoteVm extends Remote {
/**
* Interface to get the bytes associated with the instrumentation
* for the remote Java Virtual Machine.
*
* @return byte[] - a byte array containing the current bytes
* for the instrumentation exported by the
* remote Java Virtual Machine.
* @throws RemoteException Thrown on any communication error
*/
byte[] getBytes() throws RemoteException;
/**
* Interface to get the the size of the instrumentation buffer
* for the target Java Virtual Machine.
*
* @return int - the size of the instrumentation buffer for the
* remote Java Virtual Machine.
* @throws RemoteException Thrown on any communication error
*/
int getCapacity() throws RemoteException;
/**
* Interface to return the Local Virtual Machine Identifier for
* the remote Java Virtual Machine. The Local Virtual Machine
* Identifier is also know as the <em>lvmid</em>.
*
* @throws RemoteException Thrown on any communication error
*/
int getLocalVmId() throws RemoteException;
/**
* Interface to detach from the remote Java Virtual Machine.
*
* @throws RemoteException Thrown on any communication error
*/
void detach() throws RemoteException;
}