1 22 package org.jboss.test.util.server; 23 24 import java.io.File ; 25 import java.io.IOException ; 26 import java.util.ArrayList ; 27 import java.util.Iterator ; 28 import java.util.List ; 29 30 31 37 public class ServerManager 38 { 39 42 private static final int WAIT_TIME = 45; 43 private static final int START_TIME = 120; 44 45 46 private String jbossHome; 47 48 49 private String jvm = "java"; 50 51 52 private String javaHome; 53 54 private String udpGroup; 55 56 57 private List <Server> servers = new ArrayList <Server>(); 58 59 63 public ServerManager() 64 { 65 Thread cleanupThread = new Thread () 66 { 67 public void run() 68 { 69 for (Iterator iter = servers.iterator(); iter.hasNext();) 70 { 71 Server server = (Server) iter.next(); 72 if (server.isRunning()) 73 { 74 System.err.println("Found server \""+server.getName()+"\" still running; stopping it."); 75 try 76 { 77 ServerController.stopServer(server, ServerManager.this); 78 } 79 catch (IOException e) 80 { 81 System.err.println("Failed to stop server(s) on shutdown."); 82 e.printStackTrace(System.err); 83 } 84 } 85 } 86 } 87 }; 88 89 Runtime.getRuntime().addShutdownHook(cleanupThread); 90 91 } 92 93 98 public void addServer(Server newServer) 99 { 100 newServer.setManager(this); 101 servers.add(newServer); 102 } 103 104 111 public Server getServer(String name) 112 { 113 for (Iterator iter = servers.iterator(); iter.hasNext();) 114 { 115 Server server = (Server) iter.next(); 116 if (server.getName().equals(name)) 117 { 118 return server; 119 } 120 } 121 throw new IllegalArgumentException ("There is no server named: " + name); 122 } 123 124 130 public void startServer(String serverName) throws IOException 131 { 132 ServerController.startServer(getServer(serverName), this); 133 } 134 135 141 public void stopServer(String name) throws IOException 142 { 143 ServerController.stopServer(getServer(name), this); 144 } 145 146 152 public String getJavaExecutable() throws IOException 153 { 154 return new File (javaHome + File.separator + "bin",jvm).getCanonicalPath(); 155 } 156 157 162 public void setJvm(String jvm) 163 { 164 this.jvm = jvm; 165 } 166 167 172 public void setJavaHome(String javaHome) 173 { 174 this.javaHome = javaHome; 175 } 176 177 180 public void setJbossHome(String jbossHome) 181 { 182 this.jbossHome = jbossHome; 183 } 184 185 190 protected String getStartClasspath() 191 { 192 File runjar = new File (jbossHome + "/bin/run.jar"); 193 File javaJar = new File (javaHome + "/lib/tools.jar"); 194 return runjar.toString() + File.pathSeparator + javaJar.toString(); 195 } 196 197 202 protected String getStopClasspath() 203 { 204 File shutdownJar = new File (jbossHome + "/bin/shutdown.jar"); 205 File clientJar = new File (jbossHome + "/client/jbossall-client.jar"); 206 File logJar = new File (jbossHome + "/client/jboss-common.jar"); 207 return shutdownJar.toString() + File.pathSeparator + clientJar.toString()+ File.pathSeparator 208 + logJar.toString(); 209 } 210 211 216 public String getJBossHome() 217 { 218 return jbossHome; 219 } 220 221 226 public int getShutdownTimeout() 227 { 228 return WAIT_TIME; 229 } 230 231 236 public int getStartupTimeout() 237 { 238 return START_TIME; 239 } 240 241 246 protected String getUdpGroup() 247 { 248 return udpGroup; 249 } 250 251 256 public void setUdpGroup(String udpGroup) 257 { 258 this.udpGroup = udpGroup; 259 } 260 261 } | Popular Tags |