In charge of dealing with the XML processing of the snapshot's data.
Method from org.apache.geronimo.monitoring.snapshot.SnapshotConfigXMLBuilder Detail: |
public static boolean addMBeanName(String mbeanName) {
// check to see if the mbean name already exists
ArrayList< String > mbeanNames = getMBeanNames();
for(int i = 0 ; i < (int)mbeanNames.size(); i++) {
if(mbeanNames.get(i).equals(mbeanName)) {
return false; // nothing needs to be done if it is already there
}
}
// insert the mbean name into the SnapshotConfig object
SnapshotConfig sc = getSnapshotConfig();
sc.getMbeans().getMbean().add(mbeanName);
// write the object to XML
saveDocument(sc);
return true;
}
Adds to the snapshot-config.xml another configuration element
in order to persistently keep track of all user requested statistics.
If there is a duplicate, nothing will be done. |
public static boolean checkXMLExists() {
ensureMonitorDir();
File docFile = new File(pathToXML);
return docFile.exists();
}
Ensures that there is an existing XML file. Creates one if there
does not exist one already. |
public static void ensureMonitorDir() {
final String pathToDir =
System.getProperty("org.apache.geronimo.home.dir") + "/var/monitoring/";
File dir = new File(pathToDir);
if(dir.exists() && dir.isDirectory()) {
// all good
return;
} else {
// make a directory
if(dir.mkdir()) {
// directory was successfully created
log.info("/var/monitoring directory created.");
return;
} else {
log.error("Could not make the directory " + pathToDir);
}
}
}
Checks to see if the GERONIMO_HOME/var/monitoring/ directory was made.
If not, the method creates it. |
public static String getAttributeValue(String key) throws Exception {
if(key.equals( MonitorConstants.DURATION )) {
return getSnapshotConfig().getDuration();
} else if(key.equals( MonitorConstants.RETENTION )) {
return getSnapshotConfig().getRetention();
} else {
// Houston, we have a problem
throw new Exception("[WARNING] Attribute: " + key + " is not valid.");
}
}
Returns the value of the configuration attribute, defined by the key |
public static ArrayList<String> getMBeanNames() {
if(getSnapshotConfig().getMbeans() == null) {
return new ArrayList< String >();
} else {
return (ArrayList< String >)getSnapshotConfig().getMbeans().getMbean();
}
}
|
public static boolean removeMBeanName(String mbeanName) {
ArrayList< String > mbeanNames = getMBeanNames();
for(int i = 0 ; i < (int)mbeanNames.size(); i++) {
if(mbeanNames.get(i).equals(mbeanName)) {
// remove the mbean name by directly accessing it, because it is by reference
SnapshotConfig sc = getSnapshotConfig();
sc.getMbeans().getMbean().remove(i);
// save the current state of the SnapshotConfig object
saveDocument( sc );
return true;
}
}
return false;
}
Removes from the snapshot-config.xml a configuration element
in order to persistently keep track of all user requested statistics.
If there does not exist an instance of the mbeanNAme, nothing will be done. |
public static void saveDocument(SnapshotConfig sc) {
try {
Marshaller m = jc.createMarshaller();
m.marshal(sc, new FileOutputStream( pathToXML ));
} catch(Exception e) {
log.error(e.getMessage());
}
}
|
public static void saveDuration(long duration) {
SnapshotConfig sc = getSnapshotConfig();
sc.setDuration("" + duration);
saveDocument(sc);
}
Saves the duration of the snapshot as a configuration attribute |
public static void saveRetention(int retention) {
SnapshotConfig sc = getSnapshotConfig();
sc.setRetention("" + retention);
saveDocument(sc);
}
Saves the retention of the snapshot as a configuration attribute |