Author: nash
Date: Thu Feb  4 08:24:53 2010
New Revision: 906398

URL: http://svn.apache.org/viewvc?rev=906398&view=rev
Log:
Launch JMS broker and CORBA tnameserv automatically (TUSCANY-3454)

Removed:
    
tuscany/sca-java-1.x/trunk/tutorials/travelsample/launchers/currency-converter-jms/src/main/java/scatours/JMSBrokerLauncher.java
    
tuscany/sca-java-1.x/trunk/tutorials/travelsample/services/smsgateway-jms/src/main/java/scatours/JMSBrokerLauncher.java
Modified:
    
tuscany/sca-java-1.x/trunk/tutorials/travelsample/clients/currency-converter-jms/build.xml
    
tuscany/sca-java-1.x/trunk/tutorials/travelsample/launchers/currency-converter-jms/build.xml
    
tuscany/sca-java-1.x/trunk/tutorials/travelsample/launchers/currency-converter-jms/src/main/java/scatours/CurrencyConverterJMSLauncher.java
    
tuscany/sca-java-1.x/trunk/tutorials/travelsample/launchers/notification-corba/build.xml
    
tuscany/sca-java-1.x/trunk/tutorials/travelsample/launchers/notification-jms/build.xml
    
tuscany/sca-java-1.x/trunk/tutorials/travelsample/services/smsgateway-corba/build.xml
    
tuscany/sca-java-1.x/trunk/tutorials/travelsample/services/smsgateway-corba/src/main/java/scatours/smsgateway/SMSGatewayCORBAServiceBootstrap.java
    
tuscany/sca-java-1.x/trunk/tutorials/travelsample/services/smsgateway-jms/build.xml
    
tuscany/sca-java-1.x/trunk/tutorials/travelsample/services/smsgateway-jms/src/main/java/scatours/smsgateway/SMSGatewayJMSServiceBootstrap.java

Modified: 
tuscany/sca-java-1.x/trunk/tutorials/travelsample/clients/currency-converter-jms/build.xml
URL: 
http://svn.apache.org/viewvc/tuscany/sca-java-1.x/trunk/tutorials/travelsample/clients/currency-converter-jms/build.xml?rev=906398&r1=906397&r2=906398&view=diff
==============================================================================
--- 
tuscany/sca-java-1.x/trunk/tutorials/travelsample/clients/currency-converter-jms/build.xml
 (original)
+++ 
tuscany/sca-java-1.x/trunk/tutorials/travelsample/clients/currency-converter-jms/build.xml
 Thu Feb  4 08:24:53 2010
@@ -20,12 +20,8 @@
 <project name="scatours-client-currency-converter-jms" default="compile">
     <import file="../../antdefs.xml"/>
 
-    <!-- Before invoking the "run" target, both the JMS broker and the
-       JMS implementation of the currency converter service need to be
-       started, each in its own process. -->
-    <target name="run-broker">
-        <ant dir="../../launchers/currency-converter-jms" target="run-broker"/>
-    </target>
+    <!-- Before invoking the "run" target, the JMS implementation of the
+       currency converter service needs to be started in its own process. -->
     <target name="run-service">
         <ant dir="../../launchers/currency-converter-jms" target="run"/>
     </target>

Modified: 
tuscany/sca-java-1.x/trunk/tutorials/travelsample/launchers/currency-converter-jms/build.xml
URL: 
http://svn.apache.org/viewvc/tuscany/sca-java-1.x/trunk/tutorials/travelsample/launchers/currency-converter-jms/build.xml?rev=906398&r1=906397&r2=906398&view=diff
==============================================================================
--- 
tuscany/sca-java-1.x/trunk/tutorials/travelsample/launchers/currency-converter-jms/build.xml
 (original)
+++ 
tuscany/sca-java-1.x/trunk/tutorials/travelsample/launchers/currency-converter-jms/build.xml
 Thu Feb  4 08:24:53 2010
@@ -23,18 +23,6 @@
         <pathelement 
path="../../util/launcher-common/target/scatours-util-launcher-common.jar"/>
     </path>
 
-    <!-- Before invoking the "run" target, the JMS broker needs to be
-         started and running in a different process. -->
-    <target name="run-broker">
-        <java classname="scatours.JMSBrokerLauncher" fork="true">
-            <classpath>
-                <pathelement location="target/${ant.project.name}.jar"/>
-                <!-- The following is used to bring in the ActiveMQ runtime. 
-->
-                <pathelement 
location="${env.TUSCANY_HOME}/lib/tuscany-sca-manifest.jar"/>
-            </classpath>
-        </java>
-    </target>
-
     <!-- After starting the SCA JMS service by invoking the "run" target below,
        the ActiveMQ JMS implementation of the currency converter client should 
be
        run in another process using the "run-client" target. -->

