[tunguska~hg:19] Context root fixed

  • From: abien@kenai.com
  • To: commits@tunguska.kenai.com
  • Subject: [tunguska~hg:19] Context root fixed
  • Date: Tue, 3 Nov 2009 19:16:07 +0000

Project:    tunguska
Repository: hg
Revision:   19
Author:     abien
Date:       2009-11-03 19:14:38 UTC
Link:       

Log Message:
------------
Dependency to Java EE API added
Dependency to mockito added
Unit tests for adapter completed
Initial implementation
Resource for automatic creation of JMS creation of Destinations / Factories 
added.
Initial creation
JMS topic injected
Initial creation
Context root fixed


Revisions:
----------
11
12
13
14
15
16
17
18
19


Modified Paths:
---------------
tunguska/pom.xml
tunguska/src/main/java/org/tunguska/outerspace/http/CometServlet.java
tunguska/src/main/java/org/tunguska/outerspace/http/Subscriber.java
tunguska/src/main/webapp/WEB-INF/sun-web.xml


Added Paths:
------------
tunguska/src/test/java/org/tunguska/innerspace/grizzly/ChannelListenerAdapterTest.java
tunguska/src/main/java/org/tunguska/innerspace/jms/TopicListener.java
tunguska/src/main/setup/sun-resources.xml
tunguska/src/main/java/org/tunguska/innerspace/channels/ChannelListener.java
tunguska/src/main/java/org/tunguska/innerspace/grizzly/ChannelListenerAdapter.java


Diffs:
------
diff -r ae36592e271f -r 559f37f1bb4f tunguska/pom.xml
--- a/tunguska/pom.xml  Tue Nov 03 13:41:25 2009 +0100
+++ b/tunguska/pom.xml  Tue Nov 03 14:02:43 2009 +0100
@@ -35,6 +35,13 @@
       <version>1.9.18-e</version>
       <scope>provided</scope>
     </dependency>
+    <dependency>
+      <groupId>javax</groupId>
+      <artifactId>javaee-api</artifactId>
+      <version>6.0-SNAPSHOT</version>
+      <type>jar</type>
+      <scope>provided</scope>
+    </dependency>
   </dependencies>
   <build>
     <plugins>


diff -r 559f37f1bb4f -r c19936edec12 tunguska/pom.xml
--- a/tunguska/pom.xml  Tue Nov 03 14:02:43 2009 +0100
+++ b/tunguska/pom.xml  Tue Nov 03 14:16:56 2009 +0100
@@ -42,6 +42,12 @@
       <type>jar</type>
       <scope>provided</scope>
     </dependency>
+    <dependency>
+      <groupId>org.mockito</groupId>
+      <artifactId>mockito-all</artifactId>
+      <version>1.8.0</version>
+      <scope>test</scope>
+    </dependency>
   </dependencies>
   <build>
     <plugins>
@@ -73,3 +79,4 @@
 
 
 
+


diff -r c19936edec12 -r 8c3804b92a07 
tunguska/src/test/java/org/tunguska/innerspace/grizzly/ChannelListenerAdapterTest.java
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ 
b/tunguska/src/test/java/org/tunguska/innerspace/grizzly/ChannelListenerAdapterTest.java
    Tue Nov 03 14:28:21 2009 +0100
