Author: linsun
Date: Tue Jun 29 21:25:21 2010
New Revision: 959110
URL: http://svn.apache.org/viewvc?rev=959110&view=rev
Log:
[message driven service] allow users to specify messaging type via service
properties to support more than javax.jms.MessageListener interface
Added:
incubator/aries/sandbox/linsun/mds/mds-impl/src/main/java/org/apache/aries/mds/impl/EndpointFactory.java
(with props)
Removed:
incubator/aries/sandbox/linsun/mds/mds-impl/src/main/java/org/apache/aries/mds/impl/JmsEndpointFactory.java
Modified:
incubator/aries/sandbox/linsun/mds/mds-impl/src/main/java/org/apache/aries/mds/impl/MDSContainerImpl.java
incubator/aries/sandbox/linsun/mds/mds-impl/src/main/java/org/apache/aries/mds/impl/exception/MDSException.java
incubator/aries/sandbox/linsun/mds/mds-sample/src/main/resources/OSGI-INF/blueprint/config.xml
Added:
incubator/aries/sandbox/linsun/mds/mds-impl/src/main/java/org/apache/aries/mds/impl/EndpointFactory.java
URL:
http://svn.apache.org/viewvc/incubator/aries/sandbox/linsun/mds/mds-impl/src/main/java/org/apache/aries/mds/impl/EndpointFactory.java?rev=959110&view=auto
==============================================================================
---
incubator/aries/sandbox/linsun/mds/mds-impl/src/main/java/org/apache/aries/mds/impl/EndpointFactory.java
(added)
+++
incubator/aries/sandbox/linsun/mds/mds-impl/src/main/java/org/apache/aries/mds/impl/EndpointFactory.java
Tue Jun 29 21:25:21 2010
@@ -0,0 +1,92 @@
+/*
+ * 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.impl;
+
+import java.lang.reflect.Method;
+import java.lang.reflect.Proxy;
+
+import javax.resource.spi.ActivationSpec;
+import javax.resource.spi.UnavailableException;
+import javax.resource.spi.endpoint.MessageEndpoint;
+import javax.resource.spi.endpoint.MessageEndpointFactory;
+import javax.transaction.xa.XAResource;
+
+import org.apache.aries.mds.impl.exception.ApplicationException;
+import org.apache.aries.mds.impl.exception.SystemException;
+import org.apache.aries.mds.impl.transaction.TransactionPolicy;
+import org.apache.aries.mds.impl.transaction.TransactionPolicyFactory;
+import org.apache.aries.mds.impl.transaction.TransactionType;
+
+
+public class EndpointFactory implements MessageEndpointFactory {
+
+ private final MDSContainerImpl container;
+ private final XAResource xaResource;
+ private final Object instance;
+ private final Class[] interfaces;
+ private final ActivationSpec activationSpec;
+ private TransactionType tranType;
+ private TransactionPolicy tp;
+
+ public EndpointFactory(MDSContainerImpl container, Object instance,
XAResource xaResource, ActivationSpec activationSpec, String tranAttr,
TransactionPolicyFactory tpf) {
+ this.container = container;
+ this.instance = instance;
+ this.xaResource = xaResource;
+ interfaces = new Class[]{this.container.getMessageListenerInterface(),
MessageEndpoint.class};
+ this.activationSpec = activationSpec;
+
+ if (tranAttr != null) {
+ this.tranType = TransactionType.get(tranAttr);
+ }
+
+ // default transaction attribute is not supported, container managed
+ if (this.tranType == null) {
+ this.tranType = TransactionType.NotSupported;
+ }
+
+ try {
+ this.tp = tpf.createTransactionPolicy(this.tranType);
+ } catch (SystemException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (ApplicationException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+
+ }
+
+ public ActivationSpec getActivationSpec() {
+ return activationSpec;
+ }
+
+ public MessageEndpoint createEndpoint(XAResource xaResource) throws
UnavailableException {
+
+ EndpointHandler endpointHandler = new EndpointHandler(container,
instance, xaResource, this.tp);
+ //ClassLoader cl = instance.getClass().getClassLoader();
+ ClassLoader cl = EndpointFactory.class.getClassLoader();
+ MessageEndpoint messageEndpoint = (MessageEndpoint)
Proxy.newProxyInstance(cl, interfaces, endpointHandler);
+ return messageEndpoint;
+ }
+
+ public boolean isDeliveryTransacted(Method method) throws
NoSuchMethodException {
+ return TransactionType.Required == this.tranType;
+ }
+
+}
Propchange:
incubator/aries/sandbox/linsun/mds/mds-impl/src/main/java/org/apache/aries/mds/impl/EndpointFactory.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
incubator/aries/sandbox/linsun/mds/mds-impl/src/main/java/org/apache/aries/mds/impl/EndpointFactory.java
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange:
incubator/aries/sandbox/linsun/mds/mds-impl/src/main/java/org/apache/aries/mds/impl/EndpointFactory.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified:
incubator/aries/sandbox/linsun/mds/mds-impl/src/main/java/org/apache/aries/mds/impl/MDSContainerImpl.java
URL:
http://svn.apache.org/viewvc/incubator/aries/sandbox/linsun/mds/mds-impl/src/main/java/org/apache/aries/mds/impl/MDSContainerImpl.java?rev=959110&r1=959109&r2=959110&view=diff
==============================================================================
---
incubator/aries/sandbox/linsun/mds/mds-impl/src/main/java/org/apache/aries/mds/impl/MDSContainerImpl.java
(original)
+++
incubator/aries/sandbox/linsun/mds/mds-impl/src/main/java/org/apache/aries/mds/impl/MDSContainerImpl.java
Tue Jun 29 21:25:21 2010
@@ -51,6 +51,7 @@ public class MDSContainerImpl implements
private ActivationSpec activationSpec;
private MessageEndpointFactory endpointFactory;
private TransactionPolicyFactory tpf;
+ private Class messageListenerInterface;
public MDSContainerImpl(ResourceAdapter ra, ServiceReference sr,
BundleContext bc) {
this.ra = ra;
@@ -81,6 +82,16 @@ public class MDSContainerImpl implements
}
activationSpec = createActivationSpec(sr, activationSpecClass);
+ Object msgListener = this.sr.getProperty("service.exported.interface");
+ if (msgListener == null) {
+ throw new NullPointerException("service.exported.interface must be
specified so that we know the messaging type");
+ }
+ try {
+ this.messageListenerInterface =
this.getClass().getClassLoader().loadClass((String)msgListener);
+ } catch (ClassNotFoundException e) {
+ LOGGER.error("Unable to load the specified message listener
interface " + (String)msgListener , e);
+ throw new MDSException(e);
+ }
}
public void activateMessageEndpoint() {
@@ -98,7 +109,7 @@ public class MDSContainerImpl implements
// obtain transaction attribute from service property
String tranAttr = sr.getProperty("transactionAttribute") == null ?
null : (String)sr.getProperty("transactionAttribute");
- endpointFactory = new JmsEndpointFactory(this, ml, null,
activationSpec, tranAttr, tpf);
+ endpointFactory = new EndpointFactory(this, ml, null, activationSpec,
tranAttr, tpf);
// activate the endpoint
try {
@@ -333,6 +344,10 @@ public class MDSContainerImpl implements
}
+ public Class getMessageListenerInterface() {
+ return this.messageListenerInterface;
+ }
+
private static class MdbCallContext {
private Method deliveryMethod;
private TransactionPolicy txPolicy;
Modified:
incubator/aries/sandbox/linsun/mds/mds-impl/src/main/java/org/apache/aries/mds/impl/exception/MDSException.java
URL:
http://svn.apache.org/viewvc/incubator/aries/sandbox/linsun/mds/mds-impl/src/main/java/org/apache/aries/mds/impl/exception/MDSException.java?rev=959110&r1=959109&r2=959110&view=diff
==============================================================================
---
incubator/aries/sandbox/linsun/mds/mds-impl/src/main/java/org/apache/aries/mds/impl/exception/MDSException.java
(original)
+++
incubator/aries/sandbox/linsun/mds/mds-impl/src/main/java/org/apache/aries/mds/impl/exception/MDSException.java
Tue Jun 29 21:25:21 2010
@@ -17,7 +17,7 @@
package org.apache.aries.mds.impl.exception;
-public class MDSException extends Exception {
+public class MDSException extends RuntimeException {
public MDSException() {
super();
Modified:
incubator/aries/sandbox/linsun/mds/mds-sample/src/main/resources/OSGI-INF/blueprint/config.xml
URL:
http://svn.apache.org/viewvc/incubator/aries/sandbox/linsun/mds/mds-sample/src/main/resources/OSGI-INF/blueprint/config.xml?rev=959110&r1=959109&r2=959110&view=diff
==============================================================================
---
incubator/aries/sandbox/linsun/mds/mds-sample/src/main/resources/OSGI-INF/blueprint/config.xml
(original)
+++
incubator/aries/sandbox/linsun/mds/mds-sample/src/main/resources/OSGI-INF/blueprint/config.xml
Tue Jun 29 21:25:21 2010
@@ -30,6 +30,7 @@
<entry key="ac:destinationType" value="javax.jms.Queue"
/>
<entry key="transactionAttribute" value="Required" />
<entry key="service.pid"
value="org.apache.aries.mds.sample.myMessageDrivenBean" />
+ <entry key="service.exported.interface"
value="javax.jms.MessageListener" />
</service-properties>
</service>