View Javadoc

1   /*
2    * Copyright (c) 1998-2004 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.experiment.runnables;
20  
21  import java.util.Iterator;
22  
23  import jgroup.core.ConfigurationException;
24  import jgroup.experiment.PropertyDefinition;
25  import jgroup.experiment.Runnable;
26  import jgroup.experiment.ShellCommand;
27  import jgroup.relacs.config.ExperimentConfig;
28  import jgroup.relacs.config.Host;
29  import jgroup.relacs.config.HostSet;
30  
31  /**
32   * @author Bjarte Svaeren
33   */
34  public class CheckHosts implements Runnable 
35  {
36    /* (non-Javadoc)
37     * @see jgroup.experiment.Runnable#run(jgroup.relacs.config.ExperimentConfig)
38     */
39    public void run(ExperimentConfig ec) throws ConfigurationException 
40    {
41      // get the server hosts
42      HostSet hosts = (HostSet) ec.getServerConfig().getAllHosts().clone();
43      // get the client hosts
44      HostSet clients = ec.getClientConfig().getAllHosts();
45      hosts.addHosts(clients);
46      String userName  = ec.getProperty("user.name");
47  
48      ThreadGroup threadGroup = new ThreadGroup("CheckHosts");
49      for (Iterator iter = hosts.iterator(); iter.hasNext();) {
50        Host host = (Host) iter.next();
51        String hostName = host.getCanonicalHostName();
52        try {
53          ShellCommand.exec(ec.ssh(hostName) + " pgrep -fu " + userName + " java", threadGroup);
54        } catch (Exception e) {
55          e.printStackTrace();
56          System.out.println("Check for java process failed at " + hostName);
57        }
58      }
59      ShellCommand.waitFor(threadGroup);      
60    }
61  
62    /* (non-Javadoc)
63     * @see jgroup.experiment.Runnable#getProperties()
64     */
65    public PropertyDefinition[] getProperties() {
66      return null;
67    }
68  
69  } // END CheckHosts