@@ -0,0 +1,52 @@
+/**
+This file is part of tunguska.
+
+tunguska is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or
+(at your option) any later version.
+
+tunguska is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program.  If not, see 
<http://www.opensource.org/licenses/gpl-2.0.php>.
+
+* Copyright (c) 04. November 2009
+*
+*/
+package org.tunguska.innerspace.grizzly;
+
+import com.sun.grizzly.comet.CometContext;
+import java.io.IOException;
+import org.junit.Test;
+import static org.junit.Assert.*;
+import static org.mockito.Mockito.*;
+
+/**
+ *
+ * @author http://blog.adam-bien.com
+ */
+public class ChannelListenerAdapterTest {
+
+    @Test
+    public void onArrival() throws IOException {
+       String jmsMessage = "hugo";
+       CometContext cometContext = mock(CometContext.class);
+       ChannelListenerAdapter channelListenerAdapter = new 
ChannelListenerAdapter(cometContext);
+       channelListenerAdapter.onArrival(jmsMessage);
+       verify(cometContext).notify(jmsMessage);
+    }
+
+    @Test(expected=IllegalStateException.class)
+    public void onArrivalGrizzlyError() throws IOException {
+       String jmsMessage = "hugo";
+       CometContext cometContext = mock(CometContext.class);
+       doThrow(new 
IllegalStateException()).when(cometContext).notify(jmsMessage);
+       ChannelListenerAdapter channelListenerAdapter = new 
ChannelListenerAdapter(cometContext);
+       channelListenerAdapter.onArrival(jmsMessage);
+    }
+
+}
\ No newline at end of file


diff -r 8c3804b92a07 -r 3f79bdff8937 
tunguska/src/main/java/org/tunguska/innerspace/jms/TopicListener.java
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/tunguska/src/main/java/org/tunguska/innerspace/jms/TopicListener.java   
  Tue Nov 03 18:05:58 2009 +0100
