incubator-aries-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lin...@apache.org
Subject svn commit: r953860 [2/3] - in /incubator/aries/sandbox/linsun/mds: ./ mds-api/ mds-api/.settings/ mds-api/src/ mds-api/src/main/ mds-api/src/main/java/ mds-api/src/main/java/org/ mds-api/src/main/java/org/apache/ mds-api/src/main/java/org/apache/aries...
Date Fri, 11 Jun 2010 20:09:33 GMT
Added: incubator/aries/sandbox/linsun/mds/mds-itest/src/test/java/org/apache/aries/mds/itests/MessageDrivenTest.java
URL: http://svn.apache.org/viewvc/incubator/aries/sandbox/linsun/mds/mds-itest/src/test/java/org/apache/aries/mds/itests/MessageDrivenTest.java?rev=953860&view=auto
==============================================================================
--- incubator/aries/sandbox/linsun/mds/mds-itest/src/test/java/org/apache/aries/mds/itests/MessageDrivenTest.java (added)
+++ incubator/aries/sandbox/linsun/mds/mds-itest/src/test/java/org/apache/aries/mds/itests/MessageDrivenTest.java Fri Jun 11 20:09:30 2010
@@ -0,0 +1,197 @@
+/*
+ * 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.aries.mds.itests;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertSame;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+import static org.ops4j.pax.exam.CoreOptions.equinox;
+import static org.ops4j.pax.exam.CoreOptions.options;
+import static org.ops4j.pax.exam.CoreOptions.systemProperty;
+
+import java.io.Serializable;
+import java.text.SimpleDateFormat;
+import java.util.Currency;
+import java.util.Hashtable;
+import java.util.Map;
+import java.util.Set;
+import java.util.TreeMap;
+
+import javax.jms.Connection;
+import javax.jms.ConnectionFactory;
+import javax.jms.Destination;
+import javax.jms.JMSException;
+import javax.jms.Message;
+import javax.jms.MessageConsumer;
+import javax.jms.MessageProducer;
+import javax.jms.ObjectMessage;
+import javax.jms.Session;
+
+import org.apache.activemq.ActiveMQConnectionFactory;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.ops4j.pax.exam.Option;
+import org.ops4j.pax.exam.junit.JUnit4TestRunner;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.ServiceReference;
+import org.osgi.service.blueprint.container.BlueprintContainer;
+import org.osgi.service.cm.Configuration;
+import org.osgi.service.cm.ConfigurationAdmin;
+
+@RunWith(JUnit4TestRunner.class)
+public class MessageDrivenTest extends AbstractIntegrationTest {
+
+    private static final String REQUEST_QUEUE_NAME = "Hello.Queue";
+    public static final String DESTINATION = "destination";
+    public static final String DESTINATION_TYPE = "destinationType";
+    private ConnectionFactory cf;
+   
+    @Before
+    public void setUp() throws Exception {
+        super.setUp();
+        cf = getOsgiService(ConnectionFactory.class);
+
+    }
+    
+    @After
+    public void tearDown() throws Exception {
+        super.tearDown();
+        cf = null;
+    }
+    
+    @Test
+    public void test() throws Exception {
+      System.out.println("got setup correctly");
+      sendMessage();
+    }
+
+    private void sendMessage() throws JMSException {
+        Connection connection = null;
+        Session session = null;
+        MessageProducer producer = null;
+        MessageConsumer consumer = null;
+        try {
+            connection = cf.createConnection();
+            connection.start();
+
+           // create request
+            Map<String, Object> request = new TreeMap<String, Object>();
+            request.put("args", new Object[]{"cheese"});
+
+            // create a new temp response queue
+            session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+            Destination responseQueue = session.createTemporaryQueue();
+
+            // Create a request messages
+            ObjectMessage requestMessage = session.createObjectMessage();
+            requestMessage.setJMSReplyTo(responseQueue);
+            requestMessage.setObject((Serializable) request);
+
+            // Send the request message
+            producer = session.createProducer(session.createQueue(REQUEST_QUEUE_NAME));
+            producer.send(requestMessage);
+
+            // wait for the response message
+            consumer = session.createConsumer(responseQueue);
+            Message message = consumer.receive(1000);
+
+            // verify message
+            assertNotNull("Did not get a response message", message);
+            assertTrue("Response message is not an ObjectMessage", message instanceof ObjectMessage);
+            ObjectMessage responseMessage = (ObjectMessage) message;
+            if (responseMessage != null) {
+                Serializable object = responseMessage.getObject();
+                assertNotNull("Response ObjectMessage contains a null object");
+                assertTrue("Response ObjectMessage does not contain an instance of Map", object instanceof Map);
+                Map response = (Map) object;
+    
+                // process results
+                String returnValue = (String) response.get("return");
+                assertEquals("test-cheese", returnValue);
+                System.out.println("return value is " + returnValue);
+            }
+        } finally {
+            if (consumer != null) {
+                consumer.close();
+            }
+            if (producer != null) {
+                producer.close();
+            }
+            if (session != null) {
+                session.close();
+            }
+            if (connection != null) {
+                connection.close();
+            }
+        }
+    }
+    
+    @org.ops4j.pax.exam.junit.Configuration
+    public static Option[] configuration() {
+        Option[] options = options(
+            // Log
+            mavenBundle("org.ops4j.pax.logging", "pax-logging-api"),
+            mavenBundle("org.ops4j.pax.logging", "pax-logging-service"),
+            // Felix Config Admin
+            mavenBundle("org.apache.felix", "org.apache.felix.configadmin"),
+            // Felix mvn url handler
+            mavenBundle("org.ops4j.pax.url", "pax-url-mvn"),
+
+
+            // this is how you set the default log level when using pax logging (logProfile)
+            systemProperty("org.ops4j.pax.logging.DefaultServiceLog.level").value("DEBUG"),
+
+            // Bundles
+            mavenBundle("org.apache.aries", "org.apache.aries.util"),
+            mavenBundle("asm", "asm-all"),
+            mavenBundle("org.apache.aries.blueprint", "org.apache.aries.blueprint"),
+            mavenBundle("org.apache.geronimo.specs", "geronimo-annotation_1.0_spec"),
+            mavenBundle("org.apache.geronimo.specs", "geronimo-jta_1.1_spec"),
+            mavenBundle("org.apache.geronimo.specs", "geronimo-j2ee-management_1.1_spec"),
+            mavenBundle("org.apache.activemq", "kahadb"),
+            mavenBundle("org.apache.activemq", "activemq-ra"),
+            mavenBundle("org.apache.activemq", "activemq-core"),
+            mavenBundle("org.apache.geronimo.specs", "geronimo-jms_1.1_spec"),
+            mavenBundle("org.apache.geronimo.specs", "geronimo-j2ee-connector_1.5_spec"),
+            mavenBundle("org.apache.geronimo.components", "geronimo-connector"),
+            mavenBundle("org.apache.geronimo.components", "geronimo-transaction"),
+            mavenBundle("org.apache.xbean", "xbean-asm-shaded"),
+            mavenBundle("org.apache.xbean", "xbean-finder-shaded"),
+            mavenBundle("org.apache.xbean", "xbean-reflect"),
+            mavenBundle("org.apache.xbean", "xbean-naming"),
+            mavenBundle("org.apache.aries.mds", "org.apache.aries.mds.ra"),
+            mavenBundle("org.apache.aries.mds", "org.apache.aries.mds.ra.activemq"),
+            mavenBundle("org.apache.aries.mds", "org.apache.aries.mds.api"),
+            mavenBundle("org.apache.aries.mds", "org.apache.aries.mds.impl"),
+            mavenBundle("org.apache.aries.mds", "org.apache.aries.mds.sample"),
+            mavenBundle("org.osgi", "org.osgi.compendium"),
+            //org.ops4j.pax.exam.container.def.PaxRunnerOptions.vmOption("-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005"),
+
+            equinox().version("3.5.0")
+        );
+        options = updateOptions(options);
+        return options;
+    }
+
+}

Propchange: incubator/aries/sandbox/linsun/mds/mds-itest/src/test/java/org/apache/aries/mds/itests/MessageDrivenTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/aries/sandbox/linsun/mds/mds-itest/src/test/java/org/apache/aries/mds/itests/MessageDrivenTest.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: incubator/aries/sandbox/linsun/mds/mds-itest/src/test/java/org/apache/aries/mds/itests/MessageDrivenTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: incubator/aries/sandbox/linsun/mds/mds-ra-activemq/.classpath
URL: http://svn.apache.org/viewvc/incubator/aries/sandbox/linsun/mds/mds-ra-activemq/.classpath?rev=953860&view=auto
==============================================================================
--- incubator/aries/sandbox/linsun/mds/mds-ra-activemq/.classpath (added)
+++ incubator/aries/sandbox/linsun/mds/mds-ra-activemq/.classpath Fri Jun 11 20:09:30 2010
@@ -0,0 +1,38 @@
+<classpath>
+  <classpathentry kind="src" path="src/main/java" including="**/*.java"/>
+  <classpathentry kind="src" path="src/main/resources" excluding="**/*.java"/>
+  <classpathentry kind="src" path="target/maven-shared-archive-resources" excluding="**/*.java"/>
+  <classpathentry kind="output" path="target/classes"/>
+  <classpathentry kind="var" path="M2_REPO/javax/servlet/servlet-api/2.3/servlet-api-2.3.jar"/>
+  <classpathentry kind="var" path="M2_REPO/org/apache/activemq/activeio-core/3.1.2/activeio-core-3.1.2.jar"/>
+  <classpathentry kind="var" path="M2_REPO/org/apache/activemq/activemq-core/5.3.1/activemq-core-5.3.1.jar"/>
+  <classpathentry kind="var" path="M2_REPO/org/apache/activemq/protobuf/activemq-protobuf/1.0/activemq-protobuf-1.0.jar"/>
+  <classpathentry kind="var" path="M2_REPO/org/apache/activemq/activemq-ra/5.3.1/activemq-ra-5.3.1.jar"/>
+  <classpathentry kind="var" path="M2_REPO/aopalliance/aopalliance/1.0/aopalliance-1.0.jar"/>
+  <classpathentry kind="var" path="M2_REPO/avalon-framework/avalon-framework/4.1.3/avalon-framework-4.1.3.jar"/>
+  <classpathentry kind="var" path="M2_REPO/commons-logging/commons-logging/1.1/commons-logging-1.1.jar"/>
+  <classpathentry kind="var" path="M2_REPO/commons-logging/commons-logging-api/1.1/commons-logging-api-1.1.jar"/>
+  <classpathentry kind="var" path="M2_REPO/commons-net/commons-net/2.0/commons-net-2.0.jar"/>
+  <classpathentry kind="var" path="M2_REPO/org/apache/geronimo/components/geronimo-connector/2.1.4/geronimo-connector-2.1.4.jar"/>
+  <classpathentry kind="var" path="M2_REPO/org/apache/geronimo/specs/geronimo-j2ee-connector_1.5_spec/2.0.0/geronimo-j2ee-connector_1.5_spec-2.0.0.jar"/>
+  <classpathentry kind="var" path="M2_REPO/org/apache/geronimo/specs/geronimo-j2ee-management_1.1_spec/1.0.1/geronimo-j2ee-management_1.1_spec-1.0.1.jar"/>
+  <classpathentry kind="var" path="M2_REPO/org/apache/geronimo/specs/geronimo-jms_1.1_spec/1.1.1/geronimo-jms_1.1_spec-1.1.1.jar"/>
+  <classpathentry kind="var" path="M2_REPO/org/apache/geronimo/specs/geronimo-jta_1.1_spec/1.1.1/geronimo-jta_1.1_spec-1.1.1.jar"/>
+  <classpathentry kind="var" path="M2_REPO/org/apache/geronimo/components/geronimo-transaction/2.1.4/geronimo-transaction-2.1.4.jar"/>
+  <classpathentry kind="var" path="M2_REPO/junit/junit/4.8.1/junit-4.8.1.jar"/>
+  <classpathentry kind="var" path="M2_REPO/org/apache/activemq/kahadb/5.3.1/kahadb-5.3.1.jar"/>
+  <classpathentry kind="var" path="M2_REPO/log4j/log4j/1.2.12/log4j-1.2.12.jar"/>
+  <classpathentry kind="var" path="M2_REPO/logkit/logkit/1.0.1/logkit-1.0.1.jar"/>
+  <classpathentry kind="var" path="M2_REPO/org/apache/aries/mds/org.apache.aries.mds.ra/0.2-incubating-SNAPSHOT/org.apache.aries.mds.ra-0.2-incubating-SNAPSHOT.jar"/>
+  <classpathentry kind="var" path="M2_REPO/org/osgi/org.osgi.compendium/4.2.0/org.osgi.compendium-4.2.0.jar"/>
+  <classpathentry kind="var" path="M2_REPO/org/osgi/org.osgi.core/4.2.0/org.osgi.core-4.2.0.jar"/>
+  <classpathentry kind="var" path="M2_REPO/org/eclipse/osgi/3.5.0.v20090520/osgi-3.5.0.v20090520.jar"/>
+  <classpathentry kind="var" path="M2_REPO/org/slf4j/slf4j-api/1.5.11/slf4j-api-1.5.11.jar"/>
+  <classpathentry kind="var" path="M2_REPO/org/slf4j/slf4j-simple/1.5.11/slf4j-simple-1.5.11.jar"/>
+  <classpathentry kind="var" path="M2_REPO/org/springframework/spring-beans/2.5.6/spring-beans-2.5.6.jar"/>
+  <classpathentry kind="var" path="M2_REPO/org/springframework/spring-context/2.5.6/spring-context-2.5.6.jar"/>
+  <classpathentry kind="var" path="M2_REPO/org/springframework/spring-core/2.5.6/spring-core-2.5.6.jar"/>
+  <classpathentry kind="var" path="M2_REPO/org/springframework/osgi/spring-osgi-core/1.2.1/spring-osgi-core-1.2.1.jar"/>
+  <classpathentry kind="var" path="M2_REPO/org/springframework/osgi/spring-osgi-io/1.2.1/spring-osgi-io-1.2.1.jar"/>
+  <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+</classpath>
\ No newline at end of file

