/** * Creates a new context with the given debugging description and the expected runtime. * * @param description a provider for a description used for debugging purposes * @param expectedDuration the expected duration of the whole batch operation */ public BatchContext(Supplier<String> description, Duration expectedDuration) { this.op = new Operation(description, expectedDuration); }
@Override public void close() throws IOException { safeClose(); op.close(); }
private static void outputActiveOperations() { if (!Operation.getActiveOperations().isEmpty()) { LOG.INFO("Active Operations"); LOG.INFO(SEPARATOR_LINE); for (Operation op : Operation.getActiveOperations()) { LOG.INFO(op.toString()); } LOG.INFO(SEPARATOR_LINE); } }
@Override public void close() { ops.remove(this); if (isOvertime()) { Tasks.LOG.WARN(toString()); } }
@Override public void gather(MetricsCollector collector) { collector.metric("kernel_active_operations", "active-operations", "Active-Operations", ops.size(), null); collector.metric("kernel_hanging_operations", "hanging-operations", "Hanging-Operations", getActiveOperations().stream().filter(Operation::isOvertime).count(), null); } }
@Override public String toString() { if (name == null) { name = nameProvider.get(); } String result = name + " (" + w.duration() + "/" + NLS.convertDuration(timeout.getSeconds(), true, false) + ")"; if (isOvertime()) { result += " OVERTIME!"; } return result; }
/** * Creates a new connection to the database. * <p> * You must ensure to close each opened connection property as otherwise the pool will lock up, once all * connections are busy. Consider using {@link #createQuery(String)} or * {@link #createFunctionCall(String, Integer)} or {@link #createProcedureCall(String)} to access the database * in a safe manner. * * @return a new {@link Connection} to the database * @throws SQLException in case of a database error */ public Connection getConnection() throws SQLException { try (Operation op = new Operation(() -> "Database: " + name + ".getConnection()", Duration.ofSeconds(5))) { return new WrappedConnection(getDatasource().getConnection(), this); } }
List<Operation> ops = Operation.getActiveOperations(); if (!ops.isEmpty()) { output.blankLine(); output.separator(); for (Operation op : ops) { output.line(op.toString());
protected void startup() { try (Operation op = new Operation(() -> "IndexLifecycle.startClient", Duration.ofSeconds(15))) { startClient(); } schema = new Schema(this); schema.load(); try (Operation op = new Operation(() -> "IndexLifecycle.updateMappings", Duration.ofSeconds(30))) { updateMappings(); } ready = true; readyFuture.success(); delayLineTimer = new Timer("index-delay"); delayLineTimer.schedule(new DelayLineHandler(), 1000, 1000); }
@Override public int executeUpdate(String sql) throws SQLException { if (Databases.LOG.isFINE()) { Databases.LOG.FINE(sql); } Watch w = Watch.start(); try (Operation op = new Operation(() -> sql, Duration.ofSeconds(30))) { return stmt.executeUpdate(sql); } finally { updateStatistics(sql, w); } }
@Override public ResultSet executeQuery(String sql) throws SQLException { if (Databases.LOG.isFINE()) { Databases.LOG.FINE(sql); } Watch w = Watch.start(); try (Operation op = new Operation(() -> sql, Duration.ofSeconds(30))) { return delegate.executeQuery(sql); } finally { updateStatistics(sql, w); } }
@Override public ResultSet executeQuery(String sql) throws SQLException { if (Databases.LOG.isFINE()) { Databases.LOG.FINE(sql); } Watch w = Watch.start(); try (Operation op = new Operation(() -> sql, Duration.ofSeconds(30))) { return stmt.executeQuery(sql); } finally { updateStatistics(sql, w); } }
@Override public int executeUpdate(String sql, int[] columnIndexes) throws SQLException { if (Databases.LOG.isFINE()) { Databases.LOG.FINE(sql); } Watch w = Watch.start(); try (Operation op = new Operation(() -> sql, Duration.ofSeconds(30))) { return stmt.executeUpdate(sql, columnIndexes); } finally { updateStatistics(sql, w); } }
@Override public boolean execute() throws SQLException { if (Databases.LOG.isFINE()) { Databases.LOG.FINE(preparedSQL); } Watch w = Watch.start(); try (Operation op = new Operation(() -> preparedSQL, Duration.ofSeconds(30))) { return delegate.execute(); } finally { updateStatistics(preparedSQL, w); } }
@Override public boolean execute(String sql, int autoGeneratedKeys) throws SQLException { if (Databases.LOG.isFINE()) { Databases.LOG.FINE(sql); } Watch w = Watch.start(); try (Operation op = new Operation(() -> sql, Duration.ofSeconds(30))) { return delegate.execute(sql, autoGeneratedKeys); } finally { updateStatistics(sql, w); } }
@Override public boolean execute(String sql) throws SQLException { if (Databases.LOG.isFINE()) { Databases.LOG.FINE(sql); } Watch w = Watch.start(); try (Operation op = new Operation(() -> sql, Duration.ofSeconds(30))) { return stmt.execute(sql); } finally { updateStatistics(sql, w); } }
@Override public boolean execute(String sql, String[] columnNames) throws SQLException { if (Databases.LOG.isFINE()) { Databases.LOG.FINE(sql); } Watch w = Watch.start(); try (Operation op = new Operation(() -> sql, Duration.ofSeconds(30))) { return stmt.execute(sql, columnNames); } finally { updateStatistics(sql, w); } }
@Override public int executeUpdate(String sql) throws SQLException { if (Databases.LOG.isFINE()) { Databases.LOG.FINE(sql); } Watch w = Watch.start(); try (Operation op = new Operation(() -> sql, Duration.ofSeconds(30))) { return delegate.executeUpdate(sql); } finally { updateStatistics(sql, w); } }
@Override public int executeUpdate() throws SQLException { if (Databases.LOG.isFINE()) { Databases.LOG.FINE(preparedSQL); } Watch w = Watch.start(); try (Operation op = new Operation(() -> preparedSQL, Duration.ofSeconds(30))) { return delegate.executeUpdate(); } finally { updateStatistics(preparedSQL, w); } }
@Override public boolean execute(String sql, String[] columnNames) throws SQLException { if (Databases.LOG.isFINE()) { Databases.LOG.FINE(sql); } Watch w = Watch.start(); try (Operation op = new Operation(() -> sql, Duration.ofSeconds(30))) { return delegate.execute(sql, columnNames); } finally { updateStatistics(sql, w); } }