@@ -0,0 +1,86 @@
+/**
+This file is part of tunguska.
+
+tunguska is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or
+(at your option) any later version.
+
+tunguska is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program.  If not, see 
<http://www.opensource.org/licenses/gpl-2.0.php>.
+
+* Copyright (c) 04. November 2009
+*
+*/
+package org.tunguska.innerspace.jms;
+
+import org.tunguska.innerspace.channels.ChannelListener;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+import javax.jms.Connection;
+import javax.jms.ConnectionFactory;
+import javax.jms.JMSException;
+import javax.jms.Message;
+import javax.jms.MessageConsumer;
+import javax.jms.MessageListener;
+import javax.jms.Session;
+import javax.jms.TextMessage;
+import javax.jms.Topic;
+
+/**
+ *
+ * @author http://blog.adam-bien.com
+ */
+public class TopicListener implements MessageListener{
+    private static Logger logger = 
Logger.getLogger(TopicListener.class.getName());
+
+    private Connection connection;
+    private Session session;
+    private Topic topic;
+    private MessageConsumer consumer;
+    private ConnectionFactory connectionFactory;
+    private ChannelListener channelListener;
+
+    public TopicListener(ConnectionFactory connectionFactory,Topic topic, 
ChannelListener channelListener) {
+        this.topic = topic;
+        this.connectionFactory = connectionFactory;
+        this.channelListener = channelListener;
+        this.connectToServer();
+    }
+
+
+
+    void connectToServer() {
+        try{
+            connection = connectionFactory.createConnection();
+            session = connection.createSession(false, 
Session.AUTO_ACKNOWLEDGE);
+            consumer = session.createConsumer(topic);
+            consumer.setMessageListener(this);
+            connection.start();
+        }catch(JMSException ex){
+            throw new IllegalStateException("Cannot setup infrastructure 
(e.g. connect to server) " + ex,ex);
+        }
+    }
+
+
+  
+
+    @Override
+    public void onMessage(Message msg) {
+        try {
+            logger.info("Message: " + msg + " received");
+            TextMessage textMessage = (TextMessage) msg;
+            String message = textMessage.getText();
+            this.channelListener.onArrival(message);
+        } catch (JMSException ex) {
+            logger.log(Level.SEVERE, null, ex);
+            throw new IllegalStateException("Cannot delegate to 
ChannelListener: " +ex,ex);
+        }
+    }
+
+}


diff -r 3f79bdff8937 -r 3aa251fdf59e tunguska/src/main/setup/sun-resources.xml
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/tunguska/src/main/setup/sun-resources.xml Tue Nov 03 18:26:32 2009 +0100
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE resources PUBLIC "-//Sun Microsystems, Inc.//DTD Application 
Server 9.0 Resource Definitions //EN" 
"http://www.sun.com/software/appserver/dtds/sun-resources_1_3.dtd";>
+<resources>
+  <admin-object-resource enabled="true" jndi-name="jms/tunguska" 
object-type="user" res-adapter="jmsra" res-type="javax.jms.Topic">
+    <description>Is used for communication between the business logic (inner 
space) and the edge servers (outer space).</description>
+    <property name="Name" value="mq.sys.dmq"/>
+  </admin-object-resource>
+  <connector-resource enabled="true" jndi-name="jms/tunguskaFactory" 
object-type="user" pool-name="jms/tunguskaFactory">
+    <description>Creates a jms/tunguska Topic</description>
+  </connector-resource>
+  <connector-connection-pool associate-with-thread="false" 
connection-creation-retry-attempts="0" 
connection-creation-retry-interval-in-seconds="10" 
connection-definition-name="javax.jms.TopicConnectionFactory" 
connection-leak-reclaim="false" connection-leak-timeout-in-seconds="0" 
fail-all-connections="false" idle-timeout-in-seconds="300" 
is-connection-validation-required="false" lazy-connection-association="false" 
lazy-connection-enlistment="false" match-connections="true" 
max-connection-usage-count="0" max-pool-size="32" 
max-wait-time-in-millis="60000" name="jms/tunguskaFactory" 
pool-resize-quantity="2" resource-adapter-name="jmsra" steady-pool-size="8" 
validate-atmost-once-period-in-seconds="0"/>
+</resources>


diff -r 3aa251fdf59e -r a59d09110dca 
tunguska/src/main/java/org/tunguska/innerspace/channels/ChannelListener.java
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ 
b/tunguska/src/main/java/org/tunguska/innerspace/channels/ChannelListener.java
      Tue Nov 03 20:13:09 2009 +0100
@@ -0,0 +1,30 @@
+/**
+This file is part of tunguska.
+
+tunguska is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or
+(at your option) any later version.
+
+tunguska is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program.  If not, see 
<http://www.opensource.org/licenses/gpl-2.0.php>.
+
+* Copyright (c) 04. November 2009
+*
+*/
+package org.tunguska.innerspace.channels;
+
+/**
+ *
+ * @author http://blog.adam-bien.com
+ */
+public interface ChannelListener {
+
+    public void onArrival(String message);
+
+}


diff -r a59d09110dca -r 4bd725ea1d74 
tunguska/src/main/java/org/tunguska/outerspace/http/CometServlet.java
--- a/tunguska/src/main/java/org/tunguska/outerspace/http/CometServlet.java   
  Tue Nov 03 20:13:09 2009 +0100
+++ b/tunguska/src/main/java/org/tunguska/outerspace/http/CometServlet.java   
  Tue Nov 03 20:14:03 2009 +0100
@@ -20,24 +20,36 @@
 package org.tunguska.outerspace.http;
 
 
+import javax.annotation.Resource;
+import javax.jms.ConnectionFactory;
+import javax.jms.Topic;
 import javax.servlet.http.HttpServlet;
 import javax.servlet.http.HttpServletRequest;
 import com.sun.grizzly.comet.CometContext;
 import com.sun.grizzly.comet.CometEngine;
+import org.tunguska.innerspace.grizzly.ChannelListenerAdapter;
+import org.tunguska.innerspace.jms.TopicListener;
 /**
  *
  * @author nschoeneich
  */
 public abstract class CometServlet extends HttpServlet {
+    @Resource(name = "jms/tunguska")
+    private Topic tunguska;
+    @Resource(name = "jms/tunguskaFactory")
+    private ConnectionFactory tunguskaFactory;
 
     public final static int TIMEOUT_IN_SECONDS = 180;
 
+
+
     protected CometContext getCometContext(String channel) {
         CometEngine engine = CometEngine.getEngine();
         CometContext cometContext = engine.getCometContext(channel);
         if (cometContext == null) {
             cometContext = engine.register(channel);
             cometContext.setExpirationDelay(1000 * TIMEOUT_IN_SECONDS);
+            new TopicListener(tunguskaFactory, tunguska, new 
ChannelListenerAdapter(cometContext));
         }
         return cometContext;
     }
@@ -49,4 +61,4 @@
     protected CometContext getCometContext(HttpServletRequest 
httpServletRequest) {
         return 
getCometContext(getCommand(httpServletRequest.getRequestURI()));
     }
-}
+    }

diff -r a59d09110dca -r 4bd725ea1d74 
tunguska/src/main/java/org/tunguska/outerspace/http/Subscriber.java
--- a/tunguska/src/main/java/org/tunguska/outerspace/http/Subscriber.java     
  Tue Nov 03 20:13:09 2009 +0100
+++ b/tunguska/src/main/java/org/tunguska/outerspace/http/Subscriber.java     
  Tue Nov 03 20:14:03 2009 +0100
@@ -49,5 +49,6 @@
         handler.attach(response);
         CometContext cometContext = getCometContext(request);
         cometContext.addCometHandler(handler);
+        log.info("doGet performed");
     } 
 }