Modified: 
tuscany/sca-java-1.x/trunk/tutorials/travelsample/launchers/currency-converter-jms/src/main/java/scatours/CurrencyConverterJMSLauncher.java
URL: 
http://svn.apache.org/viewvc/tuscany/sca-java-1.x/trunk/tutorials/travelsample/launchers/currency-converter-jms/src/main/java/scatours/CurrencyConverterJMSLauncher.java?rev=906398&r1=906397&r2=906398&view=diff
==============================================================================
--- 
tuscany/sca-java-1.x/trunk/tutorials/travelsample/launchers/currency-converter-jms/src/main/java/scatours/CurrencyConverterJMSLauncher.java
 (original)
+++ 
tuscany/sca-java-1.x/trunk/tutorials/travelsample/launchers/currency-converter-jms/src/main/java/scatours/CurrencyConverterJMSLauncher.java
 Thu Feb  4 08:24:53 2010
@@ -21,6 +21,7 @@
 
 import static scatours.launcher.LauncherUtil.locate;
 
+import org.apache.activemq.broker.BrokerService;
 import org.apache.tuscany.sca.node.SCAContribution;
 import org.apache.tuscany.sca.node.SCANode;
 import org.apache.tuscany.sca.node.SCANodeFactory;
@@ -28,6 +29,12 @@
 public class CurrencyConverterJMSLauncher {
 
     public static void main(String[] args) throws Exception {
+        final BrokerService jmsBroker = new BrokerService();
+        jmsBroker.setPersistent(false);
+        jmsBroker.setUseJmx(false);
+        jmsBroker.addConnector("tcp://localhost:61619");
+        jmsBroker.start();
+
         SCAContribution currencyJMSContribution = locate("currency-jms");
         SCAContribution currencyContribution = locate("currency");
 
@@ -41,5 +48,6 @@
         System.in.read();
 
         node.stop();
+        jmsBroker.stop();
     }
 }

Modified: 
tuscany/sca-java-1.x/trunk/tutorials/travelsample/launchers/notification-corba/build.xml
URL: 
http://svn.apache.org/viewvc/tuscany/sca-java-1.x/trunk/tutorials/travelsample/launchers/notification-corba/build.xml?rev=906398&r1=906397&r2=906398&view=diff
==============================================================================
--- 
tuscany/sca-java-1.x/trunk/tutorials/travelsample/launchers/notification-corba/build.xml
 (original)
+++ 
tuscany/sca-java-1.x/trunk/tutorials/travelsample/launchers/notification-corba/build.xml
 Thu Feb  4 08:24:53 2010
@@ -23,12 +23,8 @@
         <pathelement 
path="../../util/launcher-common/target/scatours-util-launcher-common.jar"/>
     </path>
 
-    <!-- Before invoking the "run" target, both the CORBA nameserver and
-       the CORBA SMS Gateway service need to be started and running in
-       different processes. -->
-    <target name="run-nameserver">
-        <ant dir="../../services/smsgateway-corba" target="run-nameserver"/>
-    </target>
+    <!-- Before invoking the "run" target, the CORBA SMS Gateway service
+       needs to be started and running in a different process. -->
     <target name="run-smsgateway">
         <ant dir="../../services/smsgateway-corba" target="run"/>
     </target>

Modified: 
tuscany/sca-java-1.x/trunk/tutorials/travelsample/launchers/notification-jms/build.xml
URL: 
http://svn.apache.org/viewvc/tuscany/sca-java-1.x/trunk/tutorials/travelsample/launchers/notification-jms/build.xml?rev=906398&r1=906397&r2=906398&view=diff
==============================================================================
--- 
tuscany/sca-java-1.x/trunk/tutorials/travelsample/launchers/notification-jms/build.xml
 (original)
+++ 
tuscany/sca-java-1.x/trunk/tutorials/travelsample/launchers/notification-jms/build.xml
 Thu Feb  4 08:24:53 2010
@@ -23,12 +23,8 @@
         <pathelement 
path="../../util/launcher-common/target/scatours-util-launcher-common.jar"/>
     </path>
 
-    <!-- Before invoking the "run" target, both the JMS broker and the
-       JMS implementation of the SMS gateway need to be started and running
-       in different processes. -->
-    <target name="run-broker">
-        <ant dir="../../services/smsgateway-jms" target="run-broker"/>
-    </target>
+    <!-- Before invoking the "run" target, the JMS implementation of the
+       SMS gateway needs to be started and running in a different process. -->
     <target name="run-smsgateway">
         <ant dir="../../services/smsgateway-jms" target="run"/>
     </target>

Modified: 
tuscany/sca-java-1.x/trunk/tutorials/travelsample/services/smsgateway-corba/build.xml
URL: 
http://svn.apache.org/viewvc/tuscany/sca-java-1.x/trunk/tutorials/travelsample/services/smsgateway-corba/build.xml?rev=906398&r1=906397&r2=906398&view=diff
==============================================================================
--- 
tuscany/sca-java-1.x/trunk/tutorials/travelsample/services/smsgateway-corba/build.xml
 (original)
