diff options
author | Ram Koya <rk541m@att.com> | 2018-08-30 13:48:56 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2018-08-30 13:48:56 +0000 |
commit | 0422ec9144284e0ac5b4388d87e13d9631a52f52 (patch) | |
tree | 948648d0a61dc226ed5b8e78880721cd3dee6f79 /datarouter-prov/src | |
parent | 558ff8c21fd0fd0112caf7cdbe105c6eb69585e8 (diff) | |
parent | ac7eb459fdc1f405ddb38a8b227e04de23ae1966 (diff) |
Merge "Fixed Sonar Issues in LatencyReport.Java"
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) {
|