Added: incubator/aries/sandbox/linsun/mds/mds-ra-activemq/.project
URL: http://svn.apache.org/viewvc/incubator/aries/sandbox/linsun/mds/mds-ra-activemq/.project?rev=953860&view=auto
==============================================================================
--- incubator/aries/sandbox/linsun/mds/mds-ra-activemq/.project (added)
+++ incubator/aries/sandbox/linsun/mds/mds-ra-activemq/.project Fri Jun 11 20:09:30 2010
@@ -0,0 +1,13 @@
+<projectDescription>
+  <name>org.apache.aries.mds.ra.activemq</name>
+  <comment>This bundle contains the Message driven Service Implementation using ActiveMQ as the provider of JMS broker and resource adapter. NO_M2ECLIPSE_SUPPORT: Project files created with the maven-eclipse-plugin are not supported in M2Eclipse.</comment>
+  <projects/>
+  <buildSpec>
+    <buildCommand>
+      <name>org.eclipse.jdt.core.javabuilder</name>
+    </buildCommand>
+  </buildSpec>
+  <natures>
+    <nature>org.eclipse.jdt.core.javanature</nature>
+  </natures>
+</projectDescription>
\ No newline at end of file

Added: incubator/aries/sandbox/linsun/mds/mds-ra-activemq/.settings/org.eclipse.jdt.core.prefs
URL: http://svn.apache.org/viewvc/incubator/aries/sandbox/linsun/mds/mds-ra-activemq/.settings/org.eclipse.jdt.core.prefs?rev=953860&view=auto
==============================================================================
--- incubator/aries/sandbox/linsun/mds/mds-ra-activemq/.settings/org.eclipse.jdt.core.prefs (added)
+++ incubator/aries/sandbox/linsun/mds/mds-ra-activemq/.settings/org.eclipse.jdt.core.prefs Fri Jun 11 20:09:30 2010
@@ -0,0 +1,11 @@
+#Wed May 26 10:26:25 EDT 2010
+encoding//src/main/java=${project.build.sourceEncoding}
+org.eclipse.jdt.core.compiler.compliance=1.5
+encoding//src/main/resources=${project.build.sourceEncoding}
+encoding//src/test/resources=${project.build.sourceEncoding}
+encoding//src/test/java=${project.build.sourceEncoding}
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
+encoding//src/test/filtered-resources=${project.build.sourceEncoding}
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.source=1.5
+encoding//src/main/filtered-resources=${project.build.sourceEncoding}

Added: incubator/aries/sandbox/linsun/mds/mds-ra-activemq/pom.xml
URL: http://svn.apache.org/viewvc/incubator/aries/sandbox/linsun/mds/mds-ra-activemq/pom.xml?rev=953860&view=auto
==============================================================================
--- incubator/aries/sandbox/linsun/mds/mds-ra-activemq/pom.xml (added)
+++ incubator/aries/sandbox/linsun/mds/mds-ra-activemq/pom.xml Fri Jun 11 20:09:30 2010
@@ -0,0 +1,115 @@
+
+	<!--
+		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.
+	-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+	<modelVersion>4.0.0</modelVersion>
+	<parent>
+		<groupId>org.apache.aries.mds</groupId>
+		<artifactId>blueprint</artifactId>
+		<version>0.2-incubating-SNAPSHOT</version>
+	</parent>
+
+	<artifactId>org.apache.aries.mds.ra.activemq</artifactId>
+	<packaging>bundle</packaging>
+	<name>Apache Aries Message Driven Service ActiveMQ Resource Adapter </name>
+	<description>
+      This bundle contains the Message driven Service Implementation using ActiveMQ as the provider of JMS broker and resource adapter
+  </description>
+
+	<properties>
+		<aries.osgi.export.pkg>
+			org.apache.aries.mds.ra.activemq
+      </aries.osgi.export.pkg>
+		<aries.osgi.import>
+			!org.apache.aries.mds.ra.activemq.*,
+			*
+      </aries.osgi.import>
+	</properties>
+
+	<dependencies>
+		<dependency>
+			<groupId>org.apache.aries.mds</groupId>
+			<artifactId>org.apache.aries.mds.ra</artifactId>
+			<scope>provided</scope>
+		</dependency>
+		<dependency>
+			<groupId>org.osgi</groupId>
+			<artifactId>org.osgi.core</artifactId>
+			<scope>provided</scope>
+		</dependency>
+		<dependency>
+			<groupId>org.osgi</groupId>
+			<artifactId>org.osgi.compendium</artifactId>
+			<scope>provided</scope>
+		</dependency>
+		<dependency>
+			<groupId>org.eclipse</groupId>
+			<artifactId>osgi</artifactId>
+			<scope>provided</scope>
+		</dependency>
+		<dependency>
+			<groupId>org.slf4j</groupId>
+			<artifactId>slf4j-api</artifactId>
+		</dependency>
+		<dependency>
+			<groupId>org.slf4j</groupId>
+			<artifactId>slf4j-simple</artifactId>
+			<scope>test</scope>
+		</dependency>
+
+		<dependency>
+			<groupId>org.apache.geronimo.specs</groupId>
+			<artifactId>geronimo-jms_1.1_spec</artifactId>
+			<scope>provided</scope>
+		</dependency>
+		<dependency>
+			<groupId>org.apache.geronimo.specs</groupId>
+			<artifactId>geronimo-j2ee-connector_1.5_spec</artifactId>
+			<scope>provided</scope>
+		</dependency>
+
+		<dependency>
+			<groupId>org.apache.activemq</groupId>
+			<artifactId>activemq-ra</artifactId>
+		</dependency>
+
+		<dependency>
+			<groupId>org.apache.activemq</groupId>
+			<artifactId>activemq-core</artifactId>
+		</dependency>
+
+		<dependency>
+			<groupId>org.apache.geronimo.components</groupId>
+			<artifactId>geronimo-connector</artifactId>
+		</dependency>
+		<dependency>
+			<groupId>org.apache.geronimo.components</groupId>
+			<artifactId>geronimo-transaction</artifactId>
+		</dependency>
+
+
+	</dependencies>
+
+	<build>
+		<resources>
+			<resource>
+				<directory>src/main/resources</directory>
+				<filtering>true</filtering>
+			</resource>
+		</resources>
+	</build>
+</project>

