diff options
author | Amaresh Kumar <kamaresh@in.ibm.com> | 2018-08-30 17:45:54 +0530 |
---|---|---|
committer | Amaresh Kumar <kamaresh@in.ibm.com> | 2018-08-30 17:53:34 +0530 |
commit | ac7eb459fdc1f405ddb38a8b227e04de23ae1966 (patch) | |
tree | 6a7bf56938ae0f172870f0e373ef44c0b9fff016 /datarouter-prov/src | |
parent | 49be863f0005d80724a99acf13f31c4e03c5be68 (diff) |
Fixed Sonar Issues in LatencyReport.Java
Fixed 3 Sonar issues.
Issue-ID: DMAAP-676
Change-Id: I5f1862843a10eae8f9ba7f0d04a635c5f95b807e
Signed-off-by: Amaresh Kumar <kamaresh@in.ibm.com>
Diffstat (limited to 'datarouter-prov/src')
-rw-r--r-- | datarouter-prov/src/main/java/org/onap/dmaap/datarouter/reports/LatencyReport.java | 58 |
1 files changed, 28 insertions, 30 deletions
diff --git a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/reports/LatencyReport.java b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/reports/LatencyReport.java index ba8f15a0..549511b7 100644 --- a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/reports/LatencyReport.java +++ b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/reports/LatencyReport.java @@ -145,40 +145,38 @@ public class LatencyReport extends ReportBase { DB db = new DB();
@SuppressWarnings("resource")
Connection conn = db.getConnection();
- PreparedStatement ps = conn.prepareStatement(SELECT_SQL);
+ try(PreparedStatement ps = conn.prepareStatement(SELECT_SQL)){
ps.setLong(1, from);
ps.setLong(2, to);
- ResultSet rs = ps.executeQuery();
- PrintWriter os = new PrintWriter(outfile);
- os.println("recordid,feedid,uri,size,min,max,avg,fanout");
- Counters c = null;
- while (rs.next()) {
- long etime = rs.getLong("EVENT_TIME");
- String type = rs.getString("TYPE");
- String id = rs.getString("PUBLISH_ID");
- String fid = rs.getString("FEED_FILEID");
- int feed = rs.getInt("FEEDID");
- long clen = rs.getLong("CONTENT_LENGTH");
- if (c != null && !id.equals(c.id)) {
- String line = id + "," + c.toString();
- os.println(line);
- c = null;
+ try(ResultSet rs = ps.executeQuery()) {
+ try(PrintWriter os = new PrintWriter(outfile)) {
+ os.println("recordid,feedid,uri,size,min,max,avg,fanout");
+ Counters c = null;
+ while (rs.next()) {
+ long etime = rs.getLong("EVENT_TIME");
+ String type = rs.getString("TYPE");
+ String id = rs.getString("PUBLISH_ID");
+ String fid = rs.getString("FEED_FILEID");
+ int feed = rs.getInt("FEEDID");
+ long clen = rs.getLong("CONTENT_LENGTH");
+ if (c != null && !id.equals(c.id)) {
+ String line = id + "," + c.toString();
+ os.println(line);
+ c = null;
+ }
+ if (c == null) {
+ c = new Counters(id, feed, clen, fid);
+ }
+ if (feed != c.feedid)
+ System.err.println("Feed ID mismatch, " + feed + " <=> " + c.feedid);
+ if (clen != c.clen)
+ System.err.println("Cont Len mismatch, " + clen + " <=> " + c.clen);
+ c.addEvent(type, etime);
+ }
}
- if (c == null) {
- c = new Counters(id, feed, clen, fid);
- }
- if (feed != c.feedid)
- System.err.println("Feed ID mismatch, " + feed + " <=> " + c.feedid);
- if (clen != c.clen)
- System.err.println("Cont Len mismatch, " + clen + " <=> " + c.clen);
-// if (fid != c.fileid)
-// System.err.println("File ID mismatch, "+fid+" <=> "+c.fileid);
- c.addEvent(type, etime);
+ db.release(conn);
+ }
}
- rs.close();
- ps.close();
- db.release(conn);
- os.close();
} catch (FileNotFoundException e) {
System.err.println("File cannot be written: " + outfile);
} catch (SQLException e) {
|