+++ 
tuscany/sca-java-1.x/trunk/tutorials/travelsample/services/smsgateway-corba/build.xml
 Thu Feb  4 08:24:53 2010
@@ -28,15 +28,6 @@
         </antcall>
     </target>
 
-    <!-- Before invoking the "run" target, the CORBA nameserver needs to be
-         started and running in a different process. -->
-    <target name="run-nameserver">
-        <exec executable="${env.JAVA_HOME}/bin/tnameserv">
-            <arg value="-ORBInitialPort"/>
-            <arg value="5080"/>
-        </exec>
-    </target>
-
     <target name="run">
         <java classname="scatours.smsgateway.SMSGatewayCORBAServiceBootstrap" 
fork="true">
             <classpath location="target/${ant.project.name}.jar"/>

Modified: 
tuscany/sca-java-1.x/trunk/tutorials/travelsample/services/smsgateway-corba/src/main/java/scatours/smsgateway/SMSGatewayCORBAServiceBootstrap.java
URL: 
http://svn.apache.org/viewvc/tuscany/sca-java-1.x/trunk/tutorials/travelsample/services/smsgateway-corba/src/main/java/scatours/smsgateway/SMSGatewayCORBAServiceBootstrap.java?rev=906398&r1=906397&r2=906398&view=diff
==============================================================================
--- 
tuscany/sca-java-1.x/trunk/tutorials/travelsample/services/smsgateway-corba/src/main/java/scatours/smsgateway/SMSGatewayCORBAServiceBootstrap.java
 (original)
+++ 
tuscany/sca-java-1.x/trunk/tutorials/travelsample/services/smsgateway-corba/src/main/java/scatours/smsgateway/SMSGatewayCORBAServiceBootstrap.java
 Thu Feb  4 08:24:53 2010
@@ -18,6 +18,10 @@
  */
 package scatours.smsgateway;
 
+import java.io.BufferedReader;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+
 import org.omg.CORBA.ORB;
 import org.omg.CORBA.Object;
 import org.omg.CosNaming.NameComponent;
