Author: veithen
Date: Sun Dec 9 12:08:15 2012
New Revision: 1418903
URL: http://svn.apache.org/viewvc?rev=1418903&view=rev
Log:
* Use the Daemon interface defined by commons-daemon instead of our own Daemon
interface.
* Improved the management of the child process lifecycle.
Added:
axis/axis1/java/trunk/daemon-launcher/ (with props)
axis/axis1/java/trunk/daemon-launcher/pom.xml (with props)
axis/axis1/java/trunk/daemon-launcher/src/
axis/axis1/java/trunk/daemon-launcher/src/main/
axis/axis1/java/trunk/daemon-launcher/src/main/java/
axis/axis1/java/trunk/daemon-launcher/src/main/java/org/
axis/axis1/java/trunk/daemon-launcher/src/main/java/org/apache/
axis/axis1/java/trunk/daemon-launcher/src/main/java/org/apache/axis/
axis/axis1/java/trunk/daemon-launcher/src/main/java/org/apache/axis/tools/
axis/axis1/java/trunk/daemon-launcher/src/main/java/org/apache/axis/tools/daemon/
axis/axis1/java/trunk/daemon-launcher/src/main/java/org/apache/axis/tools/daemon/ControlConnectionReader.java
(with props)
axis/axis1/java/trunk/daemon-launcher/src/main/java/org/apache/axis/tools/daemon/DaemonContextImpl.java
(with props)
axis/axis1/java/trunk/daemon-launcher/src/main/java/org/apache/axis/tools/daemon/Launcher.java
- copied, changed from r1418761,
axis/axis1/java/trunk/axis-testutils/src/main/java/org/apache/axis/testutils/daemon/Launcher.java
axis/axis1/java/trunk/daemon-launcher/src/main/java/org/apache/axis/tools/daemon/LauncherException.java
(with props)
Removed:
axis/axis1/java/trunk/axis-testutils/src/main/java/org/apache/axis/testutils/daemon/
Modified:
axis/axis1/java/trunk/maven/maven-axis-server-plugin/pom.xml
axis/axis1/java/trunk/maven/maven-axis-server-plugin/src/main/java/org/apache/axis/tools/maven/server/StartDaemonMojo.java
axis/axis1/java/trunk/pom.xml
axis/axis1/java/trunk/samples/jms-sample/pom.xml
axis/axis1/java/trunk/samples/jms-sample/src/test/java/samples/jms/ActiveMQDaemon.java
Propchange: axis/axis1/java/trunk/daemon-launcher/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Sun Dec 9 12:08:15 2012
@@ -0,0 +1,4 @@
+.classpath
+.project
+target
+.settings
Added: axis/axis1/java/trunk/daemon-launcher/pom.xml
URL:
http://svn.apache.org/viewvc/axis/axis1/java/trunk/daemon-launcher/pom.xml?rev=1418903&view=auto
==============================================================================
--- axis/axis1/java/trunk/daemon-launcher/pom.xml (added)
+++ axis/axis1/java/trunk/daemon-launcher/pom.xml Sun Dec 9 12:08:15 2012
@@ -0,0 +1,50 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ Licensed to the Apache Software Foundation (ASF) under one
+ ~ or more contributor license agreements. See the NOTICE file
+ ~ distributed with this work for additional information
+ ~ regarding copyright ownership. The ASF licenses this file
+ ~ to you under the Apache License, Version 2.0 (the
+ ~ "License"); you may not use this file except in compliance
+ ~ with the License. You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing,
+ ~ software distributed under the License is distributed on an
+ ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ ~ KIND, either express or implied. See the License for the
+ ~ specific language governing permissions and limitations
+ ~ under the License.
+ -->
+<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.apache.axis</groupId>
+ <artifactId>axis-project</artifactId>
+ <version>1.4.1-SNAPSHOT</version>
+ <relativePath>../pom.xml</relativePath>
+ </parent>
+ <artifactId>daemon-launcher</artifactId>
+ <name>Daemon Launcher</name>
+ <description>
+ Used by maven-axis-server-plugin to launch a Commons Daemon
implementation.
+ </description>
+ <dependencies>
+ <dependency>
+ <groupId>commons-daemon</groupId>
+ <artifactId>commons-daemon</artifactId>
+ </dependency>
+ </dependencies>
+ <build>
+ <plugins>
+ <plugin>
+ <artifactId>maven-site-plugin</artifactId>
+ <configuration>
+ <skip>true</skip>
+ <skipDeploy>true</skipDeploy>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+</project>
Propchange: axis/axis1/java/trunk/daemon-launcher/pom.xml
------------------------------------------------------------------------------
svn:eol-style = native
Added:
axis/axis1/java/trunk/daemon-launcher/src/main/java/org/apache/axis/tools/daemon/ControlConnectionReader.java
URL:
http://svn.apache.org/viewvc/axis/axis1/java/trunk/daemon-launcher/src/main/java/org/apache/axis/tools/daemon/ControlConnectionReader.java?rev=1418903&view=auto
==============================================================================
---
axis/axis1/java/trunk/daemon-launcher/src/main/java/org/apache/axis/tools/daemon/ControlConnectionReader.java
(added)
+++
axis/axis1/java/trunk/daemon-launcher/src/main/java/org/apache/axis/tools/daemon/ControlConnectionReader.java
Sun Dec 9 12:08:15 2012
@@ -0,0 +1,76 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.axis.tools.daemon;
+
+import java.io.BufferedReader;
+import java.io.Reader;
+import java.util.LinkedList;
+
+import org.apache.commons.daemon.Daemon;
+
+/**
+ * Reads messages from the control connection. The main purpose of this is to
detect as soon as
+ * possible when the control connection is closed by the parent process and to
terminate the child
+ * process if that is unexpected. To achieve this we need to read the messages
eagerly and place
+ * them into a queue. In particular this covers the case where the child
process has received a
+ * <tt>STOP</tt> message and {@link Daemon#stop()} or {@link Daemon#destroy()}
hangs. In this case,
+ * if the parent process is terminated (or stops waiting for the
<tt>STOPPED</tt> message and closes
+ * the control connection), we can stop the child process immediately.
+ *
+ * @author Andreas Veithen
+ */
+final class ControlConnectionReader implements Runnable {
+ private final BufferedReader in;
+ private final LinkedList queue = new LinkedList();
+ private boolean expectClose;
+
+ ControlConnectionReader(Reader in) {
+ this.in = new BufferedReader(in);
+ }
+
+ synchronized String awaitMessage() throws InterruptedException {
+ while (queue.isEmpty()) {
+ wait();
+ }
+ return (String)queue.removeFirst();
+ }
+
+ synchronized void expectClose() {
+ this.expectClose = true;
+ }
+
+ public void run() {
+ try {
+ String message;
+ while ((message = in.readLine()) != null) {
+ synchronized (this) {
+ queue.add(message);
+ notify();
+ }
+ }
+ if (!expectClose) {
+ System.err.println("Control connection unexpectedly closed;
terminating.");
+ System.exit(1);
+ }
+ } catch (Throwable ex) {
+ ex.printStackTrace();
+ System.exit(1);
+ }
+ }
+}
Propchange:
axis/axis1/java/trunk/daemon-launcher/src/main/java/org/apache/axis/tools/daemon/ControlConnectionReader.java
------------------------------------------------------------------------------
svn:eol-style = native
Added:
axis/axis1/java/trunk/daemon-launcher/src/main/java/org/apache/axis/tools/daemon/DaemonContextImpl.java
URL:
http://svn.apache.org/viewvc/axis/axis1/java/trunk/daemon-launcher/src/main/java/org/apache/axis/tools/daemon/DaemonContextImpl.java?rev=1418903&view=auto
==============================================================================
---
axis/axis1/java/trunk/daemon-launcher/src/main/java/org/apache/axis/tools/daemon/DaemonContextImpl.java
(added)
+++
axis/axis1/java/trunk/daemon-launcher/src/main/java/org/apache/axis/tools/daemon/DaemonContextImpl.java
Sun Dec 9 12:08:15 2012
@@ -0,0 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.axis.tools.daemon;
+
+import org.apache.commons.daemon.DaemonContext;
+import org.apache.commons.daemon.DaemonController;
+
+final class DaemonContextImpl implements DaemonContext {
+ private final String[] args;
+
+ public DaemonContextImpl(String[] args) {
+ this.args = args;
+ }
+
+ public DaemonController getController() {
+ throw new UnsupportedOperationException();
+ }
+
+ public String[] getArguments() {
+ return args;
+ }
+}
Propchange:
axis/axis1/java/trunk/daemon-launcher/src/main/java/org/apache/axis/tools/daemon/DaemonContextImpl.java
------------------------------------------------------------------------------
svn:eol-style = native
Copied:
axis/axis1/java/trunk/daemon-launcher/src/main/java/org/apache/axis/tools/daemon/Launcher.java
(from r1418761,
axis/axis1/java/trunk/axis-testutils/src/main/java/org/apache/axis/testutils/daemon/Launcher.java)
URL:
http://svn.apache.org/viewvc/axis/axis1/java/trunk/daemon-launcher/src/main/java/org/apache/axis/tools/daemon/Launcher.java?p2=axis/axis1/java/trunk/daemon-launcher/src/main/java/org/apache/axis/tools/daemon/Launcher.java&p1=axis/axis1/java/trunk/axis-testutils/src/main/java/org/apache/axis/testutils/daemon/Launcher.java&r1=1418761&r2=1418903&rev=1418903&view=diff
==============================================================================
---
axis/axis1/java/trunk/axis-testutils/src/main/java/org/apache/axis/testutils/daemon/Launcher.java
(original)
+++
axis/axis1/java/trunk/daemon-launcher/src/main/java/org/apache/axis/tools/daemon/Launcher.java
Sun Dec 9 12:08:15 2012
@@ -16,9 +16,8 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.apache.axis.testutils.daemon;
+package org.apache.axis.tools.daemon;
-import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.Writer;
@@ -27,30 +26,76 @@ import java.net.InetSocketAddress;
import java.net.ServerSocket;
import java.net.Socket;
+import org.apache.commons.daemon.Daemon;
+import org.apache.commons.daemon.DaemonContext;
+
+/**
+ * Main class to launch and control a {@link Daemon} implementation. This
class is typically
+ * executed in a child JVM and allows the parent process to control the
lifecycle of the daemon
+ * instance. The main method takes the following arguments:
+ * <ol>
+ * <li>The class name of the {@link Daemon} implementation.
+ * <li>A TCP port number to use for the control connection.
+ * </ol>
+ * All remaining arguments are passed to the {@link Daemon} implementation.
+ * <p>
+ * The class uses the following protocol to allow the parent process to
control the lifecycle of the
+ * daemon:
+ * <ol>
+ * <li>The parent process spawns a new child JVM with this class as main
class. It passes the class
+ * name of the {@link Daemon} implementation and the control port as arguments
(see above).
+ * <li>The child process opens the specified TCP port and waits for the
control connection to be
+ * established.
+ * <li>The parent process connects to the control port.
+ * <li>The child process {@link Daemon#init(DaemonContext) initializes} and
{@link Daemon#start()
+ * starts} the daemon.
+ * <li>The child process sends a <tt>READY</tt> message over the control
connection to the parent
+ * process.
+ * <li>When the parent process no longer needs the daemon, it sends a
<tt>STOP</tt> message to the
+ * child process.
+ * <li>The child process {@link Daemon#stop() stops} and {@link
Daemon#destroy() destroys} the
+ * daemon.
+ * <li>The child process sends a <tt>STOPPED</tt> message to the parent
process, closes the control
+ * connection and terminates itself.
+ * <li>The parent process closes the control connection.
+ * </ol>
+ *
+ * @author Andreas Veithen
+ */
public class Launcher {
- public static void main(String[] args) throws Exception {
- String daemonClass = args[0];
- int controlPort = Integer.parseInt(args[1]);
- String[] daemonArgs = new String[args.length-2];
- System.arraycopy(args, 2, daemonArgs, 0, args.length-2);
- ServerSocket controlServerSocket = new ServerSocket();
- controlServerSocket.bind(new
InetSocketAddress(InetAddress.getByName("localhost"), controlPort));
- Socket controlSocket = controlServerSocket.accept();
- BufferedReader controlIn = new BufferedReader(new
InputStreamReader(controlSocket.getInputStream(), "ASCII"));
- Writer controlOut = new
OutputStreamWriter(controlSocket.getOutputStream(), "ASCII");
- Daemon daemon = (Daemon)Class.forName(daemonClass).newInstance();
- daemon.start(daemonArgs);
- controlOut.write("READY\r\n");
- controlOut.flush();
- String request = controlIn.readLine();
- if (request == null) {
- System.err.println("Control connection unexpectedly closed");
- } else if (request.equals("STOP")) {
- daemon.stop();
- controlOut.write("STOPPED\r\n");
+ public static void main(String[] args) {
+ try {
+ String daemonClass = args[0];
+ int controlPort = Integer.parseInt(args[1]);
+ String[] daemonArgs = new String[args.length-2];
+ System.arraycopy(args, 2, daemonArgs, 0, args.length-2);
+ ServerSocket controlServerSocket = new ServerSocket();
+ controlServerSocket.bind(new
InetSocketAddress(InetAddress.getByName("localhost"), controlPort));
+ Socket controlSocket = controlServerSocket.accept();
+ // We only accept a single connection; therefore we can close the
ServerSocket here
+ controlServerSocket.close();
+ ControlConnectionReader controlIn = new
ControlConnectionReader(new InputStreamReader(controlSocket.getInputStream(),
"ASCII"));
+ new Thread(controlIn).start();
+ Writer controlOut = new
OutputStreamWriter(controlSocket.getOutputStream(), "ASCII");
+ Daemon daemon = (Daemon)Class.forName(daemonClass).newInstance();
+ daemon.init(new DaemonContextImpl(daemonArgs));
+ daemon.start();
+ controlOut.write("READY\r\n");
controlOut.flush();
- } else {
- System.err.println("Unexpected request: " + request);
+ String request = controlIn.awaitMessage();
+ if (request.equals("STOP")) {
+ daemon.stop();
+ daemon.destroy();
+ controlIn.expectClose();
+ controlOut.write("STOPPED\r\n");
+ controlOut.flush();
+ System.exit(0);
+ } else {
+ throw new LauncherException("Unexpected request: " + request);
+ }
+ } catch (Throwable ex) {
+ ex.printStackTrace();
+ System.exit(1);
}
}
}
Added:
axis/axis1/java/trunk/daemon-launcher/src/main/java/org/apache/axis/tools/daemon/LauncherException.java
URL:
http://svn.apache.org/viewvc/axis/axis1/java/trunk/daemon-launcher/src/main/java/org/apache/axis/tools/daemon/LauncherException.java?rev=1418903&view=auto
==============================================================================
---
axis/axis1/java/trunk/daemon-launcher/src/main/java/org/apache/axis/tools/daemon/LauncherException.java
(added)
+++
axis/axis1/java/trunk/daemon-launcher/src/main/java/org/apache/axis/tools/daemon/LauncherException.java
Sun Dec 9 12:08:15 2012
@@ -0,0 +1,27 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.axis.tools.daemon;
+
+final class LauncherException extends Exception {
+ private static final long serialVersionUID = 9049901854635661634L;
+
+ public LauncherException(String msg) {
+ super(msg);
+ }
+}
Propchange:
axis/axis1/java/trunk/daemon-launcher/src/main/java/org/apache/axis/tools/daemon/LauncherException.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: axis/axis1/java/trunk/maven/maven-axis-server-plugin/pom.xml
URL:
http://svn.apache.org/viewvc/axis/axis1/java/trunk/maven/maven-axis-server-plugin/pom.xml?rev=1418903&r1=1418902&r2=1418903&view=diff
==============================================================================
--- axis/axis1/java/trunk/maven/maven-axis-server-plugin/pom.xml (original)
+++ axis/axis1/java/trunk/maven/maven-axis-server-plugin/pom.xml Sun Dec 9
12:08:15 2012
@@ -60,6 +60,23 @@
<artifactId>maven-toolchain</artifactId>
<version>1.0</version>
</dependency>
+
+ <!-- These dependencies are here merely to ensure that in the Axis
build they are built
+ before this project. This is necessary because these artifacts
may be loaded by
+ the plug-in at runtime and we need to make sure that they are
available and that
+ we get the latest version. -->
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>daemon-launcher</artifactId>
+ <version>${project.version}</version>
+ <type>pom</type>
+ </dependency>
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>axis-standalone-server</artifactId>
+ <version>${project.version}</version>
+ <type>pom</type>
+ </dependency>
</dependencies>
<reporting>
<plugins>
Modified:
axis/axis1/java/trunk/maven/maven-axis-server-plugin/src/main/java/org/apache/axis/tools/maven/server/StartDaemonMojo.java
URL:
http://svn.apache.org/viewvc/axis/axis1/java/trunk/maven/maven-axis-server-plugin/src/main/java/org/apache/axis/tools/maven/server/StartDaemonMojo.java?rev=1418903&r1=1418902&r2=1418903&view=diff
==============================================================================
---
axis/axis1/java/trunk/maven/maven-axis-server-plugin/src/main/java/org/apache/axis/tools/maven/server/StartDaemonMojo.java
(original)
+++
axis/axis1/java/trunk/maven/maven-axis-server-plugin/src/main/java/org/apache/axis/tools/maven/server/StartDaemonMojo.java
Sun Dec 9 12:08:15 2012
@@ -21,7 +21,10 @@ package org.apache.axis.tools.maven.serv
import java.io.File;
import java.io.IOException;
import java.net.ServerSocket;
+import java.util.HashSet;
+import java.util.Set;
+import org.apache.maven.artifact.Artifact;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
@@ -34,6 +37,13 @@ import org.apache.maven.plugin.MojoFailu
*/
public class StartDaemonMojo extends AbstractStartProcessMojo {
/**
+ * @parameter default-value="${plugin.version}"
+ * @required
+ * @readonly
+ */
+ private String axisVersion;
+
+ /**
* The daemon class.
*
* @parameter
@@ -72,6 +82,8 @@ public class StartDaemonMojo extends Abs
if (args != null) {
System.arraycopy(args, 0, vmArgs, 2, args.length);
}
- startJavaProcess(daemonClass,
"org.apache.axis.testutils.daemon.Launcher", null, vmArgs, workDir, new
DaemonProcessControl(controlPort));
+ Set additionalDependencies = new HashSet();
+
additionalDependencies.add(artifactFactory.createArtifact("org.apache.axis",
"daemon-launcher", axisVersion, Artifact.SCOPE_TEST, "jar"));
+ startJavaProcess(daemonClass, "org.apache.axis.tools.daemon.Launcher",
additionalDependencies, vmArgs, workDir, new DaemonProcessControl(controlPort));
}
}
Modified: axis/axis1/java/trunk/pom.xml
URL:
http://svn.apache.org/viewvc/axis/axis1/java/trunk/pom.xml?rev=1418903&r1=1418902&r2=1418903&view=diff
==============================================================================
--- axis/axis1/java/trunk/pom.xml (original)
+++ axis/axis1/java/trunk/pom.xml Sun Dec 9 12:08:15 2012
@@ -79,6 +79,7 @@
<module>axis-testutils</module>
<module>axis-tools</module>
<module>axis-war</module>
+ <module>daemon-launcher</module>
<module>distribution</module>
<module>integration</module>
<module>interop-mock</module>
@@ -131,6 +132,11 @@
<artifactId>commons-lang</artifactId>
<version>2.6</version>
</dependency>
+ <dependency>
+ <groupId>commons-daemon</groupId>
+ <artifactId>commons-daemon</artifactId>
+ <version>1.0.10</version>
+ </dependency>
</dependencies>
</dependencyManagement>
<prerequisites>
Modified: axis/axis1/java/trunk/samples/jms-sample/pom.xml
URL:
http://svn.apache.org/viewvc/axis/axis1/java/trunk/samples/jms-sample/pom.xml?rev=1418903&r1=1418902&r2=1418903&view=diff
==============================================================================
--- axis/axis1/java/trunk/samples/jms-sample/pom.xml (original)
+++ axis/axis1/java/trunk/samples/jms-sample/pom.xml Sun Dec 9 12:08:15 2012
@@ -54,9 +54,8 @@
<scope>test</scope>
</dependency>
<dependency>
- <groupId>${project.groupId}</groupId>
- <artifactId>axis-testutils</artifactId>
- <version>${project.version}</version>
+ <groupId>commons-daemon</groupId>
+ <artifactId>commons-daemon</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
Modified:
axis/axis1/java/trunk/samples/jms-sample/src/test/java/samples/jms/ActiveMQDaemon.java
URL:
http://svn.apache.org/viewvc/axis/axis1/java/trunk/samples/jms-sample/src/test/java/samples/jms/ActiveMQDaemon.java?rev=1418903&r1=1418902&r2=1418903&view=diff
==============================================================================
---
axis/axis1/java/trunk/samples/jms-sample/src/test/java/samples/jms/ActiveMQDaemon.java
(original)
+++
axis/axis1/java/trunk/samples/jms-sample/src/test/java/samples/jms/ActiveMQDaemon.java
Sun Dec 9 12:08:15 2012
@@ -20,17 +20,26 @@ package samples.jms;
import org.apache.activemq.broker.BrokerFactory;
import org.apache.activemq.broker.BrokerService;
-import org.apache.axis.testutils.daemon.Daemon;
+import org.apache.commons.daemon.Daemon;
+import org.apache.commons.daemon.DaemonContext;
+import org.apache.commons.daemon.DaemonInitException;
public class ActiveMQDaemon implements Daemon {
private BrokerService broker;
- public void start(String[] args) throws Exception {
- broker = BrokerFactory.createBroker("broker:(tcp://localhost:" +
args[0] + ")?useJmx=false&persistent=false");
+ public void init(DaemonContext context) throws DaemonInitException,
Exception {
+ broker = BrokerFactory.createBroker("broker:(tcp://localhost:" +
context.getArguments()[0] + ")?useJmx=false&persistent=false");
+ }
+
+ public void start() throws Exception {
broker.start();
}
public void stop() throws Exception {
broker.stop();
}
+
+ public void destroy() {
+ broker = null;
+ }
}