Propchange: incubator/aries/sandbox/linsun/mds/mds-ra-activemq/pom.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/aries/sandbox/linsun/mds/mds-ra-activemq/pom.xml
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: incubator/aries/sandbox/linsun/mds/mds-ra-activemq/pom.xml
------------------------------------------------------------------------------
    svn:mime-type = text/xml

Added: incubator/aries/sandbox/linsun/mds/mds-ra-activemq/src/main/java/org/apache/aries/mds/ra/URISupport.java
URL: http://svn.apache.org/viewvc/incubator/aries/sandbox/linsun/mds/mds-ra-activemq/src/main/java/org/apache/aries/mds/ra/URISupport.java?rev=953860&view=auto
==============================================================================
--- incubator/aries/sandbox/linsun/mds/mds-ra-activemq/src/main/java/org/apache/aries/mds/ra/URISupport.java (added)
+++ incubator/aries/sandbox/linsun/mds/mds-ra-activemq/src/main/java/org/apache/aries/mds/ra/URISupport.java Fri Jun 11 20:09:30 2010
@@ -0,0 +1,311 @@
+/* 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.aries.mds.ra;
+
+
+import java.io.UnsupportedEncodingException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.URLDecoder;
+import java.net.URLEncoder;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+* Swiped verbatim from ActiveMQ... the URI kings.
+*
+* URI relativize(URI, URI) added afterwards to deal with the
+* non-functional URI.relativize(URI) method
+*/
+public class URISupport {
+
+
+   public static class CompositeData {
+       String scheme;
+       String path;
+       URI components[];
+       Map parameters;
+       String fragment;
+       public String host;
+
+       public URI[] getComponents() {
+           return components;
+       }
+       public String getFragment() {
+           return fragment;
+       }
+       public Map getParameters() {
+           return parameters;
+       }
+       public String getScheme() {
+           return scheme;
+       }
+       public String getPath() {
+           return path;
+       }
+       public String getHost() {
+           return host;
+       }
+
+       public URI toURI() throws URISyntaxException {
+           StringBuffer sb = new StringBuffer();
+           if( scheme!=null ) {
+               sb.append(scheme);
+               sb.append(':');
+           }
+
+           if( host!=null && host.length()!=0 ) {
+               sb.append(host);
+           } else {
+               sb.append('(');
+               for (int i = 0; i < components.length; i++) {
+                   if( i!=0 )
+                       sb.append(',');
+                   sb.append(components[i].toString());
+               }
+               sb.append(')');
+           }
+
+           if( path !=null ) {
+               sb.append('/');
+               sb.append(path);
+           }
+           if(!parameters.isEmpty()) {
+               sb.append("?");
+               sb.append(createQueryString(parameters));
+           }
+           if( fragment!=null ) {
+               sb.append("#");
+               sb.append(fragment);
+           }
+           return new URI(sb.toString());
+       }
+   }
+
+   public static Map<String, String> parseQuery(String uri) throws URISyntaxException{
+       try{
+           Map<String, String> rc = new LinkedHashMap<String,String>();
+           if(uri!=null){
+               String[] parameters=uri.split("&");
+               for(int i=0;i<parameters.length;i++){
+                   int p=parameters[i].indexOf("=");
+                   if(p>=0){
+                       String name= URLDecoder.decode(parameters[i].substring(0,p),"UTF-8");
+                       String value=URLDecoder.decode(parameters[i].substring(p+1),"UTF-8");
+                       rc.put(name,value);
+                   }else{
+                       rc.put(parameters[i],null);
+                   }
+               }
+           }
+           return rc;
+       }catch(UnsupportedEncodingException e){
+           throw (URISyntaxException) new URISyntaxException(e.toString(),"Invalid encoding").initCause(e);
+       }
+   }
+
+   public static Map<String, String> parseParamters(URI uri) throws URISyntaxException {
+       return uri.getQuery()==null ? Collections.EMPTY_MAP : parseQuery(stripPrefix(uri.getQuery(), "?"));
+   }
+
+   /**
+    * Removes any URI query from the given uri
+    */
+   public static URI removeQuery(URI uri) throws URISyntaxException {
+       return createURIWithQuery(uri, null);
+   }
+
+   /**
+    * Creates a URI with the given query
+    */
+   public static URI createURIWithQuery(URI uri, String query) throws URISyntaxException {
+       return new URI(uri.getScheme(), uri.getUserInfo(), uri.getHost(), uri.getPort(), uri.getPath(), query, uri.getFragment());
+   }
+
+   public static CompositeData parseComposite(URI uri) throws URISyntaxException {
+
+       CompositeData rc = new CompositeData();
+       rc.scheme = uri.getScheme();
+       String ssp = stripPrefix(uri.getSchemeSpecificPart().trim(), "//").trim();
+
+       parseComposite(uri, rc, ssp);
+
+       rc.fragment = uri.getFragment();
+       return rc;
+   }
+
+   private static void parseComposite(URI uri, CompositeData rc, String ssp) throws URISyntaxException {
+       String componentString;
+       String params;
+
+       if(!checkParenthesis(ssp)){
+           throw new URISyntaxException(uri.toString(), "Not a matching number of '(' and ')' parenthesis");
+       }
+
+       int p;
+       int intialParen = ssp.indexOf("(");
+       if( intialParen==0 ) {
+           rc.host = ssp.substring(0, intialParen);
+           p = rc.host.indexOf("/");
+           if( p >= 0 ) {
+               rc.path = rc.host.substring(p);
+               rc.host = rc.host.substring(0,p);
+           }
+           p = ssp.lastIndexOf(")");
+           componentString = ssp.substring(intialParen+1,p);
+           params = ssp.substring(p+1).trim();
+
+       } else {
+           componentString = ssp;
+           params="";
+       }
+
+       String components[] = splitComponents(componentString);
+       rc.components=new URI[components.length];
+       for (int i = 0; i < components.length; i++) {
+           rc.components[i] = new URI(components[i].trim());
+       }
+
+       p = params.indexOf("?");
+       if( p >= 0 ) {
+           if( p > 0) {
+               rc.path = stripPrefix(params.substring(0, p), "/");
+           }
+           rc.parameters = parseQuery(params.substring(p+1));
+       } else {
+           if( params.length() > 0 )
+               rc.path = stripPrefix(params, "/");
+           rc.parameters = new LinkedHashMap();
+       }
+   }
+
+   private static String[] splitComponents(String str) {
+       ArrayList<String> l = new ArrayList<String>();
+
+       int last=0;
+       int depth = 0;
+       char chars[] = str.toCharArray();
+       for( int i=0; i < chars.length; i ++ ) {
+           switch( chars[i] ) {
+           case '(':
+               depth++;
+               break;
+           case ')':
+               depth--;
+               break;
+           case ',':
+               if( depth == 0 ) {
+                   String s = str.substring(last, i);
+                   l.add(s);
+                   last=i+1;
+               }
+           }
+       }
+
+       String s = str.substring(last);
+       if( s.length() !=0 )
+           l.add(s);
+
+       String rc[] = new String[l.size()];
+       l.toArray(rc);
+       return rc;
+   }
+
+   public static String stripPrefix(String value, String prefix) {
+       if( value.startsWith(prefix) )
+           return value.substring(prefix.length());
+       return value;
+   }
+
+   public static URI stripScheme(URI uri) throws URISyntaxException {
+       return new URI(stripPrefix(uri.getRawSchemeSpecificPart().trim(), "//"));
+   }
+
+   public static String createQueryString(Map options) throws URISyntaxException {
+       try {
+           if(options.size()>0) {
+               StringBuffer rc = new StringBuffer();
+               boolean first=true;
+               for (Iterator iter = options.keySet().iterator(); iter.hasNext();) {
+                   if( first )
+                       first=false;
+                   else
+                       rc.append("&");
+
+                   String key = (String) iter.next();
+                   String value = (String)options.get(key);
+                   rc.append(URLEncoder.encode(key, "UTF-8"));
+                   rc.append("=");
+                   rc.append(URLEncoder.encode(value, "UTF-8"));
+               }
+               return rc.toString();
+           } else {
+               return "";
+           }
+       } catch (UnsupportedEncodingException e) {
+           throw (URISyntaxException)new URISyntaxException(e.toString(), "Invalid encoding").initCause(e);
+       }
+   }
+
+   /**
+    * Creates a URI from the original URI and the remaining paramaters
+    * @throws URISyntaxException
+    */
+   public static URI createRemainingURI(URI originalURI, Map params) throws URISyntaxException {
+       String s = createQueryString(params);
+       if( s.length()==0 )
+           s = null;
+       return createURIWithQuery(originalURI, s);
+   }
+
+   static public URI changeScheme(URI bindAddr, String scheme) throws URISyntaxException {
+       return new URI(scheme, bindAddr.getUserInfo(), bindAddr.getHost(), bindAddr.getPort(), bindAddr.getPath(), bindAddr.getQuery(), bindAddr.getFragment());
+   }
+
+   public static boolean checkParenthesis(String str){
+       boolean result=true;
+       if(str!=null){
+           int open=0;
+           int closed=0;
+
+           int i=0;
+           while((i=str.indexOf('(',i)) >=0 ){
+               i++;
+               open++;
+           }
+           i=0;
+           while((i=str.indexOf(')',i)) >=0 ){
+               i++;
+               closed++;
+           }
+           result = open == closed;
+       }
+       return result;
+   }
+
+   public int indexOfParenthesisMatch(String str){
+       int result = -1;
+
+       return result;
+   }
+}
+

