geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dblev...@apache.org
Subject svn commit: r331661 - in /geronimo/gbuild/trunk: project.xml src/bin/ src/bin/build_and_complain.sh src/bin/buildall.sh src/bin/publish_build.sh src/main/java/org/apache/geronimo/gbuild/App.java
Date Tue, 08 Nov 2005 01:23:56 GMT
Author: dblevins
Date: Mon Nov  7 17:23:51 2005
New Revision: 331661

URL: http://svn.apache.org/viewcvs?rev=331661&view=rev
Log:
moved scripts into src/bin
hello world producer/consumer

Added:
    geronimo/gbuild/trunk/src/bin/
    geronimo/gbuild/trunk/src/bin/build_and_complain.sh
      - copied unchanged from r330941, geronimo/gbuild/build_and_complain.sh
    geronimo/gbuild/trunk/src/bin/buildall.sh
      - copied unchanged from r330941, geronimo/gbuild/buildall.sh
    geronimo/gbuild/trunk/src/bin/publish_build.sh
      - copied unchanged from r330941, geronimo/gbuild/publish_build.sh
Modified:
    geronimo/gbuild/trunk/project.xml
    geronimo/gbuild/trunk/src/main/java/org/apache/geronimo/gbuild/App.java

Modified: geronimo/gbuild/trunk/project.xml
URL: http://svn.apache.org/viewcvs/geronimo/gbuild/trunk/project.xml?rev=331661&r1=331660&r2=331661&view=diff
==============================================================================
--- geronimo/gbuild/trunk/project.xml (original)
+++ geronimo/gbuild/trunk/project.xml Mon Nov  7 17:23:51 2005
@@ -15,6 +15,16 @@
   </repository>
   <dependencies>
       <dependency>
+         <groupId>geronimo-spec</groupId>
+         <artifactId>geronimo-spec-j2ee</artifactId>
+         <version>1.4-rc4</version>
+      </dependency>
+      <dependency>
+         <groupId>concurrent</groupId>
+         <artifactId>concurrent</artifactId>
+         <version>1.3.4</version>
+      </dependency>
+      <dependency>
         <groupId>activemq</groupId>
         <artifactId>activemq-core</artifactId>
         <version>3.2</version>
@@ -31,7 +41,13 @@
         <artifactId>activeio</artifactId>
         <version>1.1</version>
       </dependency>      
-
+<!--
+    <dependency>
+      <groupId>org.codehaus.plexus</groupId>
+      <artifactId>plexus-command-line</artifactId>
+      <version>1.0-alpha-2</version>
+    </dependency>
+-->
 <!--
     <dependency>
       <groupId>activemq</groupId>
@@ -45,6 +61,11 @@
       <version>3.2</version>
     </dependency>
 -->
+    <dependency>
+       <groupId>commons-logging</groupId>
+       <artifactId>commons-logging</artifactId>
+       <version>1.0.4</version>
+    </dependency>
 
     <!-- used to support optional transport configuration via URI query strings -->
     <dependency>
@@ -112,12 +133,13 @@
       <version>2.6.2</version>
     </dependency>
 
+<!--
     <dependency>
       <groupId>org.apache.maven.continuum</groupId>
       <artifactId>continuum-core</artifactId>
       <version>1.0-SNAPSHOT</version>
     </dependency>
-
+-->
   </dependencies>
   <build>
     <sourceDirectory>src/main/java</sourceDirectory>

Modified: geronimo/gbuild/trunk/src/main/java/org/apache/geronimo/gbuild/App.java
URL: http://svn.apache.org/viewcvs/geronimo/gbuild/trunk/src/main/java/org/apache/geronimo/gbuild/App.java?rev=331661&r1=331660&r2=331661&view=diff
==============================================================================
--- geronimo/gbuild/trunk/src/main/java/org/apache/geronimo/gbuild/App.java (original)
+++ geronimo/gbuild/trunk/src/main/java/org/apache/geronimo/gbuild/App.java Mon Nov  7 17:23:51
2005
@@ -1,13 +1,255 @@
 package org.apache.geronimo.gbuild;
 
+import org.activemq.ActiveMQConnection;
+import org.activemq.ActiveMQConnectionFactory;
+import org.activemq.util.IndentPrinter;
+
+import javax.jms.Connection;
+import javax.jms.DeliveryMode;
+import javax.jms.Destination;
+import javax.jms.ExceptionListener;
+import javax.jms.JMSException;
+import javax.jms.Message;
+import javax.jms.MessageConsumer;
+import javax.jms.MessageListener;
+import javax.jms.MessageProducer;
+import javax.jms.Session;
+import javax.jms.TextMessage;
+import javax.jms.Topic;
+import java.io.IOException;
+
 /**
  * Hello world!
- *
  */
