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 jgroup.core.registry.DependableRegistry;
22  import jgroup.core.registry.RegistryFactory;
23  
24  /**
25   *  Client used to shutdown a server remotely.
26   *
27   *  @author Hein Meling
28   *  @since Jgroup 2.1
29   */
30  public class ShutdownClient
31  {
32  
33    ////////////////////////////////////////////////////////////////////////////////////////////
34    // Constants
35    ////////////////////////////////////////////////////////////////////////////////////////////
36  
37    /**
38     *  Set of servers supported for running tests through
39     *  the <code>SpeedTest</code> interface.
40     */
41    private static final String[] supportedServers = new String[] {
42      "Jgroup/PerformanceServer",
43      "ARM/ReplicatedServer",
44      "Jgroup/SpeedTest"
45    };
46  
47  
48    ////////////////////////////////////////////////////////////////////////////////////////////
49    // Main
50    ////////////////////////////////////////////////////////////////////////////////////////////
51  
52    public static void main(String[] argv)
53      throws Exception
54    {
55      DependableRegistry reg = RegistryFactory.getRegistry();
56      String[] servers = reg.list();
57      RemoteShutdown srv = null;
58      for (int i = 0; srv == null && i < servers.length; i++) {
59        for (int j = 0; srv == null && j < supportedServers.length; j++) {
60          if (servers[i].equals(supportedServers[j])) {
61            srv = (RemoteShutdown) reg.lookup(servers[i]);
62            System.out.println("Found supported server: " + servers[i]);
63          }
64        }
65      }
66      if (srv == null) {
67        System.out.println("No supported servers found");
68        System.exit(0);
69      }
70      // Send multicast prepare shutdown to all servers
71      srv.preShutdown();
72      // Do shutdown on an arbitrary server
73      srv.shutdown(0);
74    }
75  
76  } // END ShutdownClient