01: /*
02: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
03: */
04: package com.tcsimulator;
05:
06: import com.tc.process.LinkedJavaProcess;
07: import com.tcsimulator.distrunner.ServerSpec;
08:
09: import java.io.File;
10: import java.util.Collection;
11: import java.util.HashSet;
12:
13: public final class ProcessFactory {
14:
15: private final Sandbox sandbox;
16: private final ServerSpec serverSpec;
17:
18: public ProcessFactory(Sandbox sandbox, ServerSpec serverSpec) {
19: this .sandbox = sandbox;
20: this .serverSpec = serverSpec;
21: }
22:
23: public LinkedJavaProcess newDSOJavaProcessInstance(
24: String className, String[] args, boolean debug) {
25: String[] argsToPass = args;
26: if (argsToPass == null) {
27: argsToPass = new String[] {};
28: }
29: LinkedJavaProcess newProcess = new LinkedJavaProcess(className,
30: argsToPass);
31: String fileSeparator = System.getProperty("file.separator");
32: File terracottaDist = new File(sandbox.getTestHome()
33: .getAbsoluteFile(), sandbox.getDistributionName());
34: File dsoJava = new File(terracottaDist.getAbsolutePath()
35: + fileSeparator + "bin" + fileSeparator + "dso-java.sh");
36:
37: Collection jvmArgs = new HashSet();
38: jvmArgs.add("-Dtc.config=" + serverSpec.getHostName() + ":"
39: + serverSpec.getDsoPort());
40: //jvmArgs.add("-Dtc.classloader.writeToDisk=true");
41: if (debug) {
42: jvmArgs.add("-Xdebug");
43: jvmArgs
44: .add("-Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=y");
45: }
46: Collection environment = new HashSet();
47: if ("Mac OS X".equals(System.getProperty("os.name"))
48: || "Linux".equals(System.getProperty("os.name"))) {
49: environment.add("TC_JAVA_HOME="
50: + System.getProperty("java.home"));
51: }
52: newProcess.setJavaExecutable(dsoJava);
53: File dir = new File(sandbox.getServerHome(), className);
54: dir.mkdir();
55: newProcess.setDirectory(dir);
56: newProcess.setJavaArguments((String[]) jvmArgs
57: .toArray(new String[jvmArgs.size()]));
58: newProcess.setEnvironment((String[]) environment
59: .toArray(new String[environment.size()]));
60:
61: return newProcess;
62: }
63:
64: public LinkedJavaProcess newJavaProcessInstance(String className,
65: String[] args, boolean debug, String javaHome) {
66: String[] argsToPass = args;
67: if (argsToPass == null) {
68: argsToPass = new String[] {};
69: }
70: LinkedJavaProcess newProcess = new LinkedJavaProcess(className,
71: argsToPass);
72: File java = new File(javaHome);
73:
74: Collection jvmArgs = new HashSet();
75: if (debug) {
76: jvmArgs.add("-Xdebug");
77: jvmArgs
78: .add("-Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=y");
79: }
80:
81: newProcess.setJavaExecutable(java);
82: newProcess.setJavaArguments((String[]) jvmArgs
83: .toArray(new String[jvmArgs.size()]));
84:
85: return newProcess;
86: }
87:
88: }
|