View Javadoc

1   /*
2    * Copyright (c) 1998-2002 The Jgroup Team.
3    *
4    * This program is free software; you can redistribute it and/or modify
5    * it under the terms of the GNU Lesser General Public License version 2 as
6    * published by the Free Software Foundation.
7    *
8    * This program is distributed in the hope that it will be useful,
9    * but WITHOUT ANY WARRANTY; without even the implied warranty of
10   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11   * GNU Lesser General Public License for more details.
12   *
13   * You should have received a copy of the GNU Lesser General Public License
14   * along with this program; if not, write to the Free Software
15   * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
16   *
17   */
18  
19  package jgroup.test.performance;
20  
21  import java.io.FileOutputStream;
22  import java.io.PrintWriter;
23  
24  import jgroup.core.registry.DependableRegistry;
25  import jgroup.core.registry.RegistryFactory;
26  import jgroup.util.Network;
27  import jgroup.util.Util;
28  
29  /**
30   *  Test for measuring the performance of GMI invocations.
31   *  Can be executed remotely through the <t>Executor</t> class,
32   *  since it implements the <t>Server</t> interface.
33   *
34   *  @author       Alberto Montresor
35   *  @since        Jgroup 1.1
36   */
37  public class SpeedTestClient
38  {
39  
40    ////////////////////////////////////////////////////////////////////////////////////////////
41    // Main
42    ////////////////////////////////////////////////////////////////////////////////////////////
43  
44    public static void main(String[] argv)
45      throws Exception
46    {
47      SpeedTestClient client = new SpeedTestClient();
48      client.start();
49    }
50  
51    
52    ////////////////////////////////////////////////////////////////////////////////////////////
53    // Fields
54    ////////////////////////////////////////////////////////////////////////////////////////////
55  
56    /** True when the action requested is completed */
57    private boolean completed = false;
58  
59    
60    ////////////////////////////////////////////////////////////////////////////////////////////
61    // Constructor
62    ////////////////////////////////////////////////////////////////////////////////////////////
63  
64    public SpeedTestClient()
65    {
66    }
67  
68    ////////////////////////////////////////////////////////////////////////////////////////////
69    // Methods
70    ////////////////////////////////////////////////////////////////////////////////////////////
71  
72    public synchronized void start()
73      throws Exception
74    {
75      DependableRegistry reg = RegistryFactory.getRegistry();
76      SpeedTest test = (SpeedTest) reg.lookup("Jgroup/SpeedTest");
77  
78      // Open log file
79      PrintWriter out = null;
80      try {
81        StringBuilder buffer = new StringBuilder();
82        buffer.append("log-");
83        buffer.append(Network.getLocalHostName());
84        buffer.append("-");
85        buffer.append(Util.getDateTimeString());
86        buffer.append(".txt");
87        out = new PrintWriter(new FileOutputStream(buffer.toString()));
88      } catch (Exception e) {
89        e.printStackTrace();
90      }
91  
92      // Perform test
93  //    ClientTest.test1(test, out);
94  //    ClientTest.test2(test, out);
95  //    ClientTest.mtest1(test, out);
96      ClientTest.mtest2(test, out);
97      ClientTest.mtest3(test, out);
98      ClientTest.mtest4(test, out);
99  
100     completed = true;
101     notify();
102   }
103 
104   public synchronized void halt()
105     throws Exception
106   {
107     while (!completed)
108       try { wait(); } catch (Exception e) { }
109   }
110 
111 } // END SpeedTestClient