aboutsummaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'plugins')
-rw-r--r--plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-jms/src/main/java/org/onap/policy/apex/plugins/event/carrier/jms/ApexJMSConsumer.java44
-rw-r--r--plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-jms/src/main/java/org/onap/policy/apex/plugins/event/carrier/jms/ApexJMSProducer.java6
2 files changed, 17 insertions, 33 deletions
diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-jms/src/main/java/org/onap/policy/apex/plugins/event/carrier/jms/ApexJMSConsumer.java b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-jms/src/main/java/org/onap/policy/apex/plugins/event/carrier/jms/ApexJMSConsumer.java
index 745a1e98c..a96517510 100644
--- a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-jms/src/main/java/org/onap/policy/apex/plugins/event/carrier/jms/ApexJMSConsumer.java
+++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-jms/src/main/java/org/onap/policy/apex/plugins/event/carrier/jms/ApexJMSConsumer.java
@@ -196,53 +196,37 @@ public class ApexJMSConsumer implements MessageListener, ApexEventConsumer, Runn
@Override
public void run() {
// JMS session and message consumer for receiving messages
- Session jmsSession = null;
- MessageConsumer messageConsumer = null;
-
- // Create a session to the JMS server
- try {
- jmsSession = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+ try (Session jmsSession = connection.createSession(false, Session.AUTO_ACKNOWLEDGE)) {
+ // Create a message consumer for reception of messages and set this class as a message listener
+ createMessageConsumer(jmsSession);
} catch (final Exception e) {
final String errorMessage = "failed to create a JMS session towards the JMS server for receiving messages";
LOGGER.warn(errorMessage, e);
throw new ApexEventRuntimeException(errorMessage, e);
}
-
- // Create a message consumer for reception of messages and set this class as a message listener
- try {
- messageConsumer = jmsSession.createConsumer(jmsIncomingTopic);
- messageConsumer.setMessageListener(this);
- } catch (final Exception e) {
- final String errorMessage = "failed to create a JMS message consumer for receiving messages";
- LOGGER.warn(errorMessage, e);
- throw new ApexEventRuntimeException(errorMessage, e);
- }
-
// Everything is now set up
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("event receiver " + this.getClass().getName() + ":" + this.name + " subscribed to JMS topic: "
+ jmsConsumerProperties.getConsumerTopic());
}
-
// The endless loop that receives events over JMS
while (consumerThread.isAlive() && !stopOrderedFlag) {
ThreadUtilities.sleep(jmsConsumerProperties.getConsumerWaitTime());
}
+ }
- // Close the message consumer
- try {
- messageConsumer.close();
- } catch (final Exception e) {
- final String errorMessage = "failed to close the JMS message consumer for receiving messages";
- LOGGER.warn(errorMessage, e);
- }
-
- // Close the session
- try {
- jmsSession.close();
+ /**
+ * The helper function to create a message consumer from a given JMS session
+ *
+ * @param jmsSession a JMS session
+ */
+ private void createMessageConsumer(Session jmsSession) {
+ try (MessageConsumer messageConsumer = jmsSession.createConsumer(jmsIncomingTopic)) {
+ messageConsumer.setMessageListener(this);
} catch (final Exception e) {
- final String errorMessage = "failed to close the JMS session for receiving messages";
+ final String errorMessage = "failed to create a JMS message consumer for receiving messages";
LOGGER.warn(errorMessage, e);
+ throw new ApexEventRuntimeException(errorMessage, e);
}
}
diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-jms/src/main/java/org/onap/policy/apex/plugins/event/carrier/jms/ApexJMSProducer.java b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-jms/src/main/java/org/onap/policy/apex/plugins/event/carrier/jms/ApexJMSProducer.java
index 017f07f6f..edf78637d 100644
--- a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-jms/src/main/java/org/onap/policy/apex/plugins/event/carrier/jms/ApexJMSProducer.java
+++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-jms/src/main/java/org/onap/policy/apex/plugins/event/carrier/jms/ApexJMSProducer.java
@@ -86,9 +86,9 @@ public class ApexJMSProducer implements ApexEventProducer {
// Check and get the JMS Properties
if (!(producerParameters.getCarrierTechnologyParameters() instanceof JMSCarrierTechnologyParameters)) {
- LOGGER.warn("specified producer properties are not applicable to a JMS producer (" + this.name + ")");
- throw new ApexEventException(
- "specified producer properties are not applicable to a JMS producer (" + this.name + ")");
+ final String errorMessage = "specified producer properties are not applicable to a JMS producer (" + this.name + ")";
+ LOGGER.warn(errorMessage);
+ throw new ApexEventException(errorMessage);
}
jmsProducerProperties = (JMSCarrierTechnologyParameters) producerParameters.getCarrierTechnologyParameters();