-public class App 
-{
-    public static void main( String[] args )
-    {
-        System.out.println( "Hello World!" );
+public class App {
+
+    public static void main(final String[] args) {
+        Runnable broker = new Runnable() {
+            public void run() {
+                org.activemq.broker.impl.Main.main(args);
+            }
+        };
+        thread(broker, true);
+
+        thread(new HelloWorldProducer(), false);
+
+        thread(new HelloWorldConsumer(), false);
+
+        System.out.println("Hello World!");
+    }
+
+    public static void thread(Runnable runnable, boolean daemon) {
+        Thread brokerThread = new Thread(runnable);
+        brokerThread.setDaemon(daemon);
+        brokerThread.start();
+    }
+
+    public static class HelloWorldProducer implements Runnable {
+
+        public void run() {
+            try {
+                String url = "tcp://localhost:61616";
+                String subject = "EXAMPLES";
+                String clientID = "superConsumer";
+                boolean topic = false;
+                boolean durable = false;
+                boolean transacted = false;
+                int ackMode = Session.AUTO_ACKNOWLEDGE;
+                int timeToLive = 0;
+
+                // Create a ConnectionFactory
+                ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(url);
+
+                // Create a Connection
+                Connection connection = connectionFactory.createConnection();
+                if (durable && clientID != null) {
+                    connection.setClientID(clientID);
+                }
+                connection.start();
+
+                // Create a Session
+                Session session = connection.createSession(transacted, ackMode);
+
+                // Create the destination (Topic or Queue)
+                Destination destination = null;
+                if (topic) {
+                    destination = session.createTopic(subject);
+                } else {
+                    destination = session.createQueue(subject);
+                }
+
+                // Create a MessageProducer from the Session to the Topic or Queue
+                MessageProducer producer = session.createProducer(destination);
+                if (durable) {
+                    producer.setDeliveryMode(DeliveryMode.PERSISTENT);
+                } else {
+                    producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
+                }
+                if (timeToLive != 0) {
+                    producer.setTimeToLive(timeToLive);
+                }
+
+                // Create a messages
+                TextMessage message = session.createTextMessage("Hello world! From: " + this.hashCode());
+
+                // Tell the producer to send the message
+                producer.send(message);
+
+                // If we are running with transaction support, commit
+                if (transacted) {
+                    session.commit();
+                }
+
+                // lets dump the stats for fun, optional
+                dumpStats(connection);
+
+                // Clean up
+                session.close();
+                connection.close();
+            }
+            catch (Exception e) {
+                System.out.println("Caught: " + e);
+                e.printStackTrace();
+            }
+        }
+
+        protected void dumpStats(Connection connection) {
+            ActiveMQConnection c = (ActiveMQConnection) connection;
+            c.getConnectionStats().dump(new IndentPrinter());
+        }
+    }
+
+    public static class HelloWorldConsumer implements Runnable, MessageListener, ExceptionListener
{
+
+        String url = "tcp://localhost:61616";
+        String subject = "EXAMPLES";
+        String consumerName = "james";
+        String clientID = "superConsumer";
+        boolean topic = false;
+        boolean durable = false;
+        boolean transacted = false;
+        int ackMode = Session.AUTO_ACKNOWLEDGE;
+        int timeToLive = 0;
+
+        protected int count = 0;
+        protected int dumpCount = 10;
+        protected boolean verbose = true;
+        protected int maxiumMessages = 1;
+        private boolean running;
+        private Session session;
+        private long sleepTime = 0;
+
+        public void run() {
+            try {
+                running = true;
+
+                // Create a ConnectionFactory
+                ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(url);
+
+                // Create a Connection
+                Connection connection = connectionFactory.createConnection();
+                if (durable && clientID != null) {
+                    connection.setClientID(clientID);
+                }
+                connection.setExceptionListener(this);
+
+                // Create a Session
+                session = connection.createSession(transacted, ackMode);
+
+                // Create the destination (Topic or Queue)
+                Destination destination = null;
+                if (topic) {
+                    destination = session.createTopic(subject);
+                } else {
+                    destination = session.createQueue(subject);
+                }
+
+                MessageConsumer consumer = null;
+                if (durable && topic) {
+                    consumer = session.createDurableSubscriber((Topic) destination, consumerName);
+                } else {
+                    consumer = session.createConsumer(destination);
+                }
+
+                if (maxiumMessages <= 0) {
+                    consumer.setMessageListener(this);
+                }
+
+                if (maxiumMessages > 0) {
+                    consumeMessagesAndClose(connection, session, consumer);
+                }
+            }
+            catch (Exception e) {
+                System.out.println("Caught: " + e);
+                e.printStackTrace();
+            }
+        }
+
+        public void onMessage(Message message) {
+            try {
+                if (message instanceof TextMessage) {
+                    TextMessage txtMsg = (TextMessage) message;
+                    if (verbose) {
+
+                        String msg = txtMsg.getText();
+                        if (msg.length() > 50) {
+                            msg = msg.substring(0, 50) + "...";
+                        }
+
+                        System.out.println("Received: " + msg);
+                    }
+                } else {
+                    if (verbose) {
+                        System.out.println("Received: " + message);
+                    }
+                }
+                if (transacted) {
+                    session.commit();
+                }
+                /*
+                if (++count % dumpCount == 0) {
+                    dumpStats(connection);
+                }
+                */
+            }
+            catch (JMSException e) {
+                System.out.println("Caught: " + e);
+                e.printStackTrace();
+            } finally {
+                if (sleepTime > 0) {
+                    try {
+                        Thread.sleep(sleepTime);
+                    } catch (InterruptedException e) {
+                    }
+                }
+            }
+        }
+
+        synchronized public void onException(JMSException ex) {
+            System.out.println("JMS Exception occured.  Shutting down client.");
+            running = false;
+        }
+
+        synchronized boolean isRunning() {
+            return running;
+        }
+
+        protected void consumeMessagesAndClose(Connection connection, Session session, MessageConsumer
consumer) throws JMSException, IOException {
+            System.out.println("We are about to wait until we consume: " + maxiumMessages
+ " message(s) then we will shutdown");
+
+            for (int i = 0; i < maxiumMessages && isRunning();) {
+                Message message = consumer.receive(1000);
+                if (message != null) {
+                    i++;
+                    onMessage(message);
+                }
+            }
+            System.out.println("Closing connection");
+            consumer.close();
+            session.close();
+            connection.close();
+        }
+
+
     }
 }



Mime
View raw message