Fix sonar issues in messagerouter/dmaapclient 43/88143/1
authorParshad Patel <pars.patel@samsung.com>
Tue, 21 May 2019 07:47:09 +0000 (16:47 +0900)
committerParshad Patel <pars.patel@samsung.com>
Tue, 21 May 2019 07:54:35 +0000 (16:54 +0900)
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 <pars.patel@samsung.com>
src/main/java/org/onap/dmaap/mr/client/impl/MRSimplerBatchPublisher.java
src/main/java/org/onap/dmaap/mr/dme/client/PreferredRouteRequestHandler.java
src/main/java/org/onap/dmaap/mr/dme/client/SimpleExampleConsumer.java

index 4d9ab8d..fb57b94 100644 (file)
@@ -151,7 +151,7 @@ public class MRSimplerBatchPublisher extends MRBaseClient implements MRBatchingP
 
        @Override
        public int send(message msg) {
-               final LinkedList<message> list = new LinkedList<message>();
+               final LinkedList<message> list = new LinkedList<>();
                list.add(msg);
                return send(list);
        }
@@ -210,7 +210,7 @@ public class MRSimplerBatchPublisher extends MRBaseClient implements MRBatchingP
                }
 
                synchronized (this) {
-                       final LinkedList<message> result = new LinkedList<message>();
+                       final LinkedList<message> 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<TimestampedMessage>();
+               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<TimestampedMessage>();
+               fPending = new LinkedBlockingQueue<>();
                fDontSendUntilMs = 0;
                fExec = new ScheduledThreadPoolExecutor(1);
                fExec.scheduleAtFixedRate(new Runnable() {
index 4c2e546..dd0b286 100644 (file)
@@ -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);
        }
index 6fb02a5..5bb7dad 100644 (file)
@@ -82,7 +82,7 @@ public class SimpleExampleConsumer {
                                }
                        }
                } catch (Exception x) {
-                       logger.error(x.toString());
+                       logger.error("Exception in SimpleExampleConsumer", x);
                }
        }
 }