|
|||||||||||||||||||
| 30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover | |||||||||||||||||||
| Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
| DefaultJmsProducer.java | 0% | 64.3% | 80% | 61.9% |
|
||||||||||||||
| 1 |
/**
|
|
| 2 |
*
|
|
| 3 |
* Copyright 2005 LogicBlaze, Inc.
|
|
| 4 |
*
|
|
| 5 |
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
| 6 |
* you may not use this file except in compliance with the License.
|
|
| 7 |
* You may obtain a copy of the License at
|
|
| 8 |
*
|
|
| 9 |
* http://www.apache.org/licenses/LICENSE-2.0
|
|
| 10 |
*
|
|
| 11 |
* Unless required by applicable law or agreed to in writing, software
|
|
| 12 |
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
| 13 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
| 14 |
* See the License for the specific language governing permissions and
|
|
| 15 |
* limitations under the License.
|
|
| 16 |
*
|
|
| 17 |
**/
|
|
| 18 |
package org.logicblaze.lingo.jms.impl;
|
|
| 19 |
|
|
| 20 |
import javax.jms.Connection;
|
|
| 21 |
import javax.jms.ConnectionFactory;
|
|
| 22 |
import javax.jms.JMSException;
|
|
| 23 |
import javax.jms.MessageProducer;
|
|
| 24 |
import javax.jms.Session;
|
|
| 25 |
|
|
| 26 |
/**
|
|
| 27 |
* A default implementation of the {@link org.logicblaze.lingo.jms.JmsProducer} which contains a reference to the
|
|
| 28 |
* connection, session and producer so that it can easily close down all its resources properly.
|
|
| 29 |
*
|
|
| 30 |
* @version $Revision: 1.1 $
|
|
| 31 |
*/
|
|
| 32 |
public class DefaultJmsProducer extends JmsProducerImpl { |
|
| 33 |
|
|
| 34 |
private Connection connection;
|
|
| 35 |
|
|
| 36 | 46 |
public static DefaultJmsProducer newInstance(ConnectionFactory factory) throws JMSException { |
| 37 | 46 |
Connection connection = factory.createConnection(); |
| 38 |
|
|
| 39 |
// lets start the connection in case that we consume on the same connection
|
|
| 40 | 46 |
connection.start(); |
| 41 |
|
|
| 42 | 46 |
return newInstance(connection);
|
| 43 |
} |
|
| 44 |
|
|
| 45 | 46 |
public static DefaultJmsProducer newInstance(Connection connection) throws JMSException { |
| 46 | 46 |
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
|
| 47 | 46 |
MessageProducer producer = session.createProducer(null);
|
| 48 | 46 |
return new DefaultJmsProducer(connection, session, producer); |
| 49 |
} |
|
| 50 |
|
|
| 51 | 46 |
public DefaultJmsProducer(Connection connection, Session session, MessageProducer producer) {
|
| 52 | 46 |
super(session, producer);
|
| 53 | 46 |
this.connection = connection;
|
| 54 |
} |
|
| 55 |
|
|
| 56 | 4 |
public Connection getConnection() {
|
| 57 | 4 |
return connection;
|
| 58 |
} |
|
| 59 |
|
|
| 60 | 0 |
public void close() throws JMSException { |
| 61 | 0 |
super.close();
|
| 62 | 0 |
if (connection != null) { |
| 63 | 0 |
Connection tmp = connection; |
| 64 | 0 |
connection = null;
|
| 65 | 0 |
tmp.close(); |
| 66 |
} |
|
| 67 |
} |
|
| 68 |
} |
|
| 69 |
|
|
||||||||||