1 10 11 package org.mule.providers.oracle.jms; 12 13 import java.util.ArrayList ; 14 import java.util.Iterator ; 15 import java.util.List ; 16 17 import javax.jms.Connection ; 18 import javax.jms.ConnectionConsumer ; 19 import javax.jms.ConnectionMetaData ; 20 import javax.jms.ExceptionListener ; 21 import javax.jms.JMSException ; 22 import javax.jms.Queue ; 23 import javax.jms.QueueConnection ; 24 import javax.jms.QueueSession ; 25 import javax.jms.ServerSessionPool ; 26 import javax.jms.Topic ; 27 import javax.jms.TopicConnection ; 28 import javax.jms.TopicSession ; 29 30 import oracle.jms.AQjmsConnection; 31 import oracle.jms.AQjmsQueueConnectionFactory; 32 import oracle.jms.AQjmsTopicConnectionFactory; 33 34 import org.apache.commons.logging.Log; 35 import org.apache.commons.logging.LogFactory; 36 37 public class OracleJmsConnection implements TopicConnection , QueueConnection 38 { 39 40 private TopicConnection topicConnection; 41 private QueueConnection queueConnection; 42 43 49 private List connections; 50 51 54 private OracleJmsConnector connector; 55 56 public OracleJmsConnection(OracleJmsConnector connector) 57 { 58 this.connector = connector; 59 connections = new ArrayList (); 60 } 61 62 63 public void start() throws JMSException 64 { 65 Connection jmsConnection = null; 66 67 for (Iterator i = connections.iterator(); i.hasNext();) 68 { 69 jmsConnection = (Connection )i.next(); 70 if (jmsConnection != null) 71 { 72 jmsConnection.start(); 73 } 74 } 75 } 76 77 78 public void stop() throws JMSException 79 { 80 Connection jmsConnection = null; 81 82 for (Iterator i = connections.iterator(); i.hasNext();) 83 { 84 jmsConnection = (Connection )i.next(); 85 if (jmsConnection != null) 86 { 87 jmsConnection.stop(); 88 } 89 } 90 } 91 92 93 public void close() throws JMSException 94 { 95 Connection jmsConnection; 96 97 for (Iterator i = connections.iterator(); i.hasNext();) 99 { 100 jmsConnection = (Connection )i.next(); 101 if (jmsConnection != null) 102 { 103 try 104 { 105 connector.close(((AQjmsConnection)jmsConnection).getCurrentJmsSession()); 107 jmsConnection.close(); 109 } 110 catch (JMSException e) 111 { 112 logger.error("Unable to close Oracle JMS connection: " + e.getMessage()); 113 } 114 } 115 } 116 } 117 118 protected QueueConnection getQueueConnection() throws JMSException 119 { 120 QueueConnection connection; 121 122 if (connector.isMultipleSessionsPerConnection()) 123 { 124 if (queueConnection == null) 125 { 126 queueConnection = AQjmsQueueConnectionFactory.createQueueConnection(connector.getJdbcConnection()); 127 queueConnection.start(); 128 } 129 connection = queueConnection; 130 } 131 else 132 { 133 connection = AQjmsQueueConnectionFactory.createQueueConnection(connector.getJdbcConnection()); 134 connection.start(); 135 connections.add(connection); 137 } 138 return connection; 139 } 140 141 protected TopicConnection getTopicConnection() throws JMSException 142 { 143 TopicConnection connection; 144 145 if (connector.isMultipleSessionsPerConnection()) 146 { 147 if (topicConnection == null) 148 { 149 topicConnection = AQjmsTopicConnectionFactory.createTopicConnection(connector.getJdbcConnection()); 150 topicConnection.start(); 151 } 152 connection = topicConnection; 153 } 154 else 155 { 156 connection = AQjmsTopicConnectionFactory.createTopicConnection(connector.getJdbcConnection()); 157 connection.start(); 158 connections.add(connection); 160 } 161 connection.start(); 162 return connection; 163 } 164 165 public QueueSession createQueueSession(boolean transacted, int ackMode) throws JMSException 166 { 167 return getQueueConnection().createQueueSession(transacted, ackMode); 168 } 169 170 public TopicSession createTopicSession(boolean transacted, int ackMode) throws JMSException 171 { 172 return getTopicConnection().createTopicSession(transacted, ackMode); 173 } 174 175 public ConnectionConsumer createConnectionConsumer(Topic arg0, 176 String arg1, 177 ServerSessionPool arg2, 178 int arg3) throws JMSException 179 { 180 return getTopicConnection().createConnectionConsumer(arg0, arg1, arg2, arg3); 181 } 182 183 public ConnectionConsumer createDurableConnectionConsumer(Topic arg0, 184 String arg1, 185 String arg2, 186 ServerSessionPool arg3, 187 int arg4) throws JMSException 188 { 189 return getTopicConnection().createDurableConnectionConsumer(arg0, arg1, arg2, arg3, arg4); 190 } 191 192 public ConnectionConsumer createConnectionConsumer(Queue arg0, 193 String arg1, 194 ServerSessionPool arg2, 195 int arg3) throws JMSException 196 { 197 return getQueueConnection().createConnectionConsumer(arg0, arg1, arg2, arg3); 198 } 199 200 public String getClientID() throws JMSException 202 { 203 return null; 204 } 205 206 public ExceptionListener getExceptionListener() throws JMSException 208 { 209 return null; 210 } 211 212 public ConnectionMetaData getMetaData() throws JMSException 214 { 215 return null; 216 } 217 218 public void setClientID(String arg0) throws JMSException 219 { 220 } 222 223 public void setExceptionListener(ExceptionListener arg0) throws JMSException 224 { 225 } 227 228 private static Log logger = LogFactory.getLog(OracleJmsConnection.class); 229 } 230 | Popular Tags |