View Javadoc

1   /*
2    * Copyright 2001-2004 The Apache Software Foundation.
3    * 
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * 
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.jdiagnose.example;
17  
18  import java.net.UnknownHostException;
19  
20  import org.jdiagnose.library.JavaVersionDiagnostic;
21  import org.jdiagnose.remote.DefaultAgent;
22  import org.jdiagnose.remote.SendingResultListener;
23  import org.jdiagnose.remote.comms.HttpSender;
24  import org.jdiagnose.runtime.DefaultDiagnosticRunner;
25  import org.jdiagnose.runtime.DiagnosticRunner;
26  
27  /***
28   * Example class that sends remote results
29   * 
30   * @author jmccrindle
31   */
32  public class Main {
33  
34      /***
35       * @param args expects single URL argument, usually: http://host:port/jdiagnose/httplistener.htm
36       * @throws UnknownHostException if the application can't find out the current hostname
37       */
38      public static void main(String[] args) throws UnknownHostException {
39  
40          // create a new java version diagnostic
41          // to check that the java version if 1.3 or above
42          JavaVersionDiagnostic diagnostic = new JavaVersionDiagnostic("1.3+");
43          
44          // create a new runner to run the diagnostic
45          DiagnosticRunner runner = new DefaultDiagnosticRunner(diagnostic);
46          
47          // create a new agent and initialise it
48          // the agent provides information about the current host and agent
49          DefaultAgent agent = new DefaultAgent("jdiagnose");
50          agent.init();
51          
52          // create sender with a url supplied on the command line
53          HttpSender httpSender = new HttpSender(args[0]);
54          
55          // add the httpSender and agent into the runner as listeners
56          runner.addResultListener(new SendingResultListener(httpSender, agent));
57          
58          // run the diagnostic
59          runner.run();
60  
61      }
62  }