X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=datarouter-prov%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Fdmaap%2Fdatarouter%2Freports%2FLatencyReport.java;h=549511b7df545017d7a5ca5b928bafa373eb2b4e;hb=ac7eb459fdc1f405ddb38a8b227e04de23ae1966;hp=ba8f15a094ca6055f58019f7d1d9527ef705024f;hpb=49be863f0005d80724a99acf13f31c4e03c5be68;p=dmaap%2Fdatarouter.git 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) {