Propchange: incubator/aries/sandbox/linsun/mds/mds-ra-activemq/src/main/java/org/apache/aries/mds/ra/URISupport.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/aries/sandbox/linsun/mds/mds-ra-activemq/src/main/java/org/apache/aries/mds/ra/URISupport.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: incubator/aries/sandbox/linsun/mds/mds-ra-activemq/src/main/java/org/apache/aries/mds/ra/URISupport.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: incubator/aries/sandbox/linsun/mds/mds-ra-activemq/src/main/java/org/apache/aries/mds/ra/activemq/ActiveMQ5Factory.java
URL: http://svn.apache.org/viewvc/incubator/aries/sandbox/linsun/mds/mds-ra-activemq/src/main/java/org/apache/aries/mds/ra/activemq/ActiveMQ5Factory.java?rev=953860&view=auto
==============================================================================
--- incubator/aries/sandbox/linsun/mds/mds-ra-activemq/src/main/java/org/apache/aries/mds/ra/activemq/ActiveMQ5Factory.java (added)
+++ incubator/aries/sandbox/linsun/mds/mds-ra-activemq/src/main/java/org/apache/aries/mds/ra/activemq/ActiveMQ5Factory.java Fri Jun 11 20:09:30 2010
@@ -0,0 +1,76 @@
+/**
+ *
+ * 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.aries.mds.ra.activemq;
+
+import org.apache.activemq.broker.BrokerFactory;
+import org.apache.activemq.broker.BrokerFactoryHandler;
+import org.apache.activemq.broker.BrokerService;
+import org.apache.activemq.store.jdbc.JDBCPersistenceAdapter;
+import org.apache.activemq.store.memory.MemoryPersistenceAdapter;
+
+import javax.naming.Context;
+import javax.naming.NamingException;
+import javax.sql.DataSource;
+import java.net.URI;
+import java.util.Map;
+import java.util.Properties;
+
+public class ActiveMQ5Factory implements BrokerFactoryHandler {
+    private static final ThreadLocal<Properties> threadProperties = new ThreadLocal<Properties>();
+
+    public static void setThreadProperties(Properties value) {
+        threadProperties.set(value);
+    }
+
+    public BrokerService createBroker(URI brokerURI) throws Exception {
+        URI uri = new URI(brokerURI.getRawSchemeSpecificPart());
+        BrokerService broker = BrokerFactory.createBroker(uri);
+
+        Properties properties = getLowerCaseProperties();
+
+        Object value = properties.get("datasource");
+        if (value instanceof String && value.toString().length() == 0) {
+            value = null;
+        }
+
+        if (value == null) {
+            MemoryPersistenceAdapter persistenceAdapter = new MemoryPersistenceAdapter();
+            broker.setPersistenceAdapter(persistenceAdapter);
+        }
+
+        return broker;
+    }
+
+    private Properties getLowerCaseProperties() {
+        final Properties properties = threadProperties.get();
+        final Properties newProperties = new Properties();
+        if (properties != null) {
+            Object key;
+            for (Map.Entry<Object, Object> entry : properties.entrySet()) {
+                key = entry.getKey();
+                if (key instanceof String) {
+                    key = ((String) key).toLowerCase();
+                }
+                newProperties.put(key, entry.getValue());
+            }
+        }
+        return newProperties;
+    }
+
+
+}
\ No newline at end of file

Propchange: incubator/aries/sandbox/linsun/mds/mds-ra-activemq/src/main/java/org/apache/aries/mds/ra/activemq/ActiveMQ5Factory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/aries/sandbox/linsun/mds/mds-ra-activemq/src/main/java/org/apache/aries/mds/ra/activemq/ActiveMQ5Factory.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: incubator/aries/sandbox/linsun/mds/mds-ra-activemq/src/main/java/org/apache/aries/mds/ra/activemq/ActiveMQ5Factory.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: incubator/aries/sandbox/linsun/mds/mds-ra-activemq/src/main/java/org/apache/aries/mds/ra/activemq/ActiveMQFactory.java
URL: http://svn.apache.org/viewvc/incubator/aries/sandbox/linsun/mds/mds-ra-activemq/src/main/java/org/apache/aries/mds/ra/activemq/ActiveMQFactory.java?rev=953860&view=auto
==============================================================================
--- incubator/aries/sandbox/linsun/mds/mds-ra-activemq/src/main/java/org/apache/aries/mds/ra/activemq/ActiveMQFactory.java (added)
+++ incubator/aries/sandbox/linsun/mds/mds-ra-activemq/src/main/java/org/apache/aries/mds/ra/activemq/ActiveMQFactory.java Fri Jun 11 20:09:30 2010
@@ -0,0 +1,184 @@
+/**
+ *
+ * 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.aries.mds.ra.activemq;
+
+import org.apache.activemq.broker.BrokerService;
+import org.apache.activemq.util.FactoryFinder;
+
+import java.io.BufferedInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.net.URI;
+import java.util.Properties;
+import java.util.concurrent.ConcurrentHashMap;
+
+public class ActiveMQFactory {
+
+    private static final Method setThreadProperties;
+    private static final Method createBroker;
+    private static final Object instance;
+
+    private static Class clazz;
+    private static String brokerPrefix;
+
+    static {
+
+        try {
+            MyObjectFactory objectFactory = new MyObjectFactory();
+            FactoryFinder.setObjectFactory(objectFactory);
+            
+            clazz = Class.forName("org.apache.aries.mds.ra.activemq.ActiveMQ5Factory");
+            brokerPrefix = "amq5factory:";
+        } catch (java.lang.Throwable t1) {
+            throw new RuntimeException("Unable to load ActiveMQ5Factory");
+        }
+
+        try {
+            instance = clazz.newInstance();
+        } catch (InstantiationException e) {
+            throw new RuntimeException("Unable to create ActiveMQFactory instance");
+        } catch (IllegalAccessException e) {
+            throw new RuntimeException("Unable to access ActiveMQFactory instance");
+        }
+
+        try {
+            setThreadProperties = clazz.getDeclaredMethod("setThreadProperties", new Class[]{Properties.class});
+        } catch (NoSuchMethodException e) {
+            throw new RuntimeException("Unable to create ActiveMQFactory setThreadProperties method");
+        }
+
+        try {
+            createBroker = clazz.getDeclaredMethod("createBroker", new Class[]{URI.class});
+        } catch (NoSuchMethodException e) {
+            throw new RuntimeException("Unable to create ActiveMQFactory setThreadProperties method");
+        }
+    }
+
+    /**
+     * Returns the prefix metafile name of the poperties file that ActiveMQ should be
+     * provided with. This file is located at META-INF/services/org/apache/activemq/broker/
+     * and defines the BrokerFactoryHandler to load.
+     * @return String name - will be either 'amq5factory:' or 'amq4factory:' - note the trailing ':'
+     */
+    public static String getBrokerMetaFile() {
+        return brokerPrefix;
+    }
+
+    public static void setThreadProperties(final Properties p) {
+        try {
+            setThreadProperties.invoke(instance, p);
+        } catch (IllegalAccessException e) {
+            throw new RuntimeException("ActiveMQFactory.setThreadProperties.IllegalAccessException", e);
+        } catch (IllegalArgumentException e) {
+            throw new RuntimeException("ActiveMQFactory.setThreadProperties.IllegalArgumentException", e);
+        } catch (InvocationTargetException e) {
+            throw new RuntimeException("ActiveMQFactory.setThreadProperties.InvocationTargetException", e);
+        }
+    }
+
+    public BrokerService createBroker(final URI brokerURI) throws Exception {
+        try {
+            return (BrokerService) createBroker.invoke(instance, brokerURI);
+        } catch (IllegalAccessException e) {
+            throw new Exception("ActiveMQFactory.createBroker.IllegalAccessException", e);
+        } catch (IllegalArgumentException e) {
+            throw new Exception("ActiveMQFactory.createBroker.IllegalArgumentException", e);
+        } catch (InvocationTargetException e) {
+            throw new Exception("ActiveMQFactory.createBroker.InvocationTargetException", e);
+        }
+    }
+    
+    protected static class MyObjectFactory implements org.apache.activemq.util.FactoryFinder.ObjectFactory {
+
+        final ConcurrentHashMap<String, Class> classMap = new ConcurrentHashMap<String, Class>();
+
+        public Object create(final String path) throws InstantiationException, IllegalAccessException, ClassNotFoundException, IOException {
+            Class clazz = classMap.get(path);
+            if (clazz == null) {
+                clazz = loadClass(loadProperties(path));
+                classMap.put(path, clazz);
+            }
+            return clazz.newInstance();
+        }
+
+        static public Class loadClass(Properties properties) throws ClassNotFoundException, IOException {
+
+            String className = properties.getProperty("class");
+            if (className == null) {
+                throw new IOException("Expected property is missing: class");
+            }
+            Class clazz = null;
+            ClassLoader loader = Thread.currentThread().getContextClassLoader();
+
+            if (loader != null) {
+                try {
+                    clazz = loader.loadClass(className);
+                } catch (ClassNotFoundException e) {
+                    // ignore
+                }
+            }
+            
+            if (clazz == null) {
+                loader = MyObjectFactory.class.getClassLoader();
+                try {
+                    clazz = loader.loadClass(className);
+                } catch (ClassNotFoundException e) {
+                    // ignore
+                }
+            }
+            if (clazz == null) {
+                clazz = FactoryFinder.class.getClassLoader().loadClass(className);
+            }
+
+            return clazz;
+        }
+
+        static public Properties loadProperties(String uri) throws IOException {
+            // lets try the thread context class loader first
+            ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
+            InputStream in = classLoader.getResourceAsStream(uri);
+            
+            if (in == null) {
+                in = MyObjectFactory.class.getClassLoader().getResourceAsStream(uri);
+            }
+            
+            if (in == null) {
+                in = FactoryFinder.class.getClassLoader().getResourceAsStream(uri);
+                if (in == null) {
+                    throw new IOException("Could not find factory class for resource: " + uri);
+                }
+            }
+
+            // lets load the file
+            BufferedInputStream reader = null;
+            try {
+                reader = new BufferedInputStream(in);
+                Properties properties = new Properties();
+                properties.load(reader);
+                return properties;
+            } finally {
+                try {
+                    reader.close();
+                } catch (Exception e) {
+                }
+            }
+        }
+    }
+}

