X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=datarouter-prov%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Fdmaap%2Fdatarouter%2Fprovisioning%2Futils%2FLogfileLoader.java;h=6c5a13fdb8de1987b1fc9efabf1032aefbee4c40;hb=5775de7b0fc84a29511dc4a1a480c3ab32da2ade;hp=8975f1612f4f96203f07cf6b490390e2b904951d;hpb=83ada605bfbc4a9f91f320627c3a2062581a6099;p=dmaap%2Fdatarouter.git diff --git a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/utils/LogfileLoader.java b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/utils/LogfileLoader.java index 8975f161..6c5a13fd 100644 --- a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/utils/LogfileLoader.java +++ b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/utils/LogfileLoader.java @@ -82,7 +82,7 @@ public class LogfileLoader extends Thread { /** * This is a singleton -- there is only one LogfileLoader object in the server */ - private static LogfileLoader p; + private static LogfileLoader logfileLoader; /** * Get the singleton LogfileLoader object, and start it if it is not running. @@ -90,17 +90,17 @@ public class LogfileLoader extends Thread { * @return the LogfileLoader */ public static synchronized LogfileLoader getLoader() { - if (p == null) - p = new LogfileLoader(); - if (!p.isAlive()) - p.start(); - return p; + if (logfileLoader == null) + logfileLoader = new LogfileLoader(); + if (!logfileLoader.isAlive()) + logfileLoader.start(); + return logfileLoader; } /** * The PreparedStatement which is loaded by a Loadable. */ - public static final String INSERT_SQL = "insert into LOG_RECORDS values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; + public static final String INSERT_SQL = "insert into LOG_RECORDS values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; /** * Each server can assign this many IDs */ @@ -188,6 +188,7 @@ public class LogfileLoader extends Thread { try { Thread.sleep(1000L); } catch (InterruptedException e) { + Thread.currentThread().interrupt(); } idle = false; } else { @@ -213,12 +214,11 @@ public class LogfileLoader extends Thread { } } catch (Exception e) { logger.warn("PROV0020: Caught exception in LogfileLoader: " + e); - e.printStackTrace(); } } } - private boolean pruneRecords() { + boolean pruneRecords() { boolean did1 = false; long count = countRecords(); long threshold = DEFAULT_LOG_RETENTION; @@ -274,7 +274,7 @@ public class LogfileLoader extends Thread { } } catch (SQLException e) { System.err.println(e); - e.printStackTrace(); + logger.error(e); } finally { db.release(conn); } @@ -282,7 +282,7 @@ public class LogfileLoader extends Thread { return did1; } - private long countRecords() { + long countRecords() { long count = 0; Connection conn = null; try { @@ -296,14 +296,14 @@ public class LogfileLoader extends Thread { } } catch (SQLException e) { System.err.println(e); - e.printStackTrace(); + logger.error(e); } finally { db.release(conn); } return count; } - private Map getHistogram() { + Map getHistogram() { Map map = new HashMap(); Connection conn = null; try { @@ -321,7 +321,7 @@ public class LogfileLoader extends Thread { } } catch (SQLException e) { System.err.println(e); - e.printStackTrace(); + logger.error(e); } finally { db.release(conn); } @@ -332,26 +332,25 @@ public class LogfileLoader extends Thread { Connection conn = null; try { conn = db.getConnection(); - Statement stmt = conn.createStatement(); - // Build a bitset of all records in the LOG_RECORDS table - // We need to run this SELECT in stages, because otherwise we run out of memory! RLEBitSet nbs = new RLEBitSet(); - final long stepsize = 6000000L; - boolean go_again = true; - for (long i = 0; go_again; i += stepsize) { - String sql = String.format("select RECORD_ID from LOG_RECORDS LIMIT %d,%d", i, stepsize); - try(ResultSet rs = stmt.executeQuery(sql)) { - go_again = false; - while (rs.next()) { - long n = rs.getLong("RECORD_ID"); - nbs.set(n); - go_again = true; + try(Statement stmt = conn.createStatement()) { + // Build a bitset of all records in the LOG_RECORDS table + // We need to run this SELECT in stages, because otherwise we run out of memory! + final long stepsize = 6000000L; + boolean go_again = true; + for (long i = 0; go_again; i += stepsize) { + String sql = String.format("select RECORD_ID from LOG_RECORDS LIMIT %d,%d", i, stepsize); + try (ResultSet rs = stmt.executeQuery(sql)) { + go_again = false; + while (rs.next()) { + long n = rs.getLong("RECORD_ID"); + nbs.set(n); + go_again = true; + } } } } - stmt.close(); seq_set = nbs; - // Compare with the range for this server // Determine the next ID for this set of record IDs RLEBitSet tbs = (RLEBitSet) nbs.clone(); @@ -376,14 +375,14 @@ public class LogfileLoader extends Thread { logger.debug(String.format("initializeNextid, next ID is %d (%x)", nextid, nextid)); } catch (SQLException e) { System.err.println(e); - e.printStackTrace(); + logger.error(e); } finally { db.release(conn); } } @SuppressWarnings("resource") - private int[] process(File f) { + int[] process(File f) { int ok = 0, total = 0; try { Connection conn = db.getConnection(); @@ -417,19 +416,15 @@ public class LogfileLoader extends Thread { } catch (SQLException e) { logger.warn("PROV8003 Invalid value in record: " + line); logger.debug(e); - e.printStackTrace(); } catch (NumberFormatException e) { logger.warn("PROV8004 Invalid number in record: " + line); logger.debug(e); - e.printStackTrace(); } catch (ParseException e) { logger.warn("PROV8005 Invalid date in record: " + line); logger.debug(e); - e.printStackTrace(); } catch (Exception e) { logger.warn("PROV8006 Invalid pattern in record: " + line); logger.debug(e); - e.printStackTrace(); } total++; } @@ -447,7 +442,7 @@ public class LogfileLoader extends Thread { return new int[]{ok, total}; } - private Loadable[] buildRecords(String line) throws ParseException { + Loadable[] buildRecords(String line) throws ParseException { String[] pp = line.split("\\|"); if (pp != null && pp.length >= 7) { String rtype = pp[1].toUpperCase();