From: Parshad Patel Date: Tue, 21 May 2019 07:47:09 +0000 (+0900) Subject: Fix sonar issues in messagerouter/dmaapclient X-Git-Tag: 1.1.10~5 X-Git-Url: https://gerrit.onap.org/r/gitweb?p=dmaap%2Fmessagerouter%2Fdmaapclient.git;a=commitdiff_plain;h=437cec5434271167a15c4fcdd19ab60d84774c13 Fix sonar issues in messagerouter/dmaapclient Fix Replace the type specification in this constructor call with the diamond operator ("<>") Fix Either log or rethrow this exception Fix Merge this if statement with the enclosing one Fix Use isEmpty() to check whether the collection is empty or not Issue-ID: DMAAP-894 Change-Id: Ifb8800e032f285adb1c35ffe100e0b5be2b3cde2 Signed-off-by: Parshad Patel --- diff --git a/src/main/java/org/onap/dmaap/mr/client/impl/MRSimplerBatchPublisher.java b/src/main/java/org/onap/dmaap/mr/client/impl/MRSimplerBatchPublisher.java index 4d9ab8d..fb57b94 100644 --- a/src/main/java/org/onap/dmaap/mr/client/impl/MRSimplerBatchPublisher.java +++ b/src/main/java/org/onap/dmaap/mr/client/impl/MRSimplerBatchPublisher.java @@ -151,7 +151,7 @@ public class MRSimplerBatchPublisher extends MRBaseClient implements MRBatchingP @Override public int send(message msg) { - final LinkedList list = new LinkedList(); + final LinkedList list = new LinkedList<>(); list.add(msg); return send(list); } @@ -210,7 +210,7 @@ public class MRSimplerBatchPublisher extends MRBaseClient implements MRBatchingP } synchronized (this) { - final LinkedList result = new LinkedList(); + final LinkedList result = new LinkedList<>(); fPending.drainTo(result); return result; } @@ -223,13 +223,11 @@ public class MRSimplerBatchPublisher extends MRBaseClient implements MRBatchingP * @param force */ private synchronized void send(boolean force) { - if (force || shouldSendNow()) { - if (!sendBatch()) { + if ((force || shouldSendNow()) && !sendBatch()) { getLog().warn("Send failed, " + fPending.size() + " message to send."); // note the time for back-off fDontSendUntilMs = sfWaitAfterError + Clock.now(); - } } } @@ -282,7 +280,7 @@ public class MRSimplerBatchPublisher extends MRBaseClient implements MRBatchingP private synchronized boolean sendBatch() { // it's possible for this call to be made with an empty list. in this // case, just return. - if (fPending.size() < 1) { + if (fPending.isEmpty()) { return true; } @@ -346,7 +344,7 @@ public class MRSimplerBatchPublisher extends MRBaseClient implements MRBatchingP sender.setPayload(os.toString()); String dmeResponse = sender.sendAndWait(5000L); - final String logLine = "MR reply ok (" + (Clock.now() - startMs) + " ms):" + dmeResponse.toString(); + final String logLine = "MR reply ok (" + (Clock.now() - startMs) + " ms):" + dmeResponse; getLog().info(logLine); fPending.clear(); return true; @@ -405,12 +403,6 @@ public class MRSimplerBatchPublisher extends MRBaseClient implements MRBatchingP fPending.clear(); return true; } - } catch (IllegalArgumentException x) { - getLog().warn(x.getMessage(), x); - } catch (IOException x) { - getLog().warn(x.getMessage(), x); - } catch (HttpException x) { - getLog().warn(x.getMessage(), x); } catch (Exception x) { getLog().warn(x.getMessage(), x); } @@ -604,7 +596,7 @@ public class MRSimplerBatchPublisher extends MRBaseClient implements MRBatchingP } finally { - if (fPending.size() > 0) { + if (!fPending.isEmpty()) { getLog().warn("Send failed, " + fPending.size() + " message to send."); pubResponse.setPendingMsgs(fPending.size()); } @@ -835,7 +827,7 @@ public class MRSimplerBatchPublisher extends MRBaseClient implements MRBatchingP fMaxBatchAgeMs = maxBatchAgeMs; fCompress = compress; - fPending = new LinkedBlockingQueue(); + fPending = new LinkedBlockingQueue<>(); fDontSendUntilMs = 0; fExec = new ScheduledThreadPoolExecutor(1); pubResponse = new MRPublisherResponse(); @@ -857,7 +849,7 @@ public class MRSimplerBatchPublisher extends MRBaseClient implements MRBatchingP fMaxBatchAgeMs = maxBatchAgeMs; fCompress = compress; threadOccuranceTime = httpThreadOccurnace; - fPending = new LinkedBlockingQueue(); + fPending = new LinkedBlockingQueue<>(); fDontSendUntilMs = 0; fExec = new ScheduledThreadPoolExecutor(1); fExec.scheduleAtFixedRate(new Runnable() { diff --git a/src/main/java/org/onap/dmaap/mr/dme/client/PreferredRouteRequestHandler.java b/src/main/java/org/onap/dmaap/mr/dme/client/PreferredRouteRequestHandler.java index 4c2e546..dd0b286 100644 --- a/src/main/java/org/onap/dmaap/mr/dme/client/PreferredRouteRequestHandler.java +++ b/src/main/java/org/onap/dmaap/mr/dme/client/PreferredRouteRequestHandler.java @@ -47,7 +47,7 @@ public class PreferredRouteRequestHandler implements DME2ExchangeRequestHandler MRClientFactory.prop.load(MRClientFactory.routeReader); } catch (Exception ex) { - logger.error("Request Router Error " + ex); + logger.error("Request Router Error ", ex); } return MRClientFactory.prop.getProperty(routeKey); } diff --git a/src/main/java/org/onap/dmaap/mr/dme/client/SimpleExampleConsumer.java b/src/main/java/org/onap/dmaap/mr/dme/client/SimpleExampleConsumer.java index 6fb02a5..5bb7dad 100644 --- a/src/main/java/org/onap/dmaap/mr/dme/client/SimpleExampleConsumer.java +++ b/src/main/java/org/onap/dmaap/mr/dme/client/SimpleExampleConsumer.java @@ -82,7 +82,7 @@ public class SimpleExampleConsumer { } } } catch (Exception x) { - logger.error(x.toString()); + logger.error("Exception in SimpleExampleConsumer", x); } } }