01: /*
02: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright
03: * notice. All rights reserved.
04: */
05: package com.tc.test.server.appserver.jboss4x;
06:
07: import org.apache.tools.ant.taskdefs.Java;
08: import org.codehaus.cargo.container.InstalledLocalContainer;
09: import org.codehaus.cargo.container.configuration.LocalConfiguration;
10: import org.codehaus.cargo.container.jboss.JBoss4xInstalledLocalContainer;
11: import org.codehaus.cargo.container.property.GeneralPropertySet;
12:
13: import com.tc.test.server.appserver.cargo.CargoAppServer;
14: import com.tc.test.server.util.AppServerUtil;
15: import com.tc.util.PortChooser;
16: import com.tc.util.ReplaceLine;
17:
18: import java.io.File;
19: import java.io.IOException;
20:
21: /**
22: * JBoss4x AppServer implementation
23: */
24: public final class JBoss4xAppServer extends CargoAppServer {
25:
26: public JBoss4xAppServer(JBoss4xAppServerInstallation installation) {
27: super (installation);
28: }
29:
30: protected String cargoServerKey() {
31: return "jboss4x";
32: }
33:
34: protected InstalledLocalContainer container(
35: LocalConfiguration config) {
36: return new TCJBoss4xInstalledLocalContainer(config);
37: }
38:
39: protected void setConfigProperties(LocalConfiguration config)
40: throws Exception {
41: config.setProperty(GeneralPropertySet.RMI_PORT, Integer
42: .toString(AppServerUtil.getPort()));
43: }
44:
45: private static class TCJBoss4xInstalledLocalContainer extends
46: JBoss4xInstalledLocalContainer {
47: private final PortChooser pc = new PortChooser();
48:
49: public TCJBoss4xInstalledLocalContainer(
50: LocalConfiguration configuration) {
51: super (configuration);
52: }
53:
54: protected void doStart(Java java) throws Exception {
55: assignPorts();
56: super .doStart(java);
57: }
58:
59: private void assignPorts() throws IOException {
60: ReplaceLine.Token[] tokens = new ReplaceLine.Token[13];
61: int rmiPort = pc.chooseRandomPort();
62: int rmiObjPort = new PortChooser().chooseRandomPort();
63:
64: tokens[0] = new ReplaceLine.Token(14, "(RmiPort\">[0-9]+)",
65: "RmiPort\">" + rmiPort);
66: tokens[1] = new ReplaceLine.Token(50, "(port=\"[0-9]+)",
67: "port=\"" + rmiPort);
68: tokens[2] = new ReplaceLine.Token(24, "(port=\"[0-9]+)",
69: "port=\"" + pc.chooseRandomPort());
70: tokens[3] = new ReplaceLine.Token(32, "(port=\"[0-9]+)",
71: "port=\"" + rmiObjPort);
72: tokens[4] = new ReplaceLine.Token(64, "(port=\"[0-9]+)",
73: "port=\"" + rmiObjPort);
74: tokens[5] = new ReplaceLine.Token(40, "(port=\"[0-9]+)",
75: "port=\"" + pc.chooseRandomPort());
76: tokens[6] = new ReplaceLine.Token(94, "(port=\"[0-9]+)",
77: "port=\"" + pc.chooseRandomPort());
78: tokens[7] = new ReplaceLine.Token(101, "(port=\"[0-9]+)",
79: "port=\"" + pc.chooseRandomPort());
80: tokens[8] = new ReplaceLine.Token(112, "(port=\"[0-9]+)",
81: "port=\"" + pc.chooseRandomPort());
82: tokens[9] = new ReplaceLine.Token(57, "(port=\"[0-9]+)",
83: "port=\"" + pc.chooseRandomPort());
84: tokens[10] = new ReplaceLine.Token(74, "(port=\"[0-9]+)",
85: "port=\"" + pc.chooseRandomPort());
86: tokens[11] = new ReplaceLine.Token(177,
87: "(select=\"[^\"]+\")", "select=\""
88: + pc.chooseRandomPort() + "\"");
89: tokens[12] = new ReplaceLine.Token(178,
90: "(select=\"[^\"]+\")", "select=\""
91: + pc.chooseRandomPort() + "\"");
92:
93: ReplaceLine.parseFile(tokens, new File(getConfiguration()
94: .getHome(), "conf/cargo-binding.xml"));
95: }
96:
97: }
98:
99: }
|