001: /*
002: * MCS Media Computer Software Copyright (c) 2007 by MCS
003: * -------------------------------------- Created on 09.01.2007 by W.Klaas
004: *
005: * Licensed under the Apache License, Version 2.0 (the "License"); you may not
006: * use this file except in compliance with the License. You may obtain a copy of
007: * the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
013: * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
014: * License for the specific language governing permissions and limitations under
015: * the License.
016: */
017: /**
018: *
019: */package de.mcs.jmeasurement.example;
020:
021: import java.io.File;
022: import java.io.IOException;
023: import java.util.Random;
024:
025: import javax.management.InstanceAlreadyExistsException;
026: import javax.management.MBeanRegistrationException;
027: import javax.management.NotCompliantMBeanException;
028:
029: import de.mcs.jmeasurement.JMConfig;
030: import de.mcs.jmeasurement.MeasureFactory;
031: import de.mcs.jmeasurement.Monitor;
032: import de.mcs.utils.Files;
033:
034: /**
035: * This is a simple test application which does nothing really meaningful
036: * things. But it will generate new measure points all the time, use older ones
037: * and will add some time to the measuredata. The autonsnapshot system will be
038: * engaged so every minute you can see a new shnapshot report in the data
039: * directory. Configure this application with a jmconfig.properties file in the
040: * classpath.
041: *
042: * @author W.Klaas
043: *
044: */
045: public class TestApplication {
046:
047: /**
048: * @param args
049: */
050: public static void main(String[] args) {
051: System.out
052: .println("Test application for the JMeasurement API.");
053: System.out
054: .println("------------------------------------------");
055: MeasureFactory.configure();
056: // MeasureFactory.configure(new File("e:\\temp\\jmconfig.properties"));
057: try {
058: MeasureFactory.registerMBeans();
059: } catch (InstanceAlreadyExistsException e2) {
060: // TODO Auto-generated catch block
061: e2.printStackTrace();
062: } catch (MBeanRegistrationException e2) {
063: // TODO Auto-generated catch block
064: e2.printStackTrace();
065: } catch (NotCompliantMBeanException e2) {
066: // TODO Auto-generated catch block
067: e2.printStackTrace();
068: } catch (NullPointerException e2) {
069: // TODO Auto-generated catch block
070: e2.printStackTrace();
071: }
072: String workpath = MeasureFactory.getConfig().getProperty(
073: JMConfig.OPTION_WORKINGPATH);
074: try {
075: Files.remove(workpath, true);
076: new File(workpath).mkdirs();
077: } catch (IOException e1) {
078: // TODO Auto-generated catch block
079: e1.printStackTrace();
080: }
081: Random random = new Random();
082: boolean running = true;
083: Monitor monitor = null;
084: while (running) {
085: try {
086: int monitorNumber = random.nextInt(100);
087: monitor = MeasureFactory
088: .start("de.mcs.jmeasurement.example."
089: + Integer.toString(monitorNumber));
090: System.out.println("starting monitor "
091: + Integer.toString(monitorNumber));
092: int sleeping = random.nextInt(1000);
093: Thread.sleep(sleeping);
094: int noc = System.in.available();
095: running = noc == 0;
096: } catch (Exception e) {
097: // TODO Auto-generated catch block
098: running = false;
099: }
100: if (null != monitor) {
101: monitor.stop();
102: }
103: }
104: System.out.println(MeasureFactory.asString());
105: }
106:
107: }
|