Skip to content

Package: JmsProducerWrapper

JmsProducerWrapper

nameinstructionbranchcomplexitylinemethod
JmsProducerWrapper(ActiveMQConnectionFactory, String, boolean, boolean)
M: 45 C: 0
0%
M: 6 C: 0
0%
M: 4 C: 0
0%
M: 10 C: 0
0%
M: 1 C: 0
0%
close()
M: 12 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 5 C: 0
0%
M: 1 C: 0
0%
finalize()
M: 5 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
getDestination()
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
static {...}
M: 4 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /*******************************************************************************
2: * Copyright (c) 2016, 2022 Eurotech and/or its affiliates and others
3: *
4: * This program and the accompanying materials are made
5: * available under the terms of the Eclipse Public License 2.0
6: * which is available at https://www.eclipse.org/legal/epl-2.0/
7: *
8: * SPDX-License-Identifier: EPL-2.0
9: *
10: * Contributors:
11: * Eurotech - initial API and implementation
12: *******************************************************************************/
13: package org.eclipse.kapua.broker.core.pool;
14:
15: import javax.jms.Connection;
16: import javax.jms.JMSException;
17: import javax.jms.MessageProducer;
18: import javax.jms.Session;
19:
20: import org.apache.activemq.ActiveMQConnectionFactory;
21: import org.eclipse.kapua.KapuaException;
22: import org.slf4j.Logger;
23: import org.slf4j.LoggerFactory;
24:
25: /**
26: * Jms producer wrapper.<BR>
27: * This class wrap a single session per connection and manage the close operation of connection on session close.<BR>
28: * The connection is taken from a connection pool ({@link org.apache.activemq.ActiveMQConnectionFactory})
29: *
30: * @since 1.0
31: */
32: public abstract class JmsProducerWrapper {
33:
34: private static final Logger logger = LoggerFactory.getLogger(JmsProducerWrapper.class);
35:
36: protected String destination;
37: protected Connection connection;
38: protected Session session;
39: protected MessageProducer producer;
40:
41: /**
42: *
43: * @param vmconnFactory
44: * @param destination
45: * if it's null the producer will not be bound to any destination so it can sends messages to the whole topic space.<BR>
46: * Otherwise if it isn't null the producer will be bound to a queue destination as specified by the parameter.
47: * @param transacted
48: * @param start
49: * start activeMQ connection
50: * @throws JMSException
51: * @throws KapuaException
52: */
53: protected JmsProducerWrapper(ActiveMQConnectionFactory vmconnFactory, String destination, boolean transacted, boolean start) throws JMSException, KapuaException {
54: connection = vmconnFactory.createConnection();
55:• if (start == true) {
56: connection.start();
57: }
58: session = connection.createSession(transacted, Session.AUTO_ACKNOWLEDGE);
59:• if (destination != null && destination.trim().length() > 0) {
60: producer = session.createProducer(session.createQueue(destination));
61: } else {
62: producer = session.createProducer(null);
63: }
64: this.destination = destination;
65: }
66:
67: public void close() {
68: try {
69: connection.close();
70: } catch (JMSException e) {
71: logger.error("Exception on connection close {}", e.getMessage(), e);
72: }
73: }
74:
75: public String getDestination() {
76: return destination;
77: }
78:
79: @Override
80: protected void finalize() throws Throwable {
81: close();
82: super.finalize();
83: }
84:
85: }