Propchange: incubator/aries/sandbox/linsun/mds/mds-ra-activemq/src/main/java/org/apache/aries/mds/ra/activemq/ActiveMQFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/aries/sandbox/linsun/mds/mds-ra-activemq/src/main/java/org/apache/aries/mds/ra/activemq/ActiveMQFactory.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: incubator/aries/sandbox/linsun/mds/mds-ra-activemq/src/main/java/org/apache/aries/mds/ra/activemq/ActiveMQFactory.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: incubator/aries/sandbox/linsun/mds/mds-ra-activemq/src/main/java/org/apache/aries/mds/ra/activemq/ActiveMQResourceAdapterFacade.java
URL: http://svn.apache.org/viewvc/incubator/aries/sandbox/linsun/mds/mds-ra-activemq/src/main/java/org/apache/aries/mds/ra/activemq/ActiveMQResourceAdapterFacade.java?rev=953860&view=auto
==============================================================================
--- incubator/aries/sandbox/linsun/mds/mds-ra-activemq/src/main/java/org/apache/aries/mds/ra/activemq/ActiveMQResourceAdapterFacade.java (added)
+++ incubator/aries/sandbox/linsun/mds/mds-ra-activemq/src/main/java/org/apache/aries/mds/ra/activemq/ActiveMQResourceAdapterFacade.java Fri Jun 11 20:09:30 2010
@@ -0,0 +1,155 @@
+/**
+*
+* 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.aries.mds.ra.activemq;
+
+
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.Properties;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+
+import javax.resource.spi.BootstrapContext;
+import javax.resource.spi.ResourceAdapterInternalException;
+import javax.resource.spi.XATerminator;
+import javax.resource.spi.work.WorkManager;
+import javax.transaction.TransactionManager;
+
+import org.apache.activemq.ra.ActiveMQResourceAdapter;
+import org.apache.activemq.util.URISupport;
+import org.apache.aries.mds.ra.ResourceAdapterFacade;
+import org.apache.aries.mds.ra.SimpleBootstrapContext;
+import org.apache.aries.mds.ra.SimpleWorkManager;
+import org.apache.geronimo.connector.work.GeronimoWorkManager;
+import org.apache.geronimo.transaction.manager.GeronimoTransactionManager;
+
+
+public class ActiveMQResourceAdapterFacade extends ActiveMQResourceAdapter implements ResourceAdapterFacade {
+   private String dataSource;
+   private BootstrapContext bootstrapContext;
+   private WorkManager workManager;
+   private TransactionManager transactionManager;
+   private ExecutorService threadPool;
+
+   public String getDataSource() {
+       return dataSource;
+   }
+
+   public void setDataSource(String dataSource) {
+       this.dataSource = dataSource;
+   }
+   
+   public BootstrapContext getBootstrapContext() {
+       return bootstrapContext;
+   }
+
+   public void setBootstrapContext(BootstrapContext bootstrapContext) {
+       this.bootstrapContext = bootstrapContext;
+   }
+   
+   public WorkManager getWorkManager() {
+       return workManager;
+   }
+
+   public void setWorkManager(WorkManager workManager) {
+       this.workManager = workManager;
+   }
+   
+   public TransactionManager getTransactionManager() {
+       return transactionManager;
+   }
+
+   public void setTransactionManager(TransactionManager transactionManager) {
+       this.transactionManager = transactionManager;
+   }
+   
+   public void start() throws ResourceAdapterInternalException {
+       if (transactionManager == null) {
+           throw new NullPointerException("transactionManager is null - unable to find TransactionManager in OSGi service registry");
+       }
+       
+       // WorkManager: the resource adapter can use this to dispatch messages or perform tasks
+       if (workManager == null) {
+           // create a thead pool for ActiveMQ
+           // TODO make this configurable
+           threadPool = Executors.newFixedThreadPool(30);
+
+           if (transactionManager instanceof GeronimoTransactionManager) {
+               GeronimoTransactionManager geronimoTransactionManager = (GeronimoTransactionManager) transactionManager;
+               workManager = new GeronimoWorkManager(threadPool, threadPool, threadPool, geronimoTransactionManager);
+           } else {
+               workManager = new SimpleWorkManager(threadPool);
+           }  
+       }
+       
+       if (bootstrapContext == null) {
+           // BootstrapContext: wraps the WorkMananger and XATerminator
+           if (transactionManager instanceof XATerminator) {
+               bootstrapContext = new SimpleBootstrapContext(workManager, (XATerminator) transactionManager);
+           } else {
+               bootstrapContext = new SimpleBootstrapContext(workManager);
+           }           
+       }
+       
+       start(this.bootstrapContext);
+   }
+   
+   public void start(BootstrapContext bootstrapContext) throws ResourceAdapterInternalException {
+       Properties properties = new Properties();
+
+       // add data source property
+       if (dataSource != null) {
+           properties.put("DataSource", dataSource);
+       }
+
+       // prefix server uri with openejb: so our broker factory is used
+       String brokerXmlConfig = getBrokerXmlConfig();
+       if (brokerXmlConfig != null && brokerXmlConfig.startsWith("broker:")) {
+           try {
+               URISupport.CompositeData compositeData = URISupport.parseComposite(new URI(brokerXmlConfig));
+               compositeData.getParameters().put("persistent", "false");
+               setBrokerXmlConfig(ActiveMQFactory.getBrokerMetaFile() + compositeData.toURI());
+           } catch (URISyntaxException e) {
+               throw new ResourceAdapterInternalException("Invalid BrokerXmlConfig", e);
+           }
+       }
+
+       ActiveMQFactory.setThreadProperties(properties);
+
+       try {
+           super.start(bootstrapContext);
+       } finally {
+           ActiveMQFactory.setThreadProperties(null);
+
+           // reset brokerXmlConfig
+           if (brokerXmlConfig != null) {
+               setBrokerXmlConfig(brokerXmlConfig);
+           }
+       }
+   }
+   
+   public void stop() {
+       super.stop();
+       bootstrapContext = null;
+       workManager = null;
+       transactionManager = null;
+       if (!threadPool.isShutdown()) {
+           threadPool.shutdown();
+       }
+   }
+}

Propchange: incubator/aries/sandbox/linsun/mds/mds-ra-activemq/src/main/java/org/apache/aries/mds/ra/activemq/ActiveMQResourceAdapterFacade.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/aries/sandbox/linsun/mds/mds-ra-activemq/src/main/java/org/apache/aries/mds/ra/activemq/ActiveMQResourceAdapterFacade.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: incubator/aries/sandbox/linsun/mds/mds-ra-activemq/src/main/java/org/apache/aries/mds/ra/activemq/ActiveMQResourceAdapterFacade.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: incubator/aries/sandbox/linsun/mds/mds-ra-activemq/src/main/resources/META-INF/services/org/apache/activemq/broker/amq5factory
URL: http://svn.apache.org/viewvc/incubator/aries/sandbox/linsun/mds/mds-ra-activemq/src/main/resources/META-INF/services/org/apache/activemq/broker/amq5factory?rev=953860&view=auto
==============================================================================
--- incubator/aries/sandbox/linsun/mds/mds-ra-activemq/src/main/resources/META-INF/services/org/apache/activemq/broker/amq5factory (added)
+++ incubator/aries/sandbox/linsun/mds/mds-ra-activemq/src/main/resources/META-INF/services/org/apache/activemq/broker/amq5factory Fri Jun 11 20:09:30 2010
@@ -0,0 +1 @@
+class=org.apache.aries.mds.ra.activemq.ActiveMQ5Factory
\ No newline at end of file

Added: incubator/aries/sandbox/linsun/mds/mds-ra-activemq/src/main/resources/OSGI-INF/blueprint/config.xml
URL: http://svn.apache.org/viewvc/incubator/aries/sandbox/linsun/mds/mds-ra-activemq/src/main/resources/OSGI-INF/blueprint/config.xml?rev=953860&view=auto
==============================================================================
--- incubator/aries/sandbox/linsun/mds/mds-ra-activemq/src/main/resources/OSGI-INF/blueprint/config.xml (added)
+++ incubator/aries/sandbox/linsun/mds/mds-ra-activemq/src/main/resources/OSGI-INF/blueprint/config.xml Fri Jun 11 20:09:30 2010
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+	<!--
+		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.
+	-->
+<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
+	xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.0.0"
+	xmlns:ext="http://aries.apache.org/blueprint/xmlns/blueprint-ext/v1.0.0"
+	default-availability="optional">
+	
+    <bean id="activemqResourceAdapter" class="org.apache.aries.mds.ra.activemq.ActiveMQResourceAdapterFacade" init-method="start" destroy-method="stop">
+        <!-- <property name="bootstrapContext" value=""/>
+        <property name="workManager" value=""/> -->
+        <property name="serverUrl" value="tcp://localhost:61616"/>
+        <property name="brokerXmlConfig" value="broker:(tcp://localhost:61616)?useJmx=false"/>
+        <property name="transactionManager" ref="tm"/>
+    </bean>
+
+    <service ref="activemqResourceAdapter" interface="javax.resource.spi.ResourceAdapter">
+        <service-properties>
+			<entry key="serverUrl" value="tcp://localhost:61616" />
+		</service-properties>
+    </service>
+    
+    <bean id="connectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory">
+        <argument value="tcp://localhost:61616"/>
+    </bean>
+    <service ref="connectionFactory" interface="javax.jms.ConnectionFactory"/>
+
+    <reference id="tm" interface="javax.transaction.TransactionManager" timeout="100"/>
+</blueprint>
\ No newline at end of file

Propchange: incubator/aries/sandbox/linsun/mds/mds-ra-activemq/src/main/resources/OSGI-INF/blueprint/config.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/aries/sandbox/linsun/mds/mds-ra-activemq/src/main/resources/OSGI-INF/blueprint/config.xml
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: incubator/aries/sandbox/linsun/mds/mds-ra-activemq/src/main/resources/OSGI-INF/blueprint/config.xml
------------------------------------------------------------------------------
    svn:mime-type = text/xml

Added: incubator/aries/sandbox/linsun/mds/mds-ra/.classpath
URL: http://svn.apache.org/viewvc/incubator/aries/sandbox/linsun/mds/mds-ra/.classpath?rev=953860&view=auto
==============================================================================
--- incubator/aries/sandbox/linsun/mds/mds-ra/.classpath (added)
+++ incubator/aries/sandbox/linsun/mds/mds-ra/.classpath Fri Jun 11 20:09:30 2010
@@ -0,0 +1,16 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+	<classpathentry including="**/*.java" kind="src" path="src/main/java"/>
+	<classpathentry excluding="**/*.java" kind="src" path="target/maven-shared-archive-resources"/>
+	<classpathentry kind="var" path="M2_REPO/org/apache/geronimo/specs/geronimo-j2ee-connector_1.5_spec/2.0.0/geronimo-j2ee-connector_1.5_spec-2.0.0.jar"/>
+	<classpathentry kind="var" path="M2_REPO/org/apache/geronimo/specs/geronimo-jms_1.1_spec/1.1.1/geronimo-jms_1.1_spec-1.1.1.jar"/>
+	<classpathentry kind="var" path="M2_REPO/org/apache/geronimo/specs/geronimo-jta_1.1_spec/1.1.1/geronimo-jta_1.1_spec-1.1.1.jar"/>
+	<classpathentry kind="var" path="M2_REPO/junit/junit/4.8.1/junit-4.8.1.jar"/>
+	<classpathentry kind="var" path="M2_REPO/org/osgi/org.osgi.compendium/4.2.0/org.osgi.compendium-4.2.0.jar"/>
+	<classpathentry kind="var" path="M2_REPO/org/osgi/org.osgi.core/4.2.0/org.osgi.core-4.2.0.jar"/>
+	<classpathentry kind="var" path="M2_REPO/org/eclipse/osgi/3.5.0.v20090520/osgi-3.5.0.v20090520.jar"/>
+	<classpathentry kind="var" path="M2_REPO/org/slf4j/slf4j-api/1.5.11/slf4j-api-1.5.11.jar"/>
+	<classpathentry kind="var" path="M2_REPO/org/slf4j/slf4j-simple/1.5.11/slf4j-simple-1.5.11.jar"/>
+	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+	<classpathentry kind="output" path="target/classes"/>
+</classpath>

