summaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
authorDinh Danh Le <dinh.danh.le@ericsson.com>2018-06-28 12:05:08 +0100
committerDinh Danh Le <dinh.danh.le@ericsson.com>2018-06-28 17:48:24 +0100
commit751f4a09d7093d5204614e08092551d4b80dc042 (patch)
tree0421aacf7af0c4843ef7b2f763e0342292c6ce19 /plugins
parent7c2b947460d0795b29c9c23f1d7373a27ae7bc9e (diff)
Fixing sonar bugs in package ..auth.clieditor
Change-Id: Ie0aa788ef9ea4e574c65928787c9be2ef72a6a61 Issue-ID: POLICY-862 Signed-off-by: Dinh Danh Le <dinh.danh.le@ericsson.com>
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();