[jboss-svn-commits] JBL Code SVN: r14641 - in labs/jbossesb/trunk/product: rosetta/src/org/jboss/soa/esb/listeners and 8 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Mon Aug 27 09:13:40 EDT 2007
Author: tfennelly
Date: 2007-08-27 09:13:39 -0400 (Mon, 27 Aug 2007)
New Revision: 14641
Added:
labs/jbossesb/trunk/product/rosetta/src/org/jboss/internal/soa/esb/util/Exit.java
labs/jbossesb/trunk/product/samples/quickstarts/conf/anttasks/
labs/jbossesb/trunk/product/samples/quickstarts/conf/anttasks/src/
labs/jbossesb/trunk/product/samples/quickstarts/conf/anttasks/src/org/
labs/jbossesb/trunk/product/samples/quickstarts/conf/anttasks/src/org/jboss/
labs/jbossesb/trunk/product/samples/quickstarts/conf/anttasks/src/org/jboss/ant/
labs/jbossesb/trunk/product/samples/quickstarts/conf/anttasks/src/org/jboss/ant/QuickstartJava.java
Modified:
labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/StandAloneBootStrapper.java
labs/jbossesb/trunk/product/samples/quickstarts/conf/base-build.xml
labs/jbossesb/trunk/product/samples/quickstarts/transform_CSV2XML/readme.txt
labs/jbossesb/trunk/product/samples/quickstarts/transform_XML2XML_simple/readme.txt
Log:
http://jira.jboss.com/jira/browse/JBESB-881
http://jira.jboss.com/jira/browse/JBESB-882
Added: labs/jbossesb/trunk/product/rosetta/src/org/jboss/internal/soa/esb/util/Exit.java
===================================================================
--- labs/jbossesb/trunk/product/rosetta/src/org/jboss/internal/soa/esb/util/Exit.java (rev 0)
+++ labs/jbossesb/trunk/product/rosetta/src/org/jboss/internal/soa/esb/util/Exit.java 2007-08-27 13:13:39 UTC (rev 14641)
@@ -0,0 +1,141 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ *
+ * (C) 2005-2006, JBoss Inc.
+ */
+package org.jboss.internal.soa.esb.util;
+
+import org.apache.log4j.Logger;
+
+import java.net.ServerSocket;
+import java.net.Socket;
+import java.io.*;
+
+/**
+ * Exit Listener utility class.
+ * <p/>
+ * Used to exit a process cleanly, when that process is forked as a "child" process
+ * e.g. when forked by a <java> task in an Ant script.
+ * <p/>
+ * This is required because Windows (and other OSs - apparently Solaris is the same) doesn't
+ * shutdown processes cleanly through their implementation of the {@link Process#destroy()}
+ * method. Apparently the Windows implementation uses the Windows shell "TerminateProcess"
+ * call to kill all child processes and this does the job of termination rather brutally,
+ * resulting in shutdown hooks not being triggered etc.
+ *
+ * @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
+ */
+public class Exit {
+
+ private static Logger logger = Logger.getLogger(Exit.class);
+ private static final String EXIT = "Exit";
+
+ /**
+ * Start the listener on the specified port.
+ * @param port Listen port.
+ */
+ public static void startListener(final int port) throws Exception {
+ new Thread() {
+ public void run() {
+ ServerSocket serverSocket = null;
+ try {
+ serverSocket = new ServerSocket(port);
+ logger.info("Started Exit listener on port " + port);
+ while(true) {
+ Socket socket = serverSocket.accept();
+ OutputStream output = socket.getOutputStream();
+ InputStream input = socket.getInputStream();
+
+ try {
+ // Write an EXIT and see is it echoed back...
+ writeExit(output);
+ if(isExit(input)) {
+ // EXIT was echoed back, so we exit...
+ logger.info("Received process exit event on port " + port);
+ break;
+ }
+ // Not echoed back... must be someone else... continue to listen...
+ } finally {
+ closeSocket(output, input, socket);
+ }
+ }
+ } catch (IOException e) {
+ System.err.println(e);
+ System.exit(1);
+ return;
+ } finally {
+ if(serverSocket != null ) {
+ try {
+ serverSocket.close();
+ } catch (IOException e) {
+ System.err.println(e);
+ }
+ }
+ }
+ System.exit(0);
+ }
+ }.start();
+ }
+
+ public static void signalExit(int port) throws Throwable {
+ Socket socket = new Socket("localhost", port);
+ OutputStream output = socket.getOutputStream();
+ InputStream input = socket.getInputStream();
+
+ try {
+ // Wait for an EXIT...
+ if(isExit(input)) {
+ // We got an EXIT... echo it back...
+ writeExit(output);
+ }
+ } finally {
+ closeSocket(output, input, socket);
+ }
+ }
+
+ private static boolean isExit(InputStream input) {
+ try {
+ DataInputStream dataReader = new DataInputStream(input);
+ return EXIT.equals(dataReader.readUTF());
+ } catch(Exception e) {
+ return false;
+ }
+ }
+
+
+ private static void writeExit(OutputStream output) {
+ try {
+ DataOutputStream dataWriter = new DataOutputStream(output);
+
+ dataWriter.writeUTF(EXIT);
+ dataWriter.flush();
+ } catch(Exception e) {
+ }
+ }
+
+ private static void closeSocket(OutputStream output, InputStream input, Socket socket) throws IOException {
+ try {
+ output.close();
+ } finally {
+ try {
+ input.close();
+ } finally {
+ socket.close();
+ }
+ }
+ }
+}
Property changes on: labs/jbossesb/trunk/product/rosetta/src/org/jboss/internal/soa/esb/util/Exit.java
___________________________________________________________________
Name: svn:eol-style
+ native
Modified: labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/StandAloneBootStrapper.java
===================================================================
--- labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/StandAloneBootStrapper.java 2007-08-27 12:54:34 UTC (rev 14640)
+++ labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/StandAloneBootStrapper.java 2007-08-27 13:13:39 UTC (rev 14641)
@@ -29,6 +29,7 @@
import org.apache.log4j.Logger;
import org.apache.log4j.xml.DOMConfigurator;
import org.jboss.internal.soa.esb.rosetta.pooling.JmsConnectionPoolContainer;
+import org.jboss.internal.soa.esb.util.Exit;
import org.jboss.soa.esb.ConfigurationException;
import org.jboss.soa.esb.listeners.config.ConfigurationController;
@@ -36,10 +37,11 @@
{
private ConfigurationController _confController;
- private static Logger _logger = Logger
+ private static Logger _logger = Logger
.getLogger(StandAloneBootStrapper.class);
+ private static Exit exit;
- public static void main (String[] args) throws Exception
+ public static void main (String[] args) throws Exception
{
System.out.println("+----------------------------------------------------------+");
System.out.println("| |");
@@ -66,11 +68,28 @@
}
- long lSecondsToRun = 365 * 24 * 3600; // run for 1 year (is it enough
+ long lSecondsToRun = 365 * 24 * 3600; // run for 1 year (is it enough
// ?)
if (args.length > 1) try
{
- lSecondsToRun = Long.parseLong(args[1]);
+ for (int i = 1; i < args.length; i++) {
+ String arg = args[i];
+
+ if(arg.startsWith("exit-port=")) {
+ try {
+ int port = Integer.parseInt(arg.substring("exit-port=".length()));
+ Exit.startListener(port);
+ } catch(NumberFormatException e) {
+ System.out.println("Invalid exit port config '" + arg + "'.");
+ }
+ } else {
+ try {
+ lSecondsToRun = Long.parseLong(arg);
+ } catch(NumberFormatException e) {
+ System.out.println("Invalid 'secondst to run' time config '" + arg + "'.");
+ }
+ }
+ }
}
catch (Exception e)
{
@@ -106,7 +125,7 @@
}
}
- public StandAloneBootStrapper (String configName) throws ConfigurationException
+ public StandAloneBootStrapper (String configName) throws ConfigurationException
{
this(configName, null);
}
Property changes on: labs/jbossesb/trunk/product/samples/quickstarts/conf/anttasks
___________________________________________________________________
Name: svn:ignore
+ classes
Added: labs/jbossesb/trunk/product/samples/quickstarts/conf/anttasks/src/org/jboss/ant/QuickstartJava.java
===================================================================
--- labs/jbossesb/trunk/product/samples/quickstarts/conf/anttasks/src/org/jboss/ant/QuickstartJava.java (rev 0)
+++ labs/jbossesb/trunk/product/samples/quickstarts/conf/anttasks/src/org/jboss/ant/QuickstartJava.java 2007-08-27 13:13:39 UTC (rev 14641)
@@ -0,0 +1,111 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ *
+ * (C) 2005-2006, JBoss Inc.
+ */
+package org.jboss.ant;
+
+import org.apache.tools.ant.taskdefs.Java;
+import org.apache.tools.ant.taskdefs.Execute;
+import org.apache.tools.ant.taskdefs.ExecuteStreamHandler;
+import org.apache.tools.ant.taskdefs.condition.Socket;
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.types.CommandlineJava;
+import org.jboss.internal.soa.esb.util.Exit;
+
+import java.io.IOException;
+
+/**
+ * Quickstart executor.
+ * <p/>
+ * Just to provide some control over the shutdown when the process is forked.
+ *
+ * @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
+ */
+public class QuickstartJava extends Java {
+
+ public int executeJava() throws BuildException {
+ CommandlineJava cmdl = getCommandLine();
+ final Process process;
+ final ExecuteStreamHandler streamHandler = redirector.createHandler();
+
+ final int freePort = findFreePort();
+
+ setupRedirector();
+ try {
+ cmdl.createArgument().setValue("exit-port=" + freePort);
+ process = Execute.launch(getProject(), cmdl.getCommandline(), null, getProject().getBaseDir(), true);
+ startStreamHandler(streamHandler, process);
+
+ Runtime.getRuntime().addShutdownHook(new Thread() {
+ public void run() {
+ signalExit(freePort);
+ waitForProcessShutdown(process);
+ streamHandler.stop();
+ Execute.closeStreams(process);
+ }
+ });
+ } catch (IOException e) {
+ throw new BuildException("Failed to launch Quickstart processes.", e);
+ }
+
+ waitForProcessShutdown(process);
+
+ return process.exitValue();
+ }
+
+ private void startStreamHandler(ExecuteStreamHandler streamHandler, Process process) {
+ try {
+ streamHandler.setProcessInputStream(process.getOutputStream());
+ streamHandler.setProcessOutputStream(process.getInputStream());
+ streamHandler.setProcessErrorStream(process.getErrorStream());
+ streamHandler.start();
+ } catch (IOException e) {
+ throw new BuildException("Failed to setup redirect stream handler.", e);
+ }
+ }
+
+ private void signalExit(int freePort) {
+ try {
+ Exit.signalExit(freePort);
+ } catch (Throwable throwable) {
+ throw new BuildException("Failed to exit forked process.", throwable);
+ }
+ }
+
+ private int findFreePort() throws BuildException {
+ Socket socket = new Socket();
+
+ socket.setServer("localhost");
+ for(int i = 60 * 1024; i < 65000; i++) {
+ socket.setPort(i);
+ if(!socket.eval()) {
+ return i;
+ }
+ }
+
+ throw new BuildException("Failed to locate a free port off which to launch StandAloneBootStrapper.");
+ }
+
+ private void waitForProcessShutdown(Process process) {
+ try {
+ process.waitFor();
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ }
+}
Property changes on: labs/jbossesb/trunk/product/samples/quickstarts/conf/anttasks/src/org/jboss/ant/QuickstartJava.java
___________________________________________________________________
Name: svn:eol-style
+ native
Modified: labs/jbossesb/trunk/product/samples/quickstarts/conf/base-build.xml
===================================================================
--- labs/jbossesb/trunk/product/samples/quickstarts/conf/base-build.xml 2007-08-27 12:54:34 UTC (rev 14640)
+++ labs/jbossesb/trunk/product/samples/quickstarts/conf/base-build.xml 2007-08-27 13:13:39 UTC (rev 14641)
@@ -160,9 +160,9 @@
<path id="deployment-classpath">
<fileset dir="${base.jbossesb}/lib" includes="*.jar"/>
- <fileset dir="${base.jbossesb}/lib/ext" includes="*.jar"/>
- <!-- jbossesb config -->
- <fileset dir="${base.jbossesb}/lib/jbossesb.esb" includes="*.jar"/>
+ <fileset dir="${base.jbossesb}/lib/ext" includes="*.jar"/>
+ <!-- jbossesb config -->
+ <fileset dir="${base.jbossesb}/lib/jbossesb.esb" includes="*.jar"/>
<pathelement location="${base.jbossesb}/lib/jbossesb.esb"/>
<!-- jbpm config -->
<fileset dir="${base.jbossesb}/lib/jbpm.esb" includes="*.jar"/>
@@ -172,12 +172,12 @@
<pathelement location="${base.jbossesb}/lib/smooks.esb"/>
<!-- jbrules config -->
<fileset dir="${base.jbossesb}/lib/jbrules.esb" includes="*.jar"/>
- <pathelement location="${base.jbossesb}/lib/jbrules.esb"/>
- <!-- spring config -->
- <fileset dir="${base.jbossesb}/lib/spring.esb" includes="*.jar"/>
+ <pathelement location="${base.jbossesb}/lib/jbrules.esb"/>
+ <!-- spring config -->
+ <fileset dir="${base.jbossesb}/lib/spring.esb" includes="*.jar"/>
<pathelement location="${base.jbossesb}/lib/spring.esb"/>
- <!-- soap config -->
- <fileset dir="${base.jbossesb}/lib/soap.esb" includes="*.jar"/>
+ <!-- soap config -->
+ <fileset dir="${base.jbossesb}/lib/soap.esb" includes="*.jar"/>
<pathelement location="${base.jbossesb}/lib/soap.esb"/>
</path>
</target>
@@ -188,9 +188,9 @@
<property name="org.jboss.esb.server.config" value="default"/>
<path id="deployment-classpath">
- <fileset dir="${product.dir}/server/default/deploy/jbossesb.sar/lib" includes="*.jar"/>
- <!-- jbossesb config -->
- <fileset dir="${product.dir}/server/default/deploy/jbossesb.esb" includes="*.jar"/>
+ <fileset dir="${product.dir}/server/default/deploy/jbossesb.sar/lib" includes="*.jar"/>
+ <!-- jbossesb config -->
+ <fileset dir="${product.dir}/server/default/deploy/jbossesb.esb" includes="*.jar"/>
<pathelement location="${product.dir}/server/default/deploy/jbossesb.esb"/>
<!-- jbpm config -->
<fileset dir="${product.dir}/server/default/deploy/jbpm.esb" includes="*.jar"/>
@@ -201,9 +201,9 @@
<pathelement location="${product.dir}/server/default/deploy/smooks.esb"/>
<!-- jbrules config -->
<fileset dir="${product.dir}/server/default/deploy/jbrules.esb" includes="*.jar"/>
- <pathelement location="${product.dir}/server/default/deploy/jbrules.esb"/>
- <!-- spring config -->
- <fileset dir="${product.dir}/server/default/deploy/spring.esb" includes="*.jar"/>
+ <pathelement location="${product.dir}/server/default/deploy/jbrules.esb"/>
+ <!-- spring config -->
+ <fileset dir="${product.dir}/server/default/deploy/spring.esb" includes="*.jar"/>
<pathelement location="${product.dir}/server/default/deploy/spring.esb"/>
<!-- soap config -->
<fileset dir="${product.dir}/server/default/deploy/soap.esb" includes="*.jar"/>
@@ -241,6 +241,7 @@
<!--fileset dir="${org.jboss.esb.server.home}/client" includes="*.jar" /--> <!-- Required for JMS Client Code. -->
<fileset dir="${org.jboss.esb.server.home}/server/${org.jboss.esb.server.config}/deploy/jboss-aop-jdk50.deployer" includes="jboss-aop-jdk50.jar" /> <!-- Required for JMS Client Code. -->
<path refid="compile-classpath" />
+ <pathelement location="../conf/anttasks/classes" />
</path>
</target>
@@ -256,6 +257,11 @@
<javac srcdir="${basedir}/src" destdir="${classes}" debug="true">
<classpath refid="compile-classpath" />
</javac>
+
+ <mkdir dir="../conf/anttasks/classes" />
+ <javac srcdir="../conf/anttasks/src" destdir="../conf/anttasks/classes" debug="true">
+ <classpath refid="compile-classpath" />
+ </javac>
</target>
<target name="run" depends="compile,config">
@@ -267,10 +273,13 @@
<isset property="esb.config.file"/>
</condition>
<echo>Launching Quickstart in standalone mode...</echo>
- <java fork="no" classname="org.jboss.soa.esb.listeners.StandAloneBootStrapper" failonerror="true">
+ <taskdef name="qsjava" classname="org.jboss.ant.QuickstartJava" classpathref="exec-classpath" />
+ <qsjava fork="yes" classname="org.jboss.soa.esb.listeners.StandAloneBootStrapper" failonerror="true">
<arg value="${esb.config.file}" />
- <classpath refid="exec-classpath" />
- </java>
+ <!--jvmarg value="-Xdebug"/>
+ <jvmarg value="-Xrunjdwp:transport=dt_socket,address=8787,server=y,suspend=y"/ -->
+ <classpath refid="exec-classpath" />
+ </qsjava>
</target>
<target name="deploy" depends="prepare-deployment, check-exploded, deploy-esb, deploy-exploded-esb, quickstart-specific-deploys, display-instructions">
Modified: labs/jbossesb/trunk/product/samples/quickstarts/transform_CSV2XML/readme.txt
===================================================================
--- labs/jbossesb/trunk/product/samples/quickstarts/transform_CSV2XML/readme.txt 2007-08-27 12:54:34 UTC (rev 14640)
+++ labs/jbossesb/trunk/product/samples/quickstarts/transform_CSV2XML/readme.txt 2007-08-27 13:13:39 UTC (rev 14641)
@@ -46,17 +46,11 @@
for receiving the contents of the SampleOrder.csv file located in this
folder.
- smooks-cdr.lst:
- This file is used by the JBoss ESB Transformation Service to list the
- Transformation resource configuration URIs. Out of the box, the
- smoooks-cdr.lst file in this Quickstart refers to 2 resource URIs, both of
- which are classpath based.
-
smooks-res.xml:
This file defines the Transformations for the Quickstart. In this case it
defines two transformations.
- 1. The first transformation uses smooks CSVParser to parse the CVS file and
+ 1. The first part of the transformation uses smooks CSVParser to parse the CVS file and
create an intermediate xml format that looks like this:
<cvs-set>
@@ -68,6 +62,6 @@
</cvs-record>
</cvs-set>
- 2. The second tranformation transforms the intermediate smooks format to the
+ 2. The second part of the tranformation transforms the intermediate smooks format to the
target xml format. This is the second section in smooks-res.xml. It is
here you can map the values to you're target xml format.
Modified: labs/jbossesb/trunk/product/samples/quickstarts/transform_XML2XML_simple/readme.txt
===================================================================
--- labs/jbossesb/trunk/product/samples/quickstarts/transform_XML2XML_simple/readme.txt 2007-08-27 12:54:34 UTC (rev 14640)
+++ labs/jbossesb/trunk/product/samples/quickstarts/transform_XML2XML_simple/readme.txt 2007-08-27 13:13:39 UTC (rev 14641)
@@ -50,14 +50,6 @@
folder (line 31). The listener configuration then executes the
"SmooksTransformer" action for the Message Exchange between "A" and "B".
- smooks-cdr.lst:
- This file is used by the JBoss ESB Transformation Service to list the
- Transformation resource configuration URIs. Out of the box, the
- smoooks-cdr.lst file in this Quickstart refers to 2 resource URIs, both of
- which are classpath based. It also has a commented out listing for
- accessing Transformation Configurations managed by the JBoss ESB
- Administration Console (see below).
-
smooks-res.xml:
This file defines the Transformations for the Quickstart. In this case, it
simply defines a single XSL transformation for the order line items.
More information about the jboss-svn-commits
mailing list