diff options
author | antelder <antelder@13f79535-47bb-0310-9956-ffa450edef68> | 2009-02-12 10:45:29 +0000 |
---|---|---|
committer | antelder <antelder@13f79535-47bb-0310-9956-ffa450edef68> | 2009-02-12 10:45:29 +0000 |
commit | 90e4c11facf6f4011a7e4294f64cbc9d7c189128 (patch) | |
tree | 54f35a21a1818d3b6c81e1ec8678142276747ad2 | |
parent | 57979d20af5d2fd2bc2811a2be8f475bee8eafed (diff) |
TUSCANY-2841: start to add support for using a seperate response connection factory
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@743685 13f79535-47bb-0310-9956-ffa450edef68
9 files changed, 77 insertions, 3 deletions
diff --git a/branches/sca-java-1.x/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/AbstractMessageProcessor.java b/branches/sca-java-1.x/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/AbstractMessageProcessor.java index c2a9a61257..c69bac7641 100644 --- a/branches/sca-java-1.x/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/AbstractMessageProcessor.java +++ b/branches/sca-java-1.x/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/AbstractMessageProcessor.java @@ -19,6 +19,7 @@ package org.apache.tuscany.sca.binding.jms.provider; import java.lang.reflect.InvocationTargetException; +import java.util.logging.Logger; import javax.jms.JMSException; import javax.jms.Message; @@ -36,6 +37,7 @@ import org.osoa.sca.ServiceRuntimeException; * @version $Rev$ $Date$ */ public abstract class AbstractMessageProcessor implements JMSMessageProcessor { + private static final Logger logger = Logger.getLogger(AbstractMessageProcessor.class.getName()); protected String operationPropertyName; protected boolean xmlFormat = true; @@ -100,6 +102,10 @@ public abstract class AbstractMessageProcessor implements JMSMessageProcessor { } public Message createFaultMessage(Session session, Throwable o) { + if (session == null) { + logger.fine("no response session to create fault message: " + String.valueOf(o)); + return null; + } try { ObjectMessage message = session.createObjectMessage(); diff --git a/branches/sca-java-1.x/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/BytesMessageProcessor.java b/branches/sca-java-1.x/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/BytesMessageProcessor.java index 457b519051..057b58ca11 100644 --- a/branches/sca-java-1.x/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/BytesMessageProcessor.java +++ b/branches/sca-java-1.x/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/BytesMessageProcessor.java @@ -18,6 +18,8 @@ */ package org.apache.tuscany.sca.binding.jms.provider; +import java.util.logging.Logger; + import javax.jms.BytesMessage; import javax.jms.JMSException; import javax.jms.Message; @@ -33,6 +35,7 @@ import org.apache.tuscany.sca.binding.jms.impl.JMSBindingException; * @version $Rev$ $Date$ */ public class BytesMessageProcessor extends AbstractMessageProcessor { + private static final Logger logger = Logger.getLogger(AbstractMessageProcessor.class.getName()); public BytesMessageProcessor(JMSBinding jmsBinding) { super(jmsBinding); @@ -58,6 +61,10 @@ public class BytesMessageProcessor extends AbstractMessageProcessor { @Override protected Message createJMSMessage(Session session, Object o) { + if (session == null) { + logger.fine("no response session to create message: " + String.valueOf(o)); + return null; + } try { // TODO - an experiment. How to enforce a single diff --git a/branches/sca-java-1.x/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/DefaultJMSResourceFactoryExtensionPoint.java b/branches/sca-java-1.x/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/DefaultJMSResourceFactoryExtensionPoint.java index 499f69a24b..1de85ea773 100644 --- a/branches/sca-java-1.x/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/DefaultJMSResourceFactoryExtensionPoint.java +++ b/branches/sca-java-1.x/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/DefaultJMSResourceFactoryExtensionPoint.java @@ -24,7 +24,7 @@ import org.apache.tuscany.sca.binding.jms.impl.JMSBinding; public class DefaultJMSResourceFactoryExtensionPoint implements JMSResourceFactoryExtensionPoint {
public JMSResourceFactory createJMSResourceFactory(JMSBinding binding) {
- return new JMSResourceFactoryImpl(binding.getConnectionFactoryName(), binding.getInitialContextFactoryName(), binding.getJndiURL());
+ return new JMSResourceFactoryImpl(binding.getConnectionFactoryName(), binding.getResponseConnectionFactoryName(), binding.getInitialContextFactoryName(), binding.getJndiURL());
}
}
diff --git a/branches/sca-java-1.x/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/JMSResourceFactory.java b/branches/sca-java-1.x/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/JMSResourceFactory.java index 773be84c7f..b8ff408292 100644 --- a/branches/sca-java-1.x/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/JMSResourceFactory.java +++ b/branches/sca-java-1.x/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/JMSResourceFactory.java @@ -64,4 +64,20 @@ public interface JMSResourceFactory { */
public abstract Destination createDestination(String jndiName) throws NamingException;
+ /*
+ * This is a simple implementation where a connection is created per binding Ideally the resource factory should be
+ * able to leverage the host environment to provide connection pooling if it can. E.g. if Tuscany is running inside
+ * an AppServer Then we could leverage the JMS resources it provides
+ *
+ * @see org.apache.tuscany.binding.jms.JMSResourceFactory#getConnection()
+ */
+ public abstract Connection getResponseConnection() throws NamingException, JMSException;
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.apache.tuscany.binding.jms.JMSResourceFactory#createSession()
+ */
+ public abstract Session createResponseSession() throws JMSException, NamingException;
+
}
diff --git a/branches/sca-java-1.x/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/JMSResourceFactoryImpl.java b/branches/sca-java-1.x/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/JMSResourceFactoryImpl.java index d0624fb52e..8136c524c6 100644 --- a/branches/sca-java-1.x/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/JMSResourceFactoryImpl.java +++ b/branches/sca-java-1.x/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/JMSResourceFactoryImpl.java @@ -46,11 +46,16 @@ public class JMSResourceFactoryImpl implements JMSResourceFactory { protected Connection connection; protected Context context; protected boolean isConnectionStarted; + private Connection responseConnection; + private String responseConnectionFactoryName; - public JMSResourceFactoryImpl(String connectionFactoryName, String initialContextFactoryName, String jndiURL) { + public JMSResourceFactoryImpl(String connectionFactoryName, String responseConnectionFactoryName, String initialContextFactoryName, String jndiURL) { if (connectionFactoryName != null && connectionFactoryName.trim().length() > 0) { this.connectionFactoryName = connectionFactoryName.trim(); } + if (responseConnectionFactoryName != null && responseConnectionFactoryName.trim().length() > 0) { + this.responseConnectionFactoryName = responseConnectionFactoryName.trim(); + } if (initialContextFactoryName != null && initialContextFactoryName.trim().length() > 0) { this.initialContextFactoryName = initialContextFactoryName.trim(); } @@ -220,4 +225,25 @@ public class JMSResourceFactoryImpl implements JMSResourceFactory { } return o; } + + public Session createResponseSession() throws JMSException, NamingException { + return getResponseConnection().createSession(false, Session.AUTO_ACKNOWLEDGE); + } + + public Connection getResponseConnection() throws NamingException, JMSException { + if (responseConnection == null) { + if (responseConnectionFactoryName != null) { + ConnectionFactory connectionFactory = (ConnectionFactory)jndiLookUp(responseConnectionFactoryName); + if (connectionFactory == null) { + throw new JMSBindingException("connection factory not found: " + responseConnectionFactoryName); + } + responseConnection = connectionFactory.createConnection(); + } else { + // if no response connection is defined in the SCDL use the request connection + responseConnection = getConnection(); + } + } + return responseConnection; + } + } diff --git a/branches/sca-java-1.x/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/ObjectMessageProcessor.java b/branches/sca-java-1.x/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/ObjectMessageProcessor.java index 781d9fc93c..73a822a622 100644 --- a/branches/sca-java-1.x/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/ObjectMessageProcessor.java +++ b/branches/sca-java-1.x/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/ObjectMessageProcessor.java @@ -19,6 +19,7 @@ package org.apache.tuscany.sca.binding.jms.provider; import java.io.Serializable; +import java.util.logging.Logger; import javax.jms.JMSException; import javax.jms.Message; @@ -34,6 +35,7 @@ import org.apache.tuscany.sca.binding.jms.impl.JMSBindingException; * @version $Rev$ $Date$ */ public class ObjectMessageProcessor extends AbstractMessageProcessor { + private static final Logger logger = Logger.getLogger(ObjectMessageProcessor.class.getName()); public ObjectMessageProcessor(JMSBinding jmsBinding) { super(jmsBinding); @@ -52,6 +54,10 @@ public class ObjectMessageProcessor extends AbstractMessageProcessor { @Override protected Message createJMSMessage(Session session, Object o) { + if (session == null) { + logger.fine("no response session to create message: " + String.valueOf(o)); + return null; + } try { ObjectMessage message = session.createObjectMessage(); diff --git a/branches/sca-java-1.x/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/TextMessageProcessor.java b/branches/sca-java-1.x/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/TextMessageProcessor.java index b87a206f03..c1b5e6562d 100644 --- a/branches/sca-java-1.x/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/TextMessageProcessor.java +++ b/branches/sca-java-1.x/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/TextMessageProcessor.java @@ -18,6 +18,8 @@ */ package org.apache.tuscany.sca.binding.jms.provider; +import java.util.logging.Logger; + import javax.jms.JMSException; import javax.jms.Message; import javax.jms.Session; @@ -32,6 +34,7 @@ import org.apache.tuscany.sca.binding.jms.impl.JMSBindingException; * @version $Rev$ $Date$ */ public class TextMessageProcessor extends AbstractMessageProcessor { + private static final Logger logger = Logger.getLogger(TextMessageProcessor.class.getName()); public TextMessageProcessor(JMSBinding jmsBinding) { super(jmsBinding); @@ -54,6 +57,10 @@ public class TextMessageProcessor extends AbstractMessageProcessor { @Override protected Message createJMSMessage(Session session, Object o) { + if (session == null) { + logger.fine("no response session to create message: " + String.valueOf(o)); + return null; + } try { TextMessage message = session.createTextMessage(); diff --git a/branches/sca-java-1.x/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/XMLTextMessageProcessor.java b/branches/sca-java-1.x/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/XMLTextMessageProcessor.java index 3a4ba7b809..47adb27cf9 100644 --- a/branches/sca-java-1.x/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/XMLTextMessageProcessor.java +++ b/branches/sca-java-1.x/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/XMLTextMessageProcessor.java @@ -19,6 +19,7 @@ package org.apache.tuscany.sca.binding.jms.provider; import java.io.StringReader; +import java.util.logging.Logger; import javax.jms.JMSException; import javax.jms.Message; @@ -39,6 +40,7 @@ import org.apache.tuscany.sca.binding.jms.impl.JMSBindingException; * @version $Rev$ $Date$ */ public class XMLTextMessageProcessor extends AbstractMessageProcessor { + private static final Logger logger = Logger.getLogger(XMLTextMessageProcessor.class.getName()); public XMLTextMessageProcessor(JMSBinding jmsBinding) { super(jmsBinding); @@ -68,6 +70,10 @@ public class XMLTextMessageProcessor extends AbstractMessageProcessor { @Override protected Message createJMSMessage(Session session, Object o) { + if (session == null) { + logger.fine("no response session to create message: " + String.valueOf(o)); + return null; + } try { TextMessage message = session.createTextMessage(); diff --git a/branches/sca-java-1.x/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/transport/TransportServiceInterceptor.java b/branches/sca-java-1.x/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/transport/TransportServiceInterceptor.java index a2ecd3637b..2ac476ea82 100644 --- a/branches/sca-java-1.x/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/transport/TransportServiceInterceptor.java +++ b/branches/sca-java-1.x/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/transport/TransportServiceInterceptor.java @@ -91,7 +91,7 @@ public class TransportServiceInterceptor implements Interceptor { try { JMSBindingContext context = msg.getBindingContext(); javax.jms.Message requestJMSMsg = context.getJmsMsg(); - context.setJmsSession(context.getJmsResourceFactory().createSession()); + context.setJmsSession(context.getJmsResourceFactory().createResponseSession()); EndpointReference from = new EndpointReferenceImpl(null); msg.setFrom(from); |