diff -r 4bd725ea1d74 -r 4081c660b22a 
tunguska/src/main/java/org/tunguska/innerspace/grizzly/ChannelListenerAdapter.java
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ 
b/tunguska/src/main/java/org/tunguska/innerspace/grizzly/ChannelListenerAdapter.java
        Tue Nov 03 20:14:19 2009 +0100
@@ -0,0 +1,48 @@
+/**
+This file is part of tunguska.
+
+tunguska is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or
+(at your option) any later version.
+
+tunguska is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program.  If not, see 
<http://www.opensource.org/licenses/gpl-2.0.php>.
+
+* Copyright (c) 04. November 2009
+*
+*/
+package org.tunguska.innerspace.grizzly;
+
+import com.sun.grizzly.comet.CometContext;
+import java.io.IOException;
+import org.tunguska.innerspace.channels.ChannelListener;
+
+/**
+ *
+ * @author http://blog.adam-bien.com
+ */
+public class ChannelListenerAdapter implements ChannelListener{
+
+    private CometContext cometContext;
+
+    public ChannelListenerAdapter(CometContext cometContext) {
+        this.cometContext = cometContext;
+    }
+
+
+    @Override
+    public void onArrival(String message) {
+        try {
+            this.cometContext.notify(message);
+        } catch (IOException ex) {
+           throw new IllegalStateException("Cannot delegate to the comet 
infrastructure: " +ex,ex);
+        }
+    }
+
+}


diff -r 4081c660b22a -r de973ed06410 
tunguska/src/main/webapp/WEB-INF/sun-web.xml
--- a/tunguska/src/main/webapp/WEB-INF/sun-web.xml      Tue Nov 03 20:14:19 
2009 +0100
+++ b/tunguska/src/main/webapp/WEB-INF/sun-web.xml      Tue Nov 03 20:14:38 
2009 +0100
@@ -2,6 +2,14 @@
 <!DOCTYPE sun-web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Application 
Server 9.0 Servlet 2.5//EN" 
"http://www.sun.com/software/appserver/dtds/sun-web-app_2_5-0.dtd";>
 <sun-web-app error-url="">
   <context-root>/tunguska</context-root>
+  <resource-ref>
+    <res-ref-name>jms/tunguskaFactory</res-ref-name>
+    <jndi-name>jms/tunguskaFactory</jndi-name>
+  </resource-ref>
+  <message-destination-ref>
+    <message-destination-ref-name>jms/tunguska</message-destination-ref-name>
+    <jndi-name>jms/tunguska</jndi-name>
+  </message-destination-ref>
   <class-loader delegate="true"/>
   <jsp-config>
     <property name="keepgenerated" value="true">






[tunguska~hg:19] Context root fixed

abien 11/03/2009
  • Mysql
  • Glassfish
  • Jruby
  • Rails
  • Nblogo
Terms of Use; Privacy Policy;
© 2010, Oracle Corporation and/or its affiliates
(revision 20120518.3c65429)
 
 
Close
loading
Please Confirm
Close