tuscany-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From antel...@apache.org
Subject svn commit: r608423 - in /incubator/tuscany/java/sca/modules/host-jms-activemq: ./ src/main/java/org/apache/tuscany/sca/host/jms/activemq/ src/main/resources/META-INF/services/
Date Thu, 03 Jan 2008 10:35:09 GMT
Author: antelder
Date: Thu Jan  3 02:35:08 2008
New Revision: 608423

URL: http://svn.apache.org/viewvc?rev=608423&view=rev
Log:
Update activemq host to use jms host

Added:
    incubator/tuscany/java/sca/modules/host-jms-activemq/src/main/java/org/apache/tuscany/sca/host/jms/activemq/ActiveMQJMSHost.java
  (with props)
    incubator/tuscany/java/sca/modules/host-jms-activemq/src/main/java/org/apache/tuscany/sca/host/jms/activemq/JMSResourceFactoryImpl.java
  (with props)
    incubator/tuscany/java/sca/modules/host-jms-activemq/src/main/resources/META-INF/services/org.apache.tuscany.sca.host.jms.JMSHost
Modified:
    incubator/tuscany/java/sca/modules/host-jms-activemq/pom.xml
    incubator/tuscany/java/sca/modules/host-jms-activemq/src/main/java/org/apache/tuscany/sca/host/jms/activemq/ActiveMQModuleActivator.java

Modified: incubator/tuscany/java/sca/modules/host-jms-activemq/pom.xml
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/host-jms-activemq/pom.xml?rev=608423&r1=608422&r2=608423&view=diff
==============================================================================
--- incubator/tuscany/java/sca/modules/host-jms-activemq/pom.xml (original)
+++ incubator/tuscany/java/sca/modules/host-jms-activemq/pom.xml Thu Jan  3 02:35:08 2008
@@ -25,19 +25,25 @@
         <version>1.1-incubating-SNAPSHOT</version>
         <relativePath>../pom.xml</relativePath>
     </parent>
+
     <artifactId>tuscany-host-jms-activemq</artifactId>
     <name>Apache Tuscany SCA Host JMS ActiveMQ</name>
 
-    <repositories>
-       <repository>
-          <id>apache.incubator</id>
-          <url>http://people.apache.org/repo/m2-incubating-repository</url>
-       </repository>
-    </repositories>
-
     <dependencies>
             
         <dependency>
+            <groupId>org.apache.tuscany.sca</groupId>
+            <artifactId>tuscany-binding-jms</artifactId>
+            <version>1.1-incubating-SNAPSHOT</version>
+        </dependency>
+
+        <dependency>
+           <groupId>org.apache.geronimo.specs</groupId>
+           <artifactId>geronimo-jms_1.1_spec</artifactId>
+           <version>1.1</version>
+        </dependency>         
+
+        <dependency>
             <groupId>org.apache.activemq</groupId>
             <artifactId>activemq-core</artifactId>
             <version>4.1.1</version>
@@ -70,30 +76,12 @@
         </dependency>  
 
         <dependency>
-            <groupId>org.apache.tuscany.sca</groupId>
-            <artifactId>tuscany-core-spi</artifactId>
-            <version>1.1-incubating-SNAPSHOT</version>
-        </dependency>
-
-        <dependency>
             <groupId>junit</groupId>
             <artifactId>junit</artifactId>
             <version>4.2</version>
             <scope>test</scope>
         </dependency>
         
-        <dependency>
-           <groupId>org.apache.geronimo.specs</groupId>
-           <artifactId>geronimo-jms_1.1_spec</artifactId>
-           <version>1.1</version>
-           <exclusions>
-               <exclusion>
-                   <groupId>org.apache.geronimo.specs</groupId>
-                   <artifactId>geronimo-jms_1.1_spec</artifactId>
-               </exclusion>
-           </exclusions>
-        </dependency>         
-
     </dependencies>
     
 </project>

