KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tc > test > server > dsoserver > StandardDsoServer


1 /*
2  * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright
3  * notice. All rights reserved.
4  */

5 package com.tc.test.server.dsoserver;
6
7 import com.tc.config.Directories;
8 import com.tc.objectserver.control.ExtraProcessServerControl;
9 import com.tc.test.server.ServerParameters;
10 import com.tc.test.server.ServerResult;
11
12 import java.util.ArrayList JavaDoc;
13 import java.util.List JavaDoc;
14
15 /**
16  * Delegates to {@link ExtraProcessServerControl}
17  */

18 public final class StandardDsoServer implements DsoServer {
19
20   private ExtraProcessServerControl dsoServer;
21   private static final String JavaDoc domain = "127.0.0.1";
22   private static final List JavaDoc jvmArgs = new ArrayList JavaDoc();
23
24   public ServerResult start(ServerParameters rawParams) throws Exception JavaDoc {
25     DsoServerParameters params = (DsoServerParameters) rawParams;
26     jvmArgs.add("-Xmx128m");
27     jvmArgs.add("-verbose:gc");
28     // jvmArgs.add("-Dtc.classloader.writeToDisk=true");
29

30     dsoServer = new ExtraProcessServerControl(new ExtraProcessServerControl.DebugParams(), domain, params.dsoPort(),
31                                               params.jmxPort(), params.configFile().toString(), params.workingDir(),
32                                               Directories.getInstallationRoot(), false, jvmArgs, "");
33     dsoServer.writeOutputTo(params.outputFile());
34     dsoServer.start(2 * 60 * 1000);
35
36     return new DsoServerResult(params.dsoPort(), this);
37   }
38
39   public void stop() throws Exception JavaDoc {
40     if (dsoServer != null) {
41       dsoServer.shutdown();
42       dsoServer.waitFor();
43     } else {
44       System.err.println("**** DSO server was not started so ignoring request to stop the server. ****");
45     }
46   }
47
48   public void addJvmArgs(final List JavaDoc args) {
49     if (dsoServer != null && dsoServer.isRunning()) { throw new AssertionError JavaDoc(
50                                                                                "Attempting to add jvm args after DSO server has been started."); }
51     if (args != null && !args.isEmpty()) {
52       jvmArgs.addAll(args);
53     }
54   }
55
56   public boolean isRunning() {
57     if (dsoServer == null || !dsoServer.isRunning()) { return false; }
58     return true;
59   }
60 }
61
Popular Tags