de.mcs.jmeasurement.example.TestApplication Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of JMeasurement Show documentation
Show all versions of JMeasurement Show documentation
JMeasurement profiling programs in production enviroment
/*
* MCS Media Computer Software Copyright (c) 2007 by MCS
* -------------------------------------- Created on 09.01.2007 by W.Klaas
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
/**
*
*/
package de.mcs.jmeasurement.example;
import java.io.File;
import java.io.IOException;
import java.util.Random;
import de.mcs.jmeasurement.JMConfig;
import de.mcs.jmeasurement.MeasureFactory;
import de.mcs.jmeasurement.Monitor;
import de.mcs.utils.Files;
/**
* This is a simple test application which does nothing really meaningful things. But it will generate new measure
* points all the time, use older ones and will add some time to the measuredata. The autonsnapshot system will be
* engaged so every minute you can see a new shnapshot report in the data directory. Configure this application with a
* jmconfig.properties file in the classpath.
*
* @author W.Klaas
*/
public class TestApplication {
/**
* @param args
*/
public static void main(String[] args) {
System.out.println("Test application for the JMeasurement API.");
System.out.println("------------------------------------------");
MeasureFactory.configure();
// MeasureFactory.configure(new File("e:\\temp\\jmconfig.properties"));
MeasureFactory.registerMBeans();
String workpath = MeasureFactory.getConfig().getProperty(JMConfig.OPTION_WORKINGPATH);
try {
File workPath = new File(workpath);
Files.remove(workPath, true);
workPath.mkdirs();
} catch (IOException e1) {
e1.printStackTrace();
}
Random random = new Random();
boolean running = true;
Monitor monitor = null;
while (running) {
try {
int monitorNumber = random.nextInt(100);
monitor = MeasureFactory.start("de.mcs.jmeasurement.example." + Integer.toString(monitorNumber));
System.out.println("starting monitor " + Integer.toString(monitorNumber));
int sleeping = random.nextInt(1000);
Thread.sleep(sleeping);
int noc = System.in.available();
running = noc == 0;
} catch (Exception e) {
running = false;
}
if (null != monitor) {
monitor.stop();
}
}
System.out.println(MeasureFactory.asString());
}
}