1 18 package org.apache.activemq.systest.impl; 19 20 import java.io.File ; 21 22 import org.apache.activemq.ActiveMQConnectionFactory; 23 import org.apache.activemq.systest.BrokerAgent; 24 25 import javax.jms.ConnectionFactory ; 26 27 28 33 public class SeparateBrokerProcessAgentImpl extends SeparateProcessAgent implements BrokerAgent { 34 35 private static final String ENV_HOME = "ACTIVEMQ_HOME"; 36 37 private static int portCounter = 61616; 38 39 private int port; 40 private String connectionURI; 41 private String brokerScript; 42 private File workingDirectory = new File ("target/test-brokers"); 43 private String defaultPrefix = "~/activemq"; 44 private String coreURI; 45 46 public SeparateBrokerProcessAgentImpl(String host) throws Exception { 47 port = portCounter++; 48 coreURI = "tcp://" + host + ":" + port; 49 connectionURI = "failover:(" + coreURI + ")?useExponentialBackOff=false&initialReconnectDelay=500&&maxReconnectAttempts=20"; 50 } 51 52 public void kill() throws Exception { 53 stop(); 54 } 55 56 public ConnectionFactory getConnectionFactory() { 57 return new ActiveMQConnectionFactory(getConnectionURI()); 58 } 59 60 public String getConnectionURI() { 61 return connectionURI; 62 } 63 64 public void connectTo(BrokerAgent remoteBroker) throws Exception { 65 } 67 68 public String getBrokerScript() { 69 if (brokerScript == null) { 70 brokerScript = createBrokerScript(); 71 } 72 return brokerScript; 73 } 74 75 public void setBrokerScript(String activemqScript) { 76 this.brokerScript = activemqScript; 77 } 78 79 public String getDefaultPrefix() { 80 return defaultPrefix; 81 } 82 83 public void setDefaultPrefix(String defaultPrefix) { 84 this.defaultPrefix = defaultPrefix; 85 } 86 87 public File getWorkingDirectory() { 88 return workingDirectory; 89 } 90 91 public void setWorkingDirectory(File workingDirectory) { 92 this.workingDirectory = workingDirectory; 93 } 94 95 protected Process createProcess() throws Exception { 98 String commands[] = getCommands(); 99 100 System.out.print("About to execute command:"); 101 for (int i=0; i<commands.length; i++) { 102 System.out.print(" "); 103 System.out.print(commands[i]); 104 } 105 System.out.println(); 106 107 File workingDir = createBrokerWorkingDirectory(); 108 109 System.out.println("In directory: " + workingDir); 110 111 Process answer = Runtime.getRuntime().exec(commands, null, workingDir); 112 return answer; 113 } 114 115 protected File createBrokerWorkingDirectory() { 116 workingDirectory.mkdirs(); 117 118 File brokerDir = new File (workingDirectory, "broker_" + port); 120 brokerDir.mkdirs(); 121 122 File varDir = new File (brokerDir, "data"); 123 varDir.mkdirs(); 124 125 File workDir = new File (brokerDir, "work"); 126 workDir.mkdirs(); 127 return workDir; 128 } 129 130 protected String createBrokerScript() { 131 String version = null; 132 Package p = Package.getPackage("org.apache.activemq"); 133 if (p != null) { 134 version = p.getImplementationVersion(); 135 } 136 if (version == null) { 137 version = "activemq-4.0-SNAPSHOT"; 138 } 139 return "../../../../../assembly/target/" + version + "/bin/" + version + "/bin/activemq"; 140 } 141 142 protected String [] createCommand() { 143 String script = System.getProperty("brokerScript"); 145 if (script == null) { 146 String home = System.getenv(ENV_HOME); 147 if (home == null) { 148 script = getBrokerScript(); 149 } 150 else { 151 script = home + "/bin/" + brokerScript; 152 } 153 } 154 155 String [] answer = { "/bin/bash", script, "broker:" + coreURI }; 156 return answer; 157 } 158 } 159 | Popular Tags |