@@ -29,34 +33,73 @@
 public class SMSGatewayCORBAServiceBootstrap {
 
     public static void main(String[] args) throws Exception {
-        System.out.println("Publishing SMS Gateway Service as a CORBA service: 
SMSGatewayCORBAService (port=5080)");
-
-        String[] orbArgs = {"-ORBInitialPort", "5080"};
-        ORB orb = ORB.init(orbArgs, null);
+        String home = System.getProperty("java.home");
+        String[] tnsCommand = {"" + home + "/bin/tnameserv", 
"-ORBInitialPort", "5080"};
+        Process tns = null;
 
-        NamingContextExt namingCtx;
         try {
-            Object objRef = orb.resolve_initial_references("NameService");
-            namingCtx = NamingContextExtHelper.narrow(objRef);
-        } catch (Exception ex) {
-            System.err.println("ERROR: Failed to resolve Name Service.");
-            System.err.println("Don't forget to run it with:");
-            System.err.println("  tnameserv -ORBInitialPort 5080");
-            return;
-        }
+            System.out.println("Starting transient name server process 
(port=5080)");
 
-        Object rootPoaRef = orb.resolve_initial_references("RootPOA");
-        POA rootPoa = POAHelper.narrow(rootPoaRef);
-        rootPoa.the_POAManager().activate();
-
-        SMSGatewayServant smsGateway = new SMSGatewayServant();
-        Object smsGatewayRef = rootPoa.servant_to_reference(smsGateway);
-
-        String corbaServerName = "SMSGatewayCORBAService";
-        NameComponent[] name = {new NameComponent(corbaServerName, "")};
-        namingCtx.rebind(name, smsGatewayRef);
+            // Start tnameserv in a separate process
+            tns = Runtime.getRuntime().exec(tnsCommand);
 
-        System.out.println("CORBA server running - waiting for requests");
-        orb.run();
+            // Wait for the tnameserv process to complete its startup, and
+            // display the output from the tnameserv process on the console
+            InputStream tnsOut = tns.getInputStream();
+            BufferedReader tnsOutReader = new BufferedReader(new 
InputStreamReader(tnsOut));
+            while (true) {
+                String line = tnsOutReader.readLine();
+                System.out.println("tnameserv: " + line);
+                if ("Ready.".equals(line)) {
+                    break;
+                }
+            }
+
+            System.out.println("Publishing SMS Gateway Service as a CORBA 
service: SMSGatewayCORBAService (port=5080)");
+
+            String[] orbArgs = {"-ORBInitialPort", "5080"};
+            ORB orb = ORB.init(orbArgs, null);
+
+            NamingContextExt namingCtx;
+            try {
+                Object objRef = orb.resolve_initial_references("NameService");
+                namingCtx = NamingContextExtHelper.narrow(objRef);
+            } catch (Exception ex) {
+                System.err.println("ERROR: Failed to resolve Name Service.");
+                //System.err.println("Don't forget to run it with:");
+                //System.err.println("  tnameserv -ORBInitialPort 5080");
+                return;
+            }
+
+            Object rootPoaRef = orb.resolve_initial_references("RootPOA");
+            POA rootPoa = POAHelper.narrow(rootPoaRef);
+            rootPoa.the_POAManager().activate();
+
+            SMSGatewayServant smsGateway = new SMSGatewayServant();
+            Object smsGatewayRef = rootPoa.servant_to_reference(smsGateway);
+
+            String corbaServerName = "SMSGatewayCORBAService";
+            NameComponent[] name = {new NameComponent(corbaServerName, "")};
+            namingCtx.rebind(name, smsGatewayRef);
+
+            System.out.println("CORBA server running - press Enter to 
shutdown");
+            System.in.read();
+
+            orb.shutdown(true);
+            orb.destroy();
+
+        } finally {
+            // Make sure that the tnameserv process gets destroyed and its
+            // listener port is released
+            if (tns != null) {
+                System.out.println("Destroying transient name server process");
+                try {
+                    tns.destroy();
+                    System.out.println("Transient name server process 
destroyed");
+                } catch (Exception e) {
+                    // ignore
+                }
+            }
+        }
     }
 }

Modified: 
tuscany/sca-java-1.x/trunk/tutorials/travelsample/services/smsgateway-jms/build.xml
URL: 
http://svn.apache.org/viewvc/tuscany/sca-java-1.x/trunk/tutorials/travelsample/services/smsgateway-jms/build.xml?rev=906398&r1=906397&r2=906398&view=diff
==============================================================================
--- 
tuscany/sca-java-1.x/trunk/tutorials/travelsample/services/smsgateway-jms/build.xml
 (original)
+++ 
tuscany/sca-java-1.x/trunk/tutorials/travelsample/services/smsgateway-jms/build.xml
 Thu Feb  4 08:24:53 2010
@@ -20,18 +20,6 @@
 <project name="scatours-service-smsgateway-jms" default="compile">
     <import file="../../antdefs.xml"/>
 
-    <!-- Before invoking the "run" target, the JMS broker needs to be
-         started and running in a different process. -->
-    <target name="run-broker">
-        <java classname="scatours.JMSBrokerLauncher" fork="true">
-            <classpath>
-                <pathelement location="target/${ant.project.name}.jar"/>
-                <!-- The following is used to bring in the ActiveMQ runtime. 
-->
-                <pathelement 
location="${env.TUSCANY_HOME}/lib/tuscany-sca-manifest.jar"/>
-            </classpath>
-        </java>
-    </target>
-
     <!-- The "run" target creates JMS request and response queues for the
        SMS gateway service.  These queues are used by the "run" target of
        the notification-jms launcher. -->

Modified: 
tuscany/sca-java-1.x/trunk/tutorials/travelsample/services/smsgateway-jms/src/main/java/scatours/smsgateway/SMSGatewayJMSServiceBootstrap.java
URL: 
http://svn.apache.org/viewvc/tuscany/sca-java-1.x/trunk/tutorials/travelsample/services/smsgateway-jms/src/main/java/scatours/smsgateway/SMSGatewayJMSServiceBootstrap.java?rev=906398&r1=906397&r2=906398&view=diff
==============================================================================
--- 
tuscany/sca-java-1.x/trunk/tutorials/travelsample/services/smsgateway-jms/src/main/java/scatours/smsgateway/SMSGatewayJMSServiceBootstrap.java
 (original)
+++ 
tuscany/sca-java-1.x/trunk/tutorials/travelsample/services/smsgateway-jms/src/main/java/scatours/smsgateway/SMSGatewayJMSServiceBootstrap.java
 Thu Feb  4 08:24:53 2010
@@ -22,10 +22,17 @@
 import javax.jms.Session;
 
 import org.apache.activemq.ActiveMQConnectionFactory;
+import org.apache.activemq.broker.BrokerService;
 
 public class SMSGatewayJMSServiceBootstrap {
 
     public static void main(String[] args) throws Exception {
+        final BrokerService jmsBroker = new BrokerService();
+        jmsBroker.setPersistent(false);
+        jmsBroker.setUseJmx(false);
+        jmsBroker.addConnector("tcp://localhost:61619");
+        jmsBroker.start();
+
         System.out.println("Publishing SMS Gateway Service as a JMS service: 
tcp://localhost:61619");
         System.out.println("Press Ctrl^C to terminate...");
 


Reply via email to