Jvmstat

sun.jvmstat.perfdata.monitor
Class AbstractMonitoredVm

java.lang.Object
  extended by sun.jvmstat.perfdata.monitor.AbstractMonitoredVm
All Implemented Interfaces:
MonitoredVm, BufferedMonitoredVm
Direct Known Subclasses:
FileMonitoredVm, LocalMonitoredVm, RemoteMonitoredVm

public abstract class AbstractMonitoredVm
extends Object
implements BufferedMonitoredVm

Base class for all MonitoredVm implementations that utilize the HotSpot PerfData instrumentation buffer as the communications mechanism to the target Java Virtual Machine.

Since:
1.5

Field Summary
protected  int interval
          The sampling interval, if the instrumentation buffer is acquired by sampling instead of shared memory mechanisms.
protected  AbstractPerfDataBuffer pdb
          The shared memory instrumentation buffer for the target.
protected  VmIdentifier vmid
          The VmIdentifier for the target.
 
Constructor Summary
AbstractMonitoredVm(VmIdentifier vmid, int interval)
          Create an AbstractMonitoredVm instance.
 
Method Summary
abstract  void addVmListener(VmListener l)
          Add a VmListener.
 void clearLastException()
          Clear the last exception.
 void detach()
          Detach from target Java Virtual Machine.
 Monitor findByName(String name)
          Find a named Instrumentation object.
 List findByPattern(String patternString)
          Find all Instrumentation objects with names matching the given pattern.
 byte[] getBytes()
          Interface to get the bytes associated with the instrumentation for the target Java Virtual Machine.
 int getCapacity()
          Interface to get the the size of the instrumentation buffer for the target Java Virtual Machine.
 int getInterval()
          Get the polling interval.
 Exception getLastException()
          Get the last exception encountered while polling this MonitoredVm.
 MonitorStatus getMonitorStatus()
          Get a list of the inserted and removed monitors since last called.
 VmIdentifier getVmIdentifier()
          Get the VmIdentifier associated with this MonitoredVm
 boolean isErrored()
          Test if this MonitoredVm is in the errored state.
abstract  void removeVmListener(VmListener l)
          Remove a VmListener.
 void setInterval(int interval)
          Set the polling interval to interval milliseconds.
 void setLastException(Exception e)
          Set the last exception encountered while polling this MonitoredVm.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

vmid

protected VmIdentifier vmid
The VmIdentifier for the target.


pdb

protected AbstractPerfDataBuffer pdb
The shared memory instrumentation buffer for the target.


interval

protected int interval
The sampling interval, if the instrumentation buffer is acquired by sampling instead of shared memory mechanisms.

Constructor Detail

AbstractMonitoredVm

public AbstractMonitoredVm(VmIdentifier vmid,
                           int interval)
                    throws MonitorException
Create an AbstractMonitoredVm instance.

Parameters:
vmid - the VmIdentifier for the target
interval - the initial sampling interval
Throws:
MonitorException
Method Detail

getVmIdentifier

public VmIdentifier getVmIdentifier()
Get the VmIdentifier associated with this MonitoredVm

Specified by:
getVmIdentifier in interface MonitoredVm
Returns:
VmIdentifier - the fully resolved Vm identifier associated with this MonitoredVm.

findByName

public Monitor findByName(String name)
                   throws MonitorException
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 null.

Specified by:
findByName in interface MonitoredVm
Parameters:
name - the name of the Instrumentation object to find.
Returns:
Monitor - the Monitor object that can be used to monitor the the named instrumentation object, or null if the named object doesn't exist.
Throws:
MonitorException - Thrown if an error occurs while communicating with the target Java Virtual Machine.

findByPattern

public List findByPattern(String patternString)
                   throws MonitorException
Find all Instrumentation objects with names matching the given pattern. This method returns a List of Monitor objects such that the name of each object matches the given pattern.

Specified by:
findByPattern in interface MonitoredVm
Parameters:
patternString - a string containing a pattern as described in Pattern.
Returns:
List - a List of 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 Also:
Pattern

detach

public void detach()
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.

Specified by:
detach in interface MonitoredVm

setInterval

public void setInterval(int interval)
Set the polling interval to interval 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.

Specified by:
setInterval in interface MonitoredVm
Parameters:
interval - the polling interval in milliseconds

getInterval

public int getInterval()
Get the polling interval.

Specified by:
getInterval in interface MonitoredVm
Returns:
int - the current polling interval in milliseconds.
See Also:
MonitoredVm.setInterval(int)

setLastException

public void setLastException(Exception e)
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 errored state.

Specified by:
setLastException in interface MonitoredVm
Parameters:
e - the exception to record.
See Also:
MonitoredVm.isErrored()

getLastException

public Exception getLastException()
Get the last exception encountered while polling this MonitoredVm. Returns the last exception observed by the implementation dependent polling task or null if no such error has occurred.

Specified by:
getLastException in interface MonitoredVm
Returns:
Exception - the last exception that occurred during polling or null if no error condition exists.
See Also:
MonitoredVm.isErrored(), MonitoredVm.setLastException(java.lang.Exception)

clearLastException

public void clearLastException()
Clear the last exception. Calling this method will clear the errored state of this MonitoredVm. However, there is no guarantee that clearing the the errored state return the asynchronous polling task to an operational state.

Specified by:
clearLastException in interface MonitoredVm

isErrored

public boolean isErrored()
Test if this MonitoredVm is in the errored state. The errored state exists only if an error was reported with call to MonitoredVm.setLastException(java.lang.Exception) and only if the parameter to that call was non-null and no subsequent calls are made to MonitoredVm.clearLastException().

Specified by:
isErrored in interface MonitoredVm
Returns:
boolean - true if the instance has a non-null error condition set, false otherwise.
See Also:
MonitoredVm.setLastException(java.lang.Exception), MonitoredVm.getLastException()

getMonitorStatus

public MonitorStatus getMonitorStatus()
                               throws MonitorException
Get a list of the inserted and removed monitors since last called.

Returns:
MonitorStatus - the status of available Monitors for the target Java Virtual Machine.
Throws:
MonitorException - Thrown if communications errors occur while communicating with the target.

addVmListener

public abstract void addVmListener(VmListener l)
Add a VmListener. The given listener is added to the list of VmListener objects to be notified of MonitoredVm related events.

Specified by:
addVmListener in interface MonitoredVm
Parameters:
l - the VmListener to add.

removeVmListener

public abstract void removeVmListener(VmListener l)
Remove a VmListener. The given listener is removed from the list of VmListener objects to be notified of MonitoredVm related events.

Specified by:
removeVmListener in interface MonitoredVm
Parameters:
l - the VmListener to be removed.

getBytes

public byte[] getBytes()
Interface to get the bytes associated with the instrumentation for the target Java Virtual Machine.

Specified by:
getBytes in interface BufferedMonitoredVm
Returns:
byte[] - a byte array containing the current bytes for the instrumentation exported by the target Java Virtual Machine.

getCapacity

public int getCapacity()
Interface to get the the size of the instrumentation buffer for the target Java Virtual Machine.

Specified by:
getCapacity in interface BufferedMonitoredVm
Returns:
int - the size of the instrumentation buffer for the target Java Virtual Machine.

Jvmstat