Added: incubator/tuscany/java/sca/modules/host-jms-activemq/src/main/java/org/apache/tuscany/sca/host/jms/activemq/ActiveMQJMSHost.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/host-jms-activemq/src/main/java/org/apache/tuscany/sca/host/jms/activemq/ActiveMQJMSHost.java?rev=608423&view=auto
==============================================================================
--- incubator/tuscany/java/sca/modules/host-jms-activemq/src/main/java/org/apache/tuscany/sca/host/jms/activemq/ActiveMQJMSHost.java
(added)
+++ incubator/tuscany/java/sca/modules/host-jms-activemq/src/main/java/org/apache/tuscany/sca/host/jms/activemq/ActiveMQJMSHost.java
Thu Jan  3 02:35:08 2008
@@ -0,0 +1,33 @@
+/*
+ * 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.tuscany.sca.host.jms.activemq;
+
+import org.apache.tuscany.sca.host.jms.JMSHost;
+import org.apache.tuscany.sca.host.jms.JMSResourceFactory;
+
+public class ActiveMQJMSHost implements JMSHost {
+
+    public JMSResourceFactory createJMSResourceFactory(String connectionFactoryName, String
initialContextFactoryName, String jndiURL) {
+        return new JMSResourceFactoryImpl(connectionFactoryName, initialContextFactoryName,
jndiURL);
+    }
+    
+    
+
+}

Propchange: incubator/tuscany/java/sca/modules/host-jms-activemq/src/main/java/org/apache/tuscany/sca/host/jms/activemq/ActiveMQJMSHost.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/java/sca/modules/host-jms-activemq/src/main/java/org/apache/tuscany/sca/host/jms/activemq/ActiveMQJMSHost.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: incubator/tuscany/java/sca/modules/host-jms-activemq/src/main/java/org/apache/tuscany/sca/host/jms/activemq/ActiveMQModuleActivator.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/host-jms-activemq/src/main/java/org/apache/tuscany/sca/host/jms/activemq/ActiveMQModuleActivator.java?rev=608423&r1=608422&r2=608423&view=diff
==============================================================================
--- incubator/tuscany/java/sca/modules/host-jms-activemq/src/main/java/org/apache/tuscany/sca/host/jms/activemq/ActiveMQModuleActivator.java
(original)
+++ incubator/tuscany/java/sca/modules/host-jms-activemq/src/main/java/org/apache/tuscany/sca/host/jms/activemq/ActiveMQModuleActivator.java
Thu Jan  3 02:35:08 2008
@@ -24,17 +24,22 @@
 
 public class ActiveMQModuleActivator implements ModuleActivator {
 
-    private ActiveMQHost activeMQHost;
+    private static ActiveMQHost activeMQHost;
 
     public void start(ExtensionPointRegistry registry) {
-        activeMQHost = new ActiveMQHost();
-        activeMQHost.start();
     }
 
     public void stop(ExtensionPointRegistry registry) {
         if (activeMQHost != null) {
             activeMQHost.stop();
+            activeMQHost = null;
         }
     }
 
+    public static void startBroker() {
+        if (activeMQHost == null) {
+            activeMQHost = new ActiveMQHost();
+            activeMQHost.start();
+        }
+    }
 }

Added: incubator/tuscany/java/sca/modules/host-jms-activemq/src/main/java/org/apache/tuscany/sca/host/jms/activemq/JMSResourceFactoryImpl.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/host-jms-activemq/src/main/java/org/apache/tuscany/sca/host/jms/activemq/JMSResourceFactoryImpl.java?rev=608423&view=auto
==============================================================================
--- incubator/tuscany/java/sca/modules/host-jms-activemq/src/main/java/org/apache/tuscany/sca/host/jms/activemq/JMSResourceFactoryImpl.java
(added)
+++ incubator/tuscany/java/sca/modules/host-jms-activemq/src/main/java/org/apache/tuscany/sca/host/jms/activemq/JMSResourceFactoryImpl.java
Thu Jan  3 02:35:08 2008
@@ -0,0 +1,148 @@
+/*
+ * 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.tuscany.sca.host.jms.activemq;
+
+import java.util.Properties;
+
+import javax.jms.Connection;
+import javax.jms.ConnectionFactory;
+import javax.jms.Destination;
+import javax.jms.JMSException;
+import javax.jms.Session;
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+
+import org.apache.tuscany.sca.host.jms.JMSResourceFactory;
+
+/**
+ * Abstracts away any JMS provide specific feature from the JMS binding
+ */
+public class JMSResourceFactoryImpl implements JMSResourceFactory {
+
+    private String initialContextFactoryName = "org.apache.activemq.jndi.ActiveMQInitialContextFactory";
+    private String connectionFactoryName = "ConnectionFactory";
+    private String jndiURL = "tcp://localhost:61616";
+    
+    private Connection connection;
+    private Context context;
+    private boolean isConnectionStarted;
+
+    public JMSResourceFactoryImpl(String connectionFactoryName, String initialContextFactoryName,
String jndiURL) {
+        if (connectionFactoryName != null) {
+            this.connectionFactoryName = connectionFactoryName.trim();
+        }
+        if (initialContextFactoryName != null) {
+            this.initialContextFactoryName = initialContextFactoryName.trim();
+        }
+        if (jndiURL != null) {
+            this.jndiURL = jndiURL.trim();
+        }
+    }
+
+    /*
+     * This is a simple implementation where a connection is created per binding Ideally
the resource factory should be
+     * able to leverage the host environment to provide connection pooling if it can. E.g.
if Tuscany is running inside
+     * an AppServer Then we could leverage the JMS resources it provides
+     * 
+     * @see org.apache.tuscany.binding.jms.JMSResourceFactory#getConnection()
+     */
+    public Connection getConnection() throws NamingException, JMSException {
+        if (connection == null) {
+            createConnection();
+        }
+        return connection;
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see org.apache.tuscany.binding.jms.JMSResourceFactory#createSession()
+     */
+    public Session createSession() throws JMSException, NamingException {
+        return getConnection().createSession(false, Session.AUTO_ACKNOWLEDGE);
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see org.apache.tuscany.binding.jms.JMSResourceFactory#startConnection()
+     */
+    public void startConnection() throws JMSException, NamingException {
+        if (!isConnectionStarted) {
+            getConnection().start();
+            isConnectionStarted = true;
+        }
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see org.apache.tuscany.binding.jms.JMSResourceFactory#closeConnection()
+     */
+    public void closeConnection() throws JMSException, NamingException {
+        if (connection != null) {
+            connection.close();
+        }
+    }
+
+    public void startBroker() {
+        // ensure the broker has been started
+        ActiveMQModuleActivator.startBroker();
+    }
+
+    private void createConnection() throws NamingException, JMSException {
+        if (context == null) {
+            createInitialContext();
+        }
+        ConnectionFactory connectionFactory = (ConnectionFactory)context.lookup(connectionFactoryName);
+        connection = connectionFactory.createConnection();
+    }
+
+    private void createInitialContext() throws NamingException {
+        Properties props = new Properties();
+        props.setProperty(Context.INITIAL_CONTEXT_FACTORY, initialContextFactoryName);
+        props.setProperty(Context.PROVIDER_URL, jndiURL);
+
+        context = new InitialContext(props);
+    }
+
+    public Destination lookupDestination(String jndiName) throws NamingException {
+        if (context == null) {
+            createInitialContext();
+        }
+
+        Destination dest = null;
+
+        try {
+            dest = (Destination)context.lookup(jndiName);
+        } catch (NamingException ex) {
+
+        }
+        return dest;
+    }
+
+    /**
+     * You can create a destination in ActiveMQ (and have it appear in JNDI) by putting "dynamicQueues/"
in front of the
+     * queue name being looked up
+     */
+    public Destination createDestination(String jndiName) throws NamingException {
+        return lookupDestination("dynamicQueues/" + jndiName);
+    }
+}

Propchange: incubator/tuscany/java/sca/modules/host-jms-activemq/src/main/java/org/apache/tuscany/sca/host/jms/activemq/JMSResourceFactoryImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/java/sca/modules/host-jms-activemq/src/main/java/org/apache/tuscany/sca/host/jms/activemq/JMSResourceFactoryImpl.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/tuscany/java/sca/modules/host-jms-activemq/src/main/resources/META-INF/services/org.apache.tuscany.sca.host.jms.JMSHost
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/host-jms-activemq/src/main/resources/META-INF/services/org.apache.tuscany.sca.host.jms.JMSHost?rev=608423&view=auto
==============================================================================
--- incubator/tuscany/java/sca/modules/host-jms-activemq/src/main/resources/META-INF/services/org.apache.tuscany.sca.host.jms.JMSHost
(added)
+++ incubator/tuscany/java/sca/modules/host-jms-activemq/src/main/resources/META-INF/services/org.apache.tuscany.sca.host.jms.JMSHost
Thu Jan  3 02:35:08 2008
@@ -0,0 +1,20 @@
+# 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.
+# Implementation class for the ModuleActivator
+org.apache.tuscany.sca.host.jms.activemq.ActiveMQJMSHost
+
+



---------------------------------------------------------------------
To unsubscribe, e-mail: tuscany-commits-unsubscribe@ws.apache.org
For additional commands, e-mail: tuscany-commits-help@ws.apache.org


Mime
View raw message