Added: incubator/aries/sandbox/linsun/mds/mds-ra/.project
URL: http://svn.apache.org/viewvc/incubator/aries/sandbox/linsun/mds/mds-ra/.project?rev=953860&view=auto
==============================================================================
--- incubator/aries/sandbox/linsun/mds/mds-ra/.project (added)
+++ incubator/aries/sandbox/linsun/mds/mds-ra/.project Fri Jun 11 20:09:30 2010
@@ -0,0 +1,13 @@
+<projectDescription>
+  <name>org.apache.aries.mds.ra</name>
+  <comment>This bundle contains the Message driven Service Implementation using ActiveMQ as the provider of JMS broker and resource adapter. NO_M2ECLIPSE_SUPPORT: Project files created with the maven-eclipse-plugin are not supported in M2Eclipse.</comment>
+  <projects/>
+  <buildSpec>
+    <buildCommand>
+      <name>org.eclipse.jdt.core.javabuilder</name>
+    </buildCommand>
+  </buildSpec>
+  <natures>
+    <nature>org.eclipse.jdt.core.javanature</nature>
+  </natures>
+</projectDescription>
\ No newline at end of file

Added: incubator/aries/sandbox/linsun/mds/mds-ra/.settings/org.eclipse.jdt.core.prefs
URL: http://svn.apache.org/viewvc/incubator/aries/sandbox/linsun/mds/mds-ra/.settings/org.eclipse.jdt.core.prefs?rev=953860&view=auto
==============================================================================
--- incubator/aries/sandbox/linsun/mds/mds-ra/.settings/org.eclipse.jdt.core.prefs (added)
+++ incubator/aries/sandbox/linsun/mds/mds-ra/.settings/org.eclipse.jdt.core.prefs Fri Jun 11 20:09:30 2010
@@ -0,0 +1,11 @@
+#Wed May 26 10:26:25 EDT 2010
+encoding//src/main/java=${project.build.sourceEncoding}
+org.eclipse.jdt.core.compiler.compliance=1.5
+encoding//src/main/resources=${project.build.sourceEncoding}
+encoding//src/test/resources=${project.build.sourceEncoding}
+encoding//src/test/java=${project.build.sourceEncoding}
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
+encoding//src/test/filtered-resources=${project.build.sourceEncoding}
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.source=1.5
+encoding//src/main/filtered-resources=${project.build.sourceEncoding}

Added: incubator/aries/sandbox/linsun/mds/mds-ra/pom.xml
URL: http://svn.apache.org/viewvc/incubator/aries/sandbox/linsun/mds/mds-ra/pom.xml?rev=953860&view=auto
==============================================================================
--- incubator/aries/sandbox/linsun/mds/mds-ra/pom.xml (added)
+++ incubator/aries/sandbox/linsun/mds/mds-ra/pom.xml Fri Jun 11 20:09:30 2010
@@ -0,0 +1,86 @@
+    <!--
+		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.
+	-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+	<modelVersion>4.0.0</modelVersion>
+	<parent>
+		<groupId>org.apache.aries.mds</groupId>
+		<artifactId>blueprint</artifactId>
+		<version>0.2-incubating-SNAPSHOT</version>
+	</parent>
+
+	<artifactId>org.apache.aries.mds.ra</artifactId>
+	<packaging>bundle</packaging>
+	<name>Apache Aries Message Driven Service Resource Adapter </name>
+	<description>
+      This bundle contains the Message driven Service Implementation using ActiveMQ as the provider of JMS broker and resource adapter
+  </description>
+
+	<properties>
+		<aries.osgi.export.pkg>
+			org.apache.aries.mds.ra
+      </aries.osgi.export.pkg>
+		<aries.osgi.import>
+			!org.apache.aries.mds.ra.*,
+			*
+      </aries.osgi.import>
+	</properties>
+
+	<dependencies>
+		<dependency>
+			<groupId>org.osgi</groupId>
+			<artifactId>org.osgi.core</artifactId>
+			<scope>provided</scope>
+		</dependency>
+		<dependency>
+			<groupId>org.osgi</groupId>
+			<artifactId>org.osgi.compendium</artifactId>
+			<scope>provided</scope>
+		</dependency>
+		<dependency>
+			<groupId>org.eclipse</groupId>
+			<artifactId>osgi</artifactId>
+			<scope>provided</scope>
+		</dependency>
+		<dependency>
+			<groupId>org.slf4j</groupId>
+			<artifactId>slf4j-api</artifactId>
+		</dependency>
+		<dependency>
+			<groupId>org.slf4j</groupId>
+			<artifactId>slf4j-simple</artifactId>
+			<scope>test</scope>
+		</dependency>
+
+		<dependency>
+			<groupId>org.apache.geronimo.specs</groupId>
+			<artifactId>geronimo-jms_1.1_spec</artifactId>
+			<scope>provided</scope>
+		</dependency>
+		<dependency>
+			<groupId>org.apache.geronimo.specs</groupId>
+			<artifactId>geronimo-j2ee-connector_1.5_spec</artifactId>
+			<scope>provided</scope>
+		</dependency>
+		<dependency>
+			<groupId>org.apache.geronimo.specs</groupId>
+			<artifactId>geronimo-jta_1.1_spec</artifactId>
+		</dependency>
+
+
+	</dependencies>
+
+</project>

Propchange: incubator/aries/sandbox/linsun/mds/mds-ra/pom.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/aries/sandbox/linsun/mds/mds-ra/pom.xml
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: incubator/aries/sandbox/linsun/mds/mds-ra/pom.xml
------------------------------------------------------------------------------
    svn:mime-type = text/xml

