1 22 package org.jboss.test.util.server; 23 24 import java.io.File ; 25 import java.io.PrintWriter ; 26 import java.net.MalformedURLException ; 27 import java.net.URL ; 28 import java.util.ArrayList ; 29 import java.util.Iterator ; 30 import java.util.List ; 31 32 38 public class Server 39 { 40 41 private String name; 42 43 44 private String config; 45 46 47 private List <Argument> arguments = new ArrayList <Argument>(); 48 49 50 private Process process; 51 52 53 private List <Argument> jvmArguments = new ArrayList <Argument>(); 54 55 56 private List <Property> sysProperties = new ArrayList <Property>(); 57 58 59 private Integer httpPort = new Integer (8080); 60 61 62 private Integer rmiPort = new Integer (1099); 63 64 65 private String host = "localhost"; 66 67 68 private ServerManager manager; 69 70 71 private PrintWriter outWriter; 72 73 74 private PrintWriter errorWriter; 75 76 77 private boolean hasWebServer = true; 78 79 84 public String getName() 85 { 86 return name; 87 } 88 89 94 public void setName(String name) 95 { 96 this.name = name; 97 } 98 99 103 protected void setManager(ServerManager manager) 104 { 105 this.manager = manager; 106 } 107 108 113 public void addArg(Argument arg) 114 { 115 arguments.add(arg); 116 } 117 118 123 public String getArgs() 124 { 125 StringBuffer args = new StringBuffer (); 126 for (Iterator iter = arguments.iterator(); iter.hasNext();) 127 { 128 Argument argument = (Argument) iter.next(); 129 args.append(argument.getValue() + " "); 130 } 131 return args.toString(); 132 } 133 134 139 public void addJvmArg(Argument arg) 140 { 141 jvmArguments.add(arg); 142 } 143 144 149 public String getJvmArgs() 150 { 151 StringBuffer args = new StringBuffer (); 152 for (Iterator iter = jvmArguments.iterator(); iter.hasNext();) 153 { 154 Argument argument = (Argument) iter.next(); 155 args.append(argument.getValue() + " "); 156 } 157 return args.toString(); 158 } 159 160 165 public void addSysProperty(Property property) 166 { 167 sysProperties.add(property); 168 } 169 170 175 public String getSysProperties() 176 { 177 StringBuffer args = new StringBuffer (); 178 for (Iterator iter = sysProperties.iterator(); iter.hasNext();) 179 { 180 Property property = (Property) iter.next(); 181 args.append("-D" + property.getKey() + "=" + property.getValue() + " "); 182 } 183 return args.toString(); 184 } 185 186 190 public void setProcess(Process process) 191 { 192 this.process = process; 193 } 194 195 200 public boolean isRunning() 201 { 202 if (isStopped()) 203 { 204 return false; 205 } 206 else 207 { 208 try 209 { 210 process.exitValue(); 212 return false; 213 } 214 catch (IllegalThreadStateException e) 215 { 216 return true; 217 } 218 } 219 } 220 221 226 public boolean isStopped() 227 { 228 return process == null; 229 } 230 231 236 public Process getProcess() 237 { 238 return process; 239 } 240 241 247 public URL getHttpUrl() throws MalformedURLException 248 { 249 return new URL ("http://" + host + ":" + httpPort); 250 } 251 252 257 public String getRmiUrl() 258 { 259 return "jnp://" + host + ":" + rmiPort; 260 } 261 262 267 public String getConfig() 268 { 269 if (config != null) 270 { 271 return config; 272 } 273 else 274 { 275 return name; 276 } 277 } 278 279 284 public void setConfig(String config) 285 { 286 this.config = config; 287 } 288 289 294 public String getHost() 295 { 296 return host; 297 } 298 299 304 public void setHost(String host) 305 { 306 this.host = host; 307 } 308 309 314 public void setHttpPort(Integer httpPort) 315 { 316 this.httpPort = httpPort; 317 } 318 319 324 public void setRmiPort(Integer rmiPort) 325 { 326 this.rmiPort = rmiPort; 327 } 328 329 334 public Integer getRmiPort() 335 { 336 return rmiPort; 337 } 338 343 public File getErrorLog() 344 { 345 return new File (getLogDir(), "error.log"); 346 } 347 348 353 public File getOutputLog() 354 { 355 return new File (getLogDir(), "output.log"); 356 } 357 358 363 private File getLogDir() 364 { 365 return new File (getConfDir(), "log"); 366 } 367 368 373 private File getConfDir() 374 { 375 return new File (manager.getJBossHome(), "server/" + getConfig()); 376 } 377 378 383 public void setOutWriter(PrintWriter outlog) 384 { 385 outWriter = outlog; 386 } 387 388 393 public PrintWriter getOutWriter() 394 { 395 return outWriter; 396 } 397 398 403 public PrintWriter getErrorWriter() 404 { 405 return errorWriter; 406 } 407 408 412 public void setErrorWriter(PrintWriter errorlog) 413 { 414 errorWriter = errorlog; 415 } 416 417 422 public boolean hasWebServer() 423 { 424 return hasWebServer; 425 } 426 431 public void setHasWebServer(boolean hasWebServer) 432 { 433 this.hasWebServer = hasWebServer; 434 } 435 436 } | Popular Tags |