Method from org.apache.geronimo.monitoring.jmx.MasterRemoteControlJMX Detail: |
public Integer SnapshotStatus() {
// TODO: check if the snapshot thread is running
if(snapshotThread == null) {
return 0;
} else {
return snapshotThread.SnapshotStatus();
}
}
|
public boolean addMBeanForSnapshot(String mbeanName) {
return SnapshotConfigXMLBuilder.addMBeanName(mbeanName);
}
Adds a record of the mbean via its name to take snapshots of. As a result
the mbeanName will be written to snapshot-config.xml |
public void doFail() {
doStop();
}
|
public void doStart() {
}
Executes when the GBean starts up. Also starts the snapshot thread. |
public void doStop() {
if(SnapshotStatus() == 1) {
stopSnapshot();
}
}
Executes when the GBean stops. Also stops the snapshot thread. |
public HashMap<String, Long> fetchMaxSnapshotData(Integer numberOfSnapshot) {
return snapshotDBHelper.fetchMaxSnapshotData(numberOfSnapshot);
}
Fetches the max amount for each statistic stored from the snapshot thread
and returns it in a HashMap |
public HashMap<String, Long> fetchMinSnapshotData(Integer numberOfSnapshot) {
return snapshotDBHelper.fetchMinSnapshotData(numberOfSnapshot);
}
Fetches the min amount for each statistic stored from the snapshot thread
and returns it in a HashMap |
public ArrayList<String, Object> fetchSnapshotData(Integer numberOfSnapshot,
Integer everyNthSnapshot) {
return snapshotDBHelper.fetchData(numberOfSnapshot, everyNthSnapshot);
}
Fetches the data stored from the snapshot thread and returns
it in a ArrayList with each element being a HashMap of the attribute
mapping to the statistic. All stats will be the average of
1 - n, n+1 - 2n, ..., cn+1 - c(n+1)
Grabs 'numberOfSnapshots' snapshots. Grabs one snapshot per
'everyNthsnapshot' |
public Set<String> getAllMBeanNames() {
try {
Set< ObjectName > names = (Set< ObjectName >)mbServer.queryNames(null, null);
Set< String > strNames = new HashSet< String >();
for(Iterator< ObjectName > it = names.iterator(); it.hasNext(); ) {
strNames.add(it.next().getCanonicalName());
}
return strNames;
} catch(Exception e) {
log.error(e.getMessage(), e);
return new HashSet< String >();
}
}
|
public HashMap<String> getAllSnapshotStatAttributes() {
HashMap< String, ArrayList< String > > snapshotAttributes = new HashMap< String, ArrayList< String > >();
Set< String > mbeans = getTrackedMBeans();
// for each mbean name
for(Iterator< String > it = mbeans.iterator(); it.hasNext(); ) {
ArrayList< String > mbeanStatsList = new ArrayList< String >();
String mbeanName = it.next();
try {
Stats stats = (Stats)mbServer.getAttribute(new ObjectName(mbeanName), "stats");
String[] sttsName = stats.getStatisticNames();
Statistic[] stts = stats.getStatistics();
for(int i = 0; i < sttsName.length; i++) {
Statistic aStat = stats.getStatistic(sttsName[i]);
if(aStat instanceof RangeStatistic) {
mbeanStatsList.add(stts[i].getName() + " Current");
mbeanStatsList.add(stts[i].getName() + " Max");
mbeanStatsList.add(stts[i].getName() + " Min");
} else if(aStat instanceof CountStatistic) {
mbeanStatsList.add(stts[i].getName());
} else if(aStat instanceof TimeStatistic) {
mbeanStatsList.add(stts[i].getName() + " CurrentTime");
mbeanStatsList.add(stts[i].getName() + " MaxTime");
mbeanStatsList.add(stts[i].getName() + " MinTime");
mbeanStatsList.add(stts[i].getName() + " TotalTime");
} else {
// for the time being, only numbers should be returned
}
}
} catch (Exception e) {
log.error(e.getMessage(), e);
}
// save attributes to the returning list
snapshotAttributes.put(mbeanName, mbeanStatsList);
}
return snapshotAttributes;
}
|
public static GBeanInfo getGBeanInfo() {
return GBEAN_INFO;
}
|
public Long getSnapshotCount() {
return snapshotDBHelper.getSnapshotCount();
}
|
public Long getSnapshotDuration() {
try {
return Long.parseLong(SnapshotConfigXMLBuilder.getAttributeValue( MonitorConstants.DURATION ));
} catch(Exception e) {
return new Long( MonitorConstants.DEFAULT_DURATION );
}
}
Gets the elapsed time in milliseconds between each snapshot. |
public Integer getSnapshotRetention() {
try {
return new Integer(SnapshotConfigXMLBuilder.getAttributeValue( MonitorConstants.RETENTION ));
} catch(Exception e) {
return new Integer(MonitorConstants.DEFAULT_RETENTION); // the default
}
}
|
public TreeMap<Long, Long> getSpecificStatistics(String mbeanName,
String statsName,
Integer numberOfSnapshots,
Integer everyNthSnapshot,
Boolean showArchived) {
return snapshotDBHelper.getSpecificStatistics(mbeanName, statsName, numberOfSnapshots.intValue(), everyNthSnapshot.intValue(), showArchived);
}
|
public Set<String> getStatisticsProviderMBeanNames() {
return (Set< String >)MBeanHelper.getStatsProvidersMBeans( getAllMBeanNames() );
}
Fetches all mbean names that provide JSR-77 statistics |
public static HashMap getStats(String objectName) throws Exception {
HashMap statsMap = new HashMap();
Stats stats = (Stats)mbServer.getAttribute(new ObjectName(objectName), "stats");
String[] sttsName = stats.getStatisticNames();
Statistic[] stts = stats.getStatistics();
for(int i = 0; i < sttsName.length; i++) {
Statistic aStat = stats.getStatistic(sttsName[i]);
if(aStat instanceof RangeStatistic) {
Long current = new Long(((RangeStatistic)aStat).getCurrent());
Long high = new Long(((RangeStatistic)aStat).getHighWaterMark());
Long low = new Long(((RangeStatistic)aStat).getLowWaterMark());
statsMap.put(stts[i].getName() + " Current", current);
statsMap.put(stts[i].getName() + " Max", high);
statsMap.put(stts[i].getName() + " Min", low);
} else if(aStat instanceof CountStatistic) {
Long current = new Long(((CountStatistic)aStat).getCount());
statsMap.put(stts[i].getName(), current);
} else if(aStat instanceof TimeStatistic) {
Long current = new Long(((TimeStatistic)aStat).getCount());
Long max = new Long(((TimeStatistic)aStat).getMaxTime());
Long min = new Long(((TimeStatistic)aStat).getMinTime());
Long total = new Long(((TimeStatistic)aStat).getTotalTime());
statsMap.put(stts[i].getName() + " CurrentTime", current);
statsMap.put(stts[i].getName() + " MaxTime", max);
statsMap.put(stts[i].getName() + " MinTime", min);
statsMap.put(stts[i].getName() + " TotalTime", total);
} else {
// this should never happen
throw new Exception();
}
}
return statsMap;
}
Looks up the JSR-77 statistics associated with this object name. |
public Set<String> getTrackedMBeans() {
ArrayList< String > mbeans = (ArrayList< String >)SnapshotConfigXMLBuilder.getMBeanNames();
Set< String > set = new HashSet< String >();
for(int i = 0; i < mbeans.size(); i++) {
set.add(mbeans.get(i));
}
return set;
}
|
public Object invoke(ObjectName name,
String operationName,
Object[] params,
String[] signature) throws Exception {
return mbServer.invoke(name, operationName, params, signature);
}
|
public boolean removeMBeanForSnapshot(String mbeanName) {
return SnapshotConfigXMLBuilder.removeMBeanName(mbeanName);
}
Removes a record of the mbean via its name to take snapshots of. As a result
the mbeanName will be removed from snapshot-config.xml |
public void setAttribute(String objectName,
String attrName,
Object attrValue) throws Exception {
Attribute attr = new Attribute(attrName, attrValue);
mbServer.setAttribute(new ObjectName(objectName), attr);
}
Changes the objectName's attrName's value to attrValue |
public void setSnapshotDuration(Long snapshotDuration) {
if(snapshotThread != null) {
snapshotThread.setSnapshotDuration(snapshotDuration.longValue());
saveDuration(snapshotThread.getSnapshotDuration());
} else {
log.warn("There is not a snapshot thread instantiated.");
}
}
Sets the elapsed time in milliseconds between each snapshot. |
public void setSnapshotRetention(Integer retention) {
saveRetention(retention.intValue());
}
|
public boolean startSnapshot(Long interval) {
// get the saved/default retention period
String retentionStr = null;
try {
retentionStr = SnapshotConfigXMLBuilder.getAttributeValue( MonitorConstants.RETENTION );
} catch(Exception e){
// happens when there is not an instance of "retention" in the config
// which is okay.
}
int retention;
if(retentionStr == null) {
retention = MonitorConstants.DEFAULT_RETENTION;
} else {
retention = Integer.parseInt(retentionStr);
}
return startSnapshot(interval, new Integer(retention));
}
Begins the snapshot process given the time interval between snapshots
Precondition:
interval is given in milli seconds |
public boolean startSnapshot(Long interval,
Integer retention) {
if((snapshotThread == null || (snapshotThread != null && (snapshotThread.SnapshotStatus() == 0))) && interval.longValue() > 0) {
saveDuration(interval.longValue());
saveRetention(retention.intValue());
snapshotThread = new SnapshotThread(interval.longValue(), mbServer);
snapshotThread.start();
log.info("Snapshot thread successfully created.");
return true;
} else {
log.warn("There is already a snapshot thread running.");
return false;
}
}
Begins the snapshot process given the time interval between snapshots
Precondition:
interval is given in milli seconds |
public boolean stopSnapshot() {
if(snapshotThread != null) {
if(snapshotThread.getSnapshotDuration() != Long.MAX_VALUE) {
saveDuration(snapshotThread.getSnapshotDuration());
snapshotThread.setSnapshotDuration(Long.MAX_VALUE);
log.info("Snapshot thread stopped.");
return true;
} else {
return false;
}
} else {
log.error("There is not a snapshot thread running. Stopping aborted.");
return false;
}
}
Stops the snapshot thread |