Added: incubator/aries/sandbox/linsun/mds/mds-ra/src/main/java/org/apache/aries/mds/ra/MdbUtil.java
URL: http://svn.apache.org/viewvc/incubator/aries/sandbox/linsun/mds/mds-ra/src/main/java/org/apache/aries/mds/ra/MdbUtil.java?rev=953860&view=auto
==============================================================================
--- incubator/aries/sandbox/linsun/mds/mds-ra/src/main/java/org/apache/aries/mds/ra/MdbUtil.java (added)
+++ incubator/aries/sandbox/linsun/mds/mds-ra/src/main/java/org/apache/aries/mds/ra/MdbUtil.java Fri Jun 11 20:09:30 2010
@@ -0,0 +1,78 @@
+/**
+ *
+ * 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.aries.mds.ra;
+
+import javax.jms.MessageProducer;
+import javax.jms.JMSException;
+import javax.jms.MessageConsumer;
+import javax.jms.Session;
+import javax.jms.Connection;
+import java.lang.reflect.Method;
+
+public class MdbUtil {
+    public static String getSignature(Method method){
+        StringBuilder builder = new StringBuilder();
+        builder.append(method.getName()).append("(");
+        boolean first = true;
+        for (Class<?> type : method.getParameterTypes()) {
+            if (!first) {
+                builder.append(",");
+            }
+            builder.append(type);
+            first = false;
+        }
+        builder.append(")");
+        return builder.toString();
+    }
+
+    public static void close(MessageProducer closeable) {
+        if (closeable != null) {
+            try {
+                closeable.close();
+            } catch (JMSException e) {
+            }
+        }
+    }
+
+    public static void close(MessageConsumer closeable) {
+        if (closeable != null) {
+            try {
+                closeable.close();
+            } catch (JMSException e) {
+            }
+        }
+    }
+
+    public static void close(Session closeable) {
+        if (closeable != null) {
+            try {
+                closeable.close();
+            } catch (JMSException e) {
+            }
+        }
+    }
+
+    public static void close(Connection closeable) {
+        if (closeable != null) {
+            try {
+                closeable.close();
+            } catch (JMSException e) {
+            }
+        }
+    }
+}

Propchange: incubator/aries/sandbox/linsun/mds/mds-ra/src/main/java/org/apache/aries/mds/ra/MdbUtil.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/aries/sandbox/linsun/mds/mds-ra/src/main/java/org/apache/aries/mds/ra/MdbUtil.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: incubator/aries/sandbox/linsun/mds/mds-ra/src/main/java/org/apache/aries/mds/ra/MdbUtil.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: incubator/aries/sandbox/linsun/mds/mds-ra/src/main/java/org/apache/aries/mds/ra/ResourceAdapterFacade.java
URL: http://svn.apache.org/viewvc/incubator/aries/sandbox/linsun/mds/mds-ra/src/main/java/org/apache/aries/mds/ra/ResourceAdapterFacade.java?rev=953860&view=auto
==============================================================================
--- incubator/aries/sandbox/linsun/mds/mds-ra/src/main/java/org/apache/aries/mds/ra/ResourceAdapterFacade.java (added)
+++ incubator/aries/sandbox/linsun/mds/mds-ra/src/main/java/org/apache/aries/mds/ra/ResourceAdapterFacade.java Fri Jun 11 20:09:30 2010
@@ -0,0 +1,47 @@
+/**
+*
+* 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.aries.mds.ra;
+
+
+import javax.resource.spi.BootstrapContext;
+import javax.resource.spi.ResourceAdapterInternalException;
+import javax.resource.spi.work.WorkManager;
+import javax.transaction.TransactionManager;
+
+
+public interface ResourceAdapterFacade  {
+   public String getDataSource();
+
+   public void setDataSource(String dataSource);
+   
+   public BootstrapContext getBootstrapContext();
+
+   public void setBootstrapContext(BootstrapContext bootstrapContext);
+   
+   public WorkManager getWorkManager();
+
+   public void setWorkManager(WorkManager workManager);
+   
+   public TransactionManager getTransactionManager();
+
+   public void setTransactionManager(TransactionManager transactionManager);
+   
+   public void start() throws ResourceAdapterInternalException;
+ 
+   public void stop();
+}

Propchange: incubator/aries/sandbox/linsun/mds/mds-ra/src/main/java/org/apache/aries/mds/ra/ResourceAdapterFacade.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/aries/sandbox/linsun/mds/mds-ra/src/main/java/org/apache/aries/mds/ra/ResourceAdapterFacade.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: incubator/aries/sandbox/linsun/mds/mds-ra/src/main/java/org/apache/aries/mds/ra/ResourceAdapterFacade.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: incubator/aries/sandbox/linsun/mds/mds-ra/src/main/java/org/apache/aries/mds/ra/SimpleBootstrapContext.java
URL: http://svn.apache.org/viewvc/incubator/aries/sandbox/linsun/mds/mds-ra/src/main/java/org/apache/aries/mds/ra/SimpleBootstrapContext.java?rev=953860&view=auto
==============================================================================
--- incubator/aries/sandbox/linsun/mds/mds-ra/src/main/java/org/apache/aries/mds/ra/SimpleBootstrapContext.java (added)
+++ incubator/aries/sandbox/linsun/mds/mds-ra/src/main/java/org/apache/aries/mds/ra/SimpleBootstrapContext.java Fri Jun 11 20:09:30 2010
@@ -0,0 +1,50 @@
+/**
+ *
+ * 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.aries.mds.ra;
+
+import java.util.Timer;
+import javax.resource.spi.work.WorkManager;
+import javax.resource.spi.XATerminator;
+import javax.resource.spi.BootstrapContext;
+
+public class SimpleBootstrapContext implements BootstrapContext {
+    private final WorkManager workManager;
+    private final XATerminator xaTerminator;
+
+    public SimpleBootstrapContext(WorkManager workManager) {
+        this.workManager = workManager;
+        xaTerminator = null;
+    }
+
+    public SimpleBootstrapContext(WorkManager workManager, XATerminator xaTerminator) {
+        this.workManager = workManager;
+        this.xaTerminator = xaTerminator;
+    }
+
+    public WorkManager getWorkManager() {
+        return workManager;
+    }
+
+    public XATerminator getXATerminator() {
+        return xaTerminator;
+    }
+
+    public Timer createTimer() {
+        return new Timer(true);
+    }
+}

Propchange: incubator/aries/sandbox/linsun/mds/mds-ra/src/main/java/org/apache/aries/mds/ra/SimpleBootstrapContext.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/aries/sandbox/linsun/mds/mds-ra/src/main/java/org/apache/aries/mds/ra/SimpleBootstrapContext.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: incubator/aries/sandbox/linsun/mds/mds-ra/src/main/java/org/apache/aries/mds/ra/SimpleBootstrapContext.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: incubator/aries/sandbox/linsun/mds/mds-ra/src/main/java/org/apache/aries/mds/ra/SimpleWorkManager.java
URL: http://svn.apache.org/viewvc/incubator/aries/sandbox/linsun/mds/mds-ra/src/main/java/org/apache/aries/mds/ra/SimpleWorkManager.java?rev=953860&view=auto
==============================================================================
--- incubator/aries/sandbox/linsun/mds/mds-ra/src/main/java/org/apache/aries/mds/ra/SimpleWorkManager.java (added)
+++ incubator/aries/sandbox/linsun/mds/mds-ra/src/main/java/org/apache/aries/mds/ra/SimpleWorkManager.java Fri Jun 11 20:09:30 2010
@@ -0,0 +1,254 @@
+/*
+ * 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.aries.mds.ra;
+
+
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.Executor;
+import javax.resource.spi.work.ExecutionContext;
+import javax.resource.spi.work.Work;
+import javax.resource.spi.work.WorkAdapter;
+import javax.resource.spi.work.WorkCompletedException;
+import javax.resource.spi.work.WorkEvent;
+import static javax.resource.spi.work.WorkEvent.WORK_ACCEPTED;
+import static javax.resource.spi.work.WorkEvent.WORK_COMPLETED;
+import static javax.resource.spi.work.WorkEvent.WORK_REJECTED;
+import static javax.resource.spi.work.WorkEvent.WORK_STARTED;
+import javax.resource.spi.work.WorkException;
+import static javax.resource.spi.work.WorkException.INTERNAL;
+import static javax.resource.spi.work.WorkException.START_TIMED_OUT;
+import javax.resource.spi.work.WorkListener;
+import javax.resource.spi.work.WorkManager;
+import javax.resource.spi.work.WorkRejectedException;
+
+import static org.apache.aries.mds.ra.SimpleWorkManager.WorkType.DO;
+import static org.apache.aries.mds.ra.SimpleWorkManager.WorkType.SCHEDULE;
+import static org.apache.aries.mds.ra.SimpleWorkManager.WorkType.START;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class SimpleWorkManager implements WorkManager {
+    public enum WorkType {
+        DO, START, SCHEDULE
+    }
+
+    private static final Logger LOGGER = LoggerFactory.getLogger(SimpleWorkManager.class);
+
+    /**
+     * All work is performed by this executor
+     */
+    private Executor executor;
+
+    public SimpleWorkManager(Executor executor) {
+        if (executor == null) throw new NullPointerException("executor is null");
+        this.executor = executor;
+    }
+
+    public void doWork(Work work) throws WorkException {
+        if (work == null) throw new NullPointerException("work is null");
+        doWork(work, INDEFINITE, null, null);
+    }
+
+    public void doWork(Work work, long startTimeout, ExecutionContext executionContext, WorkListener workListener) throws WorkException {
+        if (work == null) throw new NullPointerException("work is null");
+        executeWork(DO, work, startTimeout, executionContext, workListener);
+    }
+
+    public long startWork(Work work) throws WorkException {
+        if (work == null) throw new NullPointerException("work is null");
+        return startWork(work, INDEFINITE, null, null);
+    }
+
+    public long startWork(Work work, long startTimeout, ExecutionContext executionContext, WorkListener workListener) throws WorkException {
+        if (work == null) throw new NullPointerException("work is null");
+        return executeWork(START, work, startTimeout, executionContext, workListener);
+    }
+
+    public void scheduleWork(Work work) throws WorkException {
+        if (work == null) throw new NullPointerException("work is null");
+        scheduleWork(work, INDEFINITE, null, null);
+    }
+
+    public void scheduleWork(Work work, long startTimeout, ExecutionContext executionContext, WorkListener workListener) throws WorkException {
+        if (work == null) throw new NullPointerException("work is null");
+        executeWork(SCHEDULE, work, startTimeout, executionContext, workListener);
+    }
+
+    private long executeWork(WorkType workType, Work work, long startTimeout, ExecutionContext executionContext, WorkListener workListener) throws WorkException {
+        // assure we have a work listener
+        if (workListener == null) workListener = new LoggingWorkListener(workType);
+
+        // reject work with an XID
+        if (executionContext != null && executionContext.getXid() != null) {
+            WorkRejectedException workRejectedException = new WorkRejectedException("SimpleWorkManager can not import an XID", WorkException.TX_RECREATE_FAILED);
+            workListener.workRejected(new WorkEvent(this, WORK_REJECTED, work, workRejectedException));
+            throw workRejectedException;
+        }
+
+        // accecpt all other work
+        workListener.workAccepted(new WorkEvent(this, WORK_ACCEPTED, work, null));
+
+        // execute work
+        Worker worker = new Worker(work, workListener, startTimeout);
+        executor.execute(worker);
+
+        if (workType == DO) {
+            // wait for completion
+            try {
+                worker.waitForCompletion();
+            } catch (InterruptedException e) {
+                WorkException workException = new WorkException("Work submission thread was interrupted", e);
+                workException.setErrorCode(INTERNAL);
+                throw workException;
+            }
+
+            // if work threw an exception, rethrow it
+            WorkException workCompletedException = worker.getWorkException();
+            if (workCompletedException != null) {
+                throw workCompletedException;
+            }
+        } else if (workType == START) {
+            // wait for work to start
+            try {
+                worker.waitForStart();
+            } catch (InterruptedException e) {
+                WorkException workException = new WorkException("Work submission thread was interrupted", e);
+                workException.setErrorCode(INTERNAL);
+                throw workException;
+            }
+
+            // if work threw a rejection exception, rethrow it (it is the exception for timeout) 
+            WorkException workCompletedException = worker.getWorkException();
+            if (workCompletedException instanceof WorkRejectedException) {
+                throw workCompletedException;
+            }
+        }
+
+        return worker.getStartDelay();
+    }
+
+    private class Worker implements Runnable {
+        private final Work work;
+        private final WorkListener workListener;
+        private final long startTimeout;
+        private final long created = System.currentTimeMillis();
+        private final CountDownLatch started = new CountDownLatch(1);
+        private final CountDownLatch completed = new CountDownLatch(1);
+        private long startDelay = UNKNOWN;
+        private WorkException workException;
+
+        public Worker(Work work, WorkListener workListener, long startTimeout) {
+            this.work = work;
+            this.workListener = workListener;
+            if (startTimeout <= 0) {
+                this.startTimeout = INDEFINITE;
+            } else {
+                this.startTimeout = startTimeout;
+            }
+        }
+
+        public void run() {
+            try {
+                // check if we have started within the specified limit
+                startDelay = System.currentTimeMillis() - created;
+                if (startDelay > startTimeout) {
+                    workException = new WorkRejectedException("Work not started within specified timeout " + startTimeout + "ms", START_TIMED_OUT);
+                    workListener.workRejected(new WorkEvent(this, WORK_REJECTED, work, workException, startTimeout));
+                    return;
+                }
+
+                // notify listener that work has been started
+                workListener.workStarted(new WorkEvent(SimpleWorkManager.this, WORK_STARTED, work, null));
+
+                // officially started
+                started.countDown();
+
+                // execute the real work
+                workException = null;
+                try {
+                    work.run();
+                } catch (Throwable e) {
+                    workException = new WorkCompletedException(e);
+                } finally {
+                    // notify listener that work completed (with an optional exception)
+                    workListener.workCompleted(new WorkEvent(SimpleWorkManager.this, WORK_COMPLETED, work, workException));
+                }
+            } finally {
+                // assure that threads waiting for start are released
+                started.countDown();
+
+                // Done
+                completed.countDown();
+            }
+        }
+
+        public long getStartDelay() {
+            return startDelay;
+        }
+
+        public WorkException getWorkException() {
+            return workException;
+        }
+
+        public void waitForStart() throws InterruptedException {
+            started.await();
+        }
+
+        public void waitForCompletion() throws InterruptedException {
+            completed.await();
+        }
+    }
+
+    private static class LoggingWorkListener extends WorkAdapter {
+        private final WorkType workType;
+
+        private LoggingWorkListener(WorkType workType) {
+            this.workType = workType;
+        }
+
+        public void workRejected(WorkEvent event) {
+            // Don't log doWork or startWork since exception is propagated to caller
+            if (workType == DO || workType == START) {
+                return;
+            }
+            WorkException exception = event.getException();
+            if (exception != null) {
+                if (WorkException.START_TIMED_OUT.equals(exception.getErrorCode())) {
+                    LOGGER.error(exception.getMessage());
+                }
+            }
+        }
+
+        public void workCompleted(WorkEvent event) {
+            // Don't log doWork since exception is propagated to caller
+            if (workType == DO) {
+                return;
+            }
+
+            Throwable cause = event.getException();
+            if (cause != null && cause.getCause() != null) {
+                cause = cause.getCause();
+            }
+            if (cause != null) {
+                LOGGER.error(event.getWork().toString(), cause);
+            }
+        }
+    }
+}

