Author: gaohoward
Date: 2010-11-18 05:50:39 -0500 (Thu, 18 Nov 2010)
New Revision: 9911
Added:
trunk/src/main/org/hornetq/jms/client/HornetQQueueConnection.java
trunk/src/main/org/hornetq/jms/client/HornetQTopicConnection.java
trunk/src/main/org/hornetq/jms/client/HornetQXAConnection.java
trunk/src/main/org/hornetq/jms/client/HornetQXAQueueConnection.java
trunk/src/main/org/hornetq/jms/client/HornetQXATopicConnection.java
Modified:
trunk/src/main/org/hornetq/jms/client/HornetQConnection.java
trunk/src/main/org/hornetq/jms/client/HornetQConnectionFactory.java
trunk/tests/jms-tests/src/org/hornetq/jms/tests/ConnectionFactoryTest.java
Log:
HORNETQ-515
Modified: trunk/src/main/org/hornetq/jms/client/HornetQConnection.java
===================================================================
--- trunk/src/main/org/hornetq/jms/client/HornetQConnection.java 2010-11-17 16:32:48 UTC
(rev 9910)
+++ trunk/src/main/org/hornetq/jms/client/HornetQConnection.java 2010-11-18 10:50:39 UTC
(rev 9911)
@@ -60,8 +60,7 @@
* <p/>
* $Id$
*/
-public class HornetQConnection implements Connection, QueueConnection, TopicConnection,
XAConnection,
- XAQueueConnection, XATopicConnection
+public class HornetQConnection implements Connection
{
// Constants
------------------------------------------------------------------------------------
Modified: trunk/src/main/org/hornetq/jms/client/HornetQConnectionFactory.java
===================================================================
--- trunk/src/main/org/hornetq/jms/client/HornetQConnectionFactory.java 2010-11-17
16:32:48 UTC (rev 9910)
+++ trunk/src/main/org/hornetq/jms/client/HornetQConnectionFactory.java 2010-11-18
10:50:39 UTC (rev 9911)
@@ -118,7 +118,7 @@
public QueueConnection createQueueConnection(final String username, final String
password) throws JMSException
{
- return createConnectionInternal(username, password, false,
HornetQConnection.TYPE_QUEUE_CONNECTION);
+ return (QueueConnection)createConnectionInternal(username, password, false,
HornetQConnection.TYPE_QUEUE_CONNECTION);
}
// TopicConnectionFactory implementation
--------------------------------------------------------
@@ -130,7 +130,7 @@
public TopicConnection createTopicConnection(final String username, final String
password) throws JMSException
{
- return createConnectionInternal(username, password, false,
HornetQConnection.TYPE_TOPIC_CONNECTION);
+ return (TopicConnection)createConnectionInternal(username, password, false,
HornetQConnection.TYPE_TOPIC_CONNECTION);
}
// XAConnectionFactory implementation
-----------------------------------------------------------
@@ -142,7 +142,7 @@
public XAConnection createXAConnection(final String username, final String password)
throws JMSException
{
- return createConnectionInternal(username, password, true,
HornetQConnection.TYPE_GENERIC_CONNECTION);
+ return (XAConnection)createConnectionInternal(username, password, true,
HornetQConnection.TYPE_GENERIC_CONNECTION);
}
// XAQueueConnectionFactory implementation
------------------------------------------------------
@@ -154,7 +154,7 @@
public XAQueueConnection createXAQueueConnection(final String username, final String
password) throws JMSException
{
- return createConnectionInternal(username, password, true,
HornetQConnection.TYPE_QUEUE_CONNECTION);
+ return (XAQueueConnection)createConnectionInternal(username, password, true,
HornetQConnection.TYPE_QUEUE_CONNECTION);
}
// XATopicConnectionFactory implementation
------------------------------------------------------
@@ -166,7 +166,7 @@
public XATopicConnection createXATopicConnection(final String username, final String
password) throws JMSException
{
- return createConnectionInternal(username, password, true,
HornetQConnection.TYPE_TOPIC_CONNECTION);
+ return (XATopicConnection)createConnectionInternal(username, password, true,
HornetQConnection.TYPE_TOPIC_CONNECTION);
}
// Referenceable implementation
-----------------------------------------------------------------
@@ -604,13 +604,74 @@
// This means there is one underlying remoting connection per jms connection (if
not load balanced)
ClientSessionFactory factory = sessionFactory.copy();
- HornetQConnection connection = new HornetQConnection(username,
- password,
- type,
- clientID,
- dupsOKBatchSize,
- transactionBatchSize,
- factory);
+ HornetQConnection connection = null;
+
+ if (isXA)
+ {
+ if (type == HornetQConnection.TYPE_GENERIC_CONNECTION)
+ {
+ connection = new HornetQXAConnection(username,
+ password,
+ type,
+ clientID,
+ dupsOKBatchSize,
+ transactionBatchSize,
+ factory);
+ }
+ else if (type == HornetQConnection.TYPE_QUEUE_CONNECTION)
+ {
+ connection = new HornetQXAQueueConnection(username,
+ password,
+ type,
+ clientID,
+ dupsOKBatchSize,
+ transactionBatchSize,
+ factory);
+ }
+ else if (type == HornetQConnection.TYPE_TOPIC_CONNECTION)
+ {
+ connection = new HornetQXATopicConnection(username,
+ password,
+ type,
+ clientID,
+ dupsOKBatchSize,
+ transactionBatchSize,
+ factory);
+ }
+ }
+ else
+ {
+ if (type == HornetQConnection.TYPE_GENERIC_CONNECTION)
+ {
+ connection = new HornetQConnection(username,
+ password,
+ type,
+ clientID,
+ dupsOKBatchSize,
+ transactionBatchSize,
+ factory);
+ }
+ else if (type == HornetQConnection.TYPE_QUEUE_CONNECTION)
+ {
+ connection = new HornetQQueueConnection(username,
+ password,
+ type,
+ clientID,
+ dupsOKBatchSize,
+ transactionBatchSize,
+ factory);
+ }
+ else if (type == HornetQConnection.TYPE_TOPIC_CONNECTION)
+ {
+ connection = new HornetQTopicConnection(username,
+ password,
+ type,
+ clientID,
+ dupsOKBatchSize,
+ transactionBatchSize,
+ factory);
+ }
+ }
try
{
Added: trunk/src/main/org/hornetq/jms/client/HornetQQueueConnection.java
===================================================================
--- trunk/src/main/org/hornetq/jms/client/HornetQQueueConnection.java
(rev 0)
+++ trunk/src/main/org/hornetq/jms/client/HornetQQueueConnection.java 2010-11-18 10:50:39
UTC (rev 9911)
@@ -0,0 +1,38 @@
+/*
+ * Copyright 2010 Red Hat, Inc.
+ * Red Hat 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.hornetq.jms.client;
+
+import javax.jms.QueueConnection;
+
+import org.hornetq.api.core.client.ClientSessionFactory;
+
+/**
+ * HornetQ implementation of a JMS QueueConnection.
+ *
+ * @author <a href="mailto:hgao@redhat.com">Howard Gao</a>
+ */
+public class HornetQQueueConnection extends HornetQConnection implements QueueConnection
+{
+ public HornetQQueueConnection(final String username,
+ final String password,
+ final int connectionType,
+ final String clientID,
+ final int dupsOKBatchSize,
+ final int transactionBatchSize,
+ final ClientSessionFactory sessionFactory)
+ {
+ super(username, password, connectionType, clientID, dupsOKBatchSize,
transactionBatchSize, sessionFactory);
+ }
+
+}
Added: trunk/src/main/org/hornetq/jms/client/HornetQTopicConnection.java
===================================================================
--- trunk/src/main/org/hornetq/jms/client/HornetQTopicConnection.java
(rev 0)
+++ trunk/src/main/org/hornetq/jms/client/HornetQTopicConnection.java 2010-11-18 10:50:39
UTC (rev 9911)
@@ -0,0 +1,37 @@
+/*
+ * Copyright 2010 Red Hat, Inc.
+ * Red Hat 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.hornetq.jms.client;
+
+import javax.jms.TopicConnection;
+
+import org.hornetq.api.core.client.ClientSessionFactory;
+
+/**
+ * HornetQ implementation of a JMS TopicConnection.
+ *
+ * @author <a href="mailto:hgao@redhat.com">Howard Gao</a>
+ */
+public class HornetQTopicConnection extends HornetQConnection implements TopicConnection
+{
+ public HornetQTopicConnection(final String username,
+ final String password,
+ final int connectionType,
+ final String clientID,
+ final int dupsOKBatchSize,
+ final int transactionBatchSize,
+ final ClientSessionFactory sessionFactory)
+ {
+ super(username, password, connectionType, clientID, dupsOKBatchSize,
transactionBatchSize, sessionFactory);
+ }
+}
Added: trunk/src/main/org/hornetq/jms/client/HornetQXAConnection.java
===================================================================
--- trunk/src/main/org/hornetq/jms/client/HornetQXAConnection.java
(rev 0)
+++ trunk/src/main/org/hornetq/jms/client/HornetQXAConnection.java 2010-11-18 10:50:39 UTC
(rev 9911)
@@ -0,0 +1,39 @@
+/*
+ * Copyright 2010 Red Hat, Inc.
+ * Red Hat 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.hornetq.jms.client;
+
+import javax.jms.XAConnection;
+
+import org.hornetq.api.core.client.ClientSessionFactory;
+
+/**
+ * HornetQ implementation of a JMS XAConnection.
+ *
+ * @author <a href="mailto:hgao@redhat.com">Howard Gao</a>
+ */
+public class HornetQXAConnection extends HornetQConnection implements XAConnection
+{
+
+ public HornetQXAConnection(final String username,
+ final String password,
+ final int connectionType,
+ final String clientID,
+ final int dupsOKBatchSize,
+ final int transactionBatchSize,
+ final ClientSessionFactory sessionFactory)
+ {
+ super(username, password, connectionType, clientID, dupsOKBatchSize,
transactionBatchSize, sessionFactory);
+ }
+
+}
Added: trunk/src/main/org/hornetq/jms/client/HornetQXAQueueConnection.java
===================================================================
--- trunk/src/main/org/hornetq/jms/client/HornetQXAQueueConnection.java
(rev 0)
+++ trunk/src/main/org/hornetq/jms/client/HornetQXAQueueConnection.java 2010-11-18
10:50:39 UTC (rev 9911)
@@ -0,0 +1,37 @@
+/*
+ * Copyright 2010 Red Hat, Inc.
+ * Red Hat 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.hornetq.jms.client;
+
+import javax.jms.XAQueueConnection;
+
+import org.hornetq.api.core.client.ClientSessionFactory;
+
+/**
+ * HornetQ implementation of a JMS XAQueueConnection.
+ *
+ * @author <a href="mailto:hgao@redhat.com">Howard Gao</a>
+ */
+public class HornetQXAQueueConnection extends HornetQConnection implements
XAQueueConnection
+{
+ public HornetQXAQueueConnection(final String username,
+ final String password,
+ final int connectionType,
+ final String clientID,
+ final int dupsOKBatchSize,
+ final int transactionBatchSize,
+ final ClientSessionFactory sessionFactory)
+ {
+ super(username, password, connectionType, clientID, dupsOKBatchSize,
transactionBatchSize, sessionFactory);
+ }
+}
Added: trunk/src/main/org/hornetq/jms/client/HornetQXATopicConnection.java
===================================================================
--- trunk/src/main/org/hornetq/jms/client/HornetQXATopicConnection.java
(rev 0)
+++ trunk/src/main/org/hornetq/jms/client/HornetQXATopicConnection.java 2010-11-18
10:50:39 UTC (rev 9911)
@@ -0,0 +1,37 @@
+/*
+ * Copyright 2010 Red Hat, Inc.
+ * Red Hat 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.hornetq.jms.client;
+
+import javax.jms.XATopicConnection;
+
+import org.hornetq.api.core.client.ClientSessionFactory;
+
+/**
+ * HornetQ implementation of a JMS XATopicConnection.
+ *
+ * @author <a href="mailto:hgao@redhat.com">Howard Gao</a>
+ */
+public class HornetQXATopicConnection extends HornetQConnection implements
XATopicConnection
+{
+ public HornetQXATopicConnection(final String username,
+ final String password,
+ final int connectionType,
+ final String clientID,
+ final int dupsOKBatchSize,
+ final int transactionBatchSize,
+ final ClientSessionFactory sessionFactory)
+ {
+ super(username, password, connectionType, clientID, dupsOKBatchSize,
transactionBatchSize, sessionFactory);
+ }
+}
Modified: trunk/tests/jms-tests/src/org/hornetq/jms/tests/ConnectionFactoryTest.java
===================================================================
--- trunk/tests/jms-tests/src/org/hornetq/jms/tests/ConnectionFactoryTest.java 2010-11-17
16:32:48 UTC (rev 9910)
+++ trunk/tests/jms-tests/src/org/hornetq/jms/tests/ConnectionFactoryTest.java 2010-11-18
10:50:39 UTC (rev 9911)
@@ -28,8 +28,11 @@
import javax.jms.Topic;
import javax.jms.TopicConnection;
import javax.jms.TopicConnectionFactory;
+import javax.jms.XAConnection;
import javax.jms.XAConnectionFactory;
+import javax.jms.XAQueueConnection;
import javax.jms.XAQueueConnectionFactory;
+import javax.jms.XATopicConnection;
import javax.jms.XATopicConnectionFactory;
import org.hornetq.jms.client.HornetQConnectionFactory;
@@ -389,7 +392,111 @@
assertTrue(factory instanceof TopicConnectionFactory);
assertEquals(2, getTypes(factory));
}
+
+ public void testConnectionTypes() throws Exception
+ {
+ Connection genericConnection = null;
+ XAConnection xaConnection = null;
+ QueueConnection queueConnection = null;
+ TopicConnection topicConnection = null;
+ XAQueueConnection xaQueueConnection = null;
+ XATopicConnection xaTopicConnection = null;
+ ConnectionFactory genericFactory =
(ConnectionFactory)JMSTestCase.ic.lookup("/ConnectionFactory");
+ genericConnection = genericFactory.createConnection();
+ assertConnectionType(genericConnection, "generic");
+
+ XAConnectionFactory xaFactory =
(XAConnectionFactory)JMSTestCase.ic.lookup("/CF_XA_TRUE");
+ xaConnection = xaFactory.createXAConnection();
+ assertConnectionType(xaConnection, "xa");
+
+ QueueConnectionFactory queueCF =
(QueueConnectionFactory)JMSTestCase.ic.lookup("/CF_QUEUE");
+ queueConnection = queueCF.createQueueConnection();
+ assertConnectionType(queueConnection, "queue");
+
+ TopicConnectionFactory topicCF =
(TopicConnectionFactory)JMSTestCase.ic.lookup("/CF_TOPIC");
+ topicConnection = topicCF.createTopicConnection();
+ assertConnectionType(topicConnection, "topic");
+
+ XAQueueConnectionFactory xaQueueCF =
(XAQueueConnectionFactory)JMSTestCase.ic.lookup("/CF_QUEUE_XA_TRUE");
+ xaQueueConnection = xaQueueCF.createXAQueueConnection();
+ assertConnectionType(xaQueueConnection, "xa-queue");
+
+ XATopicConnectionFactory xaTopicCF =
(XATopicConnectionFactory)JMSTestCase.ic.lookup("/CF_TOPIC_XA_TRUE");
+ xaTopicConnection = xaTopicCF.createXATopicConnection();
+ assertConnectionType(xaTopicConnection, "xa-topic");
+
+ genericConnection.close();
+ xaConnection.close();
+ queueConnection.close();
+ topicConnection.close();
+ xaQueueConnection.close();
+ xaTopicConnection.close();
+ }
+
+ private void assertConnectionType(Connection conn, String type)
+ {
+ if ("generic".equals(type))
+ {
+ //generic
+ assertTrue(conn instanceof Connection);
+ assertFalse(conn instanceof XAConnection);
+ assertFalse(conn instanceof QueueConnection);
+ assertFalse(conn instanceof XAQueueConnection);
+ assertFalse(conn instanceof TopicConnection);
+ assertFalse(conn instanceof XATopicConnection);
+ }
+ else if ("queue".equals(type))
+ {
+ assertTrue(conn instanceof Connection);
+ assertFalse(conn instanceof XAConnection);
+ assertTrue(conn instanceof QueueConnection);
+ assertFalse(conn instanceof XAQueueConnection);
+ assertFalse(conn instanceof TopicConnection);
+ assertFalse(conn instanceof XATopicConnection);
+ }
+ else if ("topic".equals(type))
+ {
+ assertTrue(conn instanceof Connection);
+ assertFalse(conn instanceof XAConnection);
+ assertFalse(conn instanceof QueueConnection);
+ assertFalse(conn instanceof XAQueueConnection);
+ assertTrue(conn instanceof TopicConnection);
+ assertFalse(conn instanceof XATopicConnection);
+ }
+ else if ("xa".equals(type))
+ {
+ assertTrue(conn instanceof Connection);
+ assertTrue(conn instanceof XAConnection);
+ assertFalse(conn instanceof QueueConnection);
+ assertFalse(conn instanceof XAQueueConnection);
+ assertFalse(conn instanceof TopicConnection);
+ assertFalse(conn instanceof XATopicConnection);
+ }
+ else if ("xa-queue".equals(type))
+ {
+ assertTrue(conn instanceof Connection);
+ assertTrue(conn instanceof XAConnection);
+ assertTrue(conn instanceof QueueConnection);
+ assertTrue(conn instanceof XAQueueConnection);
+ assertFalse(conn instanceof TopicConnection);
+ assertFalse(conn instanceof XATopicConnection);
+ }
+ else if ("xa-topic".equals(type))
+ {
+ assertTrue(conn instanceof Connection);
+ assertTrue(conn instanceof XAConnection);
+ assertFalse(conn instanceof QueueConnection);
+ assertFalse(conn instanceof XAQueueConnection);
+ assertTrue(conn instanceof TopicConnection);
+ assertTrue(conn instanceof XATopicConnection);
+ }
+ else
+ {
+ fail("Unknown connection type: " + type);
+ }
+ }
+
private int getTypes(HornetQConnectionFactory factory)
{
int num = 0;