Propchange: incubator/aries/sandbox/linsun/mds/mds-ra/src/main/java/org/apache/aries/mds/ra/SimpleWorkManager.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/aries/sandbox/linsun/mds/mds-ra/src/main/java/org/apache/aries/mds/ra/SimpleWorkManager.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: incubator/aries/sandbox/linsun/mds/mds-ra/src/main/java/org/apache/aries/mds/ra/SimpleWorkManager.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: incubator/aries/sandbox/linsun/mds/mds-sample/.classpath
URL: http://svn.apache.org/viewvc/incubator/aries/sandbox/linsun/mds/mds-sample/.classpath?rev=953860&view=auto
==============================================================================
--- incubator/aries/sandbox/linsun/mds/mds-sample/.classpath (added)
+++ incubator/aries/sandbox/linsun/mds/mds-sample/.classpath Fri Jun 11 20:09:30 2010
@@ -0,0 +1,14 @@
+<classpath>
+  <classpathentry kind="src" path="src/main/java" including="**/*.java"/>
+  <classpathentry kind="src" path="src/main/resources" including="**/*" excluding="**/*.java"/>
+  <classpathentry kind="src" path="target/maven-shared-archive-resources" excluding="**/*.java"/>
+  <classpathentry kind="output" path="target/classes"/>
+  <classpathentry kind="var" path="M2_REPO/org/apache/geronimo/specs/geronimo-jms_1.1_spec/1.1.1/geronimo-jms_1.1_spec-1.1.1.jar"/>
+  <classpathentry kind="var" path="M2_REPO/junit/junit/4.8.1/junit-4.8.1.jar"/>
+  <classpathentry kind="var" path="M2_REPO/org/osgi/org.osgi.compendium/4.2.0/org.osgi.compendium-4.2.0.jar"/>
+  <classpathentry kind="var" path="M2_REPO/org/osgi/org.osgi.core/4.2.0/org.osgi.core-4.2.0.jar"/>
+  <classpathentry kind="var" path="M2_REPO/org/eclipse/osgi/3.5.0.v20090520/osgi-3.5.0.v20090520.jar"/>
+  <classpathentry kind="var" path="M2_REPO/org/slf4j/slf4j-api/1.5.11/slf4j-api-1.5.11.jar"/>
+  <classpathentry kind="var" path="M2_REPO/org/slf4j/slf4j-simple/1.5.11/slf4j-simple-1.5.11.jar"/>
+  <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+</classpath>
\ No newline at end of file

Added: incubator/aries/sandbox/linsun/mds/mds-sample/.project
URL: http://svn.apache.org/viewvc/incubator/aries/sandbox/linsun/mds/mds-sample/.project?rev=953860&view=auto
==============================================================================
--- incubator/aries/sandbox/linsun/mds/mds-sample/.project (added)
+++ incubator/aries/sandbox/linsun/mds/mds-sample/.project Fri Jun 11 20:09:30 2010
@@ -0,0 +1,14 @@
+<projectDescription>
+  <name>org.apache.aries.mds.sample</name>
+  <comment>This bundle contains the Message driven service 
+      sample. NO_M2ECLIPSE_SUPPORT: Project files created with the maven-eclipse-plugin are not supported in M2Eclipse.</comment>
+  <projects/>
+  <buildSpec>
+    <buildCommand>
+      <name>org.eclipse.jdt.core.javabuilder</name>
+    </buildCommand>
+  </buildSpec>
+  <natures>
+    <nature>org.eclipse.jdt.core.javanature</nature>
+  </natures>
+</projectDescription>
\ No newline at end of file

Added: incubator/aries/sandbox/linsun/mds/mds-sample/.settings/org.eclipse.jdt.core.prefs
URL: http://svn.apache.org/viewvc/incubator/aries/sandbox/linsun/mds/mds-sample/.settings/org.eclipse.jdt.core.prefs?rev=953860&view=auto
==============================================================================
--- incubator/aries/sandbox/linsun/mds/mds-sample/.settings/org.eclipse.jdt.core.prefs (added)
+++ incubator/aries/sandbox/linsun/mds/mds-sample/.settings/org.eclipse.jdt.core.prefs Fri Jun 11 20:09:30 2010
@@ -0,0 +1,11 @@
+#Wed May 26 10:26:25 EDT 2010
+encoding//src/main/java=${project.build.sourceEncoding}
+org.eclipse.jdt.core.compiler.compliance=1.5
+encoding//src/main/resources=${project.build.sourceEncoding}
+encoding//src/test/resources=${project.build.sourceEncoding}
+encoding//src/test/java=${project.build.sourceEncoding}
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
+encoding//src/test/filtered-resources=${project.build.sourceEncoding}
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.source=1.5
+encoding//src/main/filtered-resources=${project.build.sourceEncoding}



Mime
View raw message