private void executeOneByOne(Statement statement) throws SQLException { for (String sqlStatement : source.get()) { statementCount++; try { statement.execute(sqlStatement); } catch (Exception e) { log.error(String.format("Can't execute sql statement (%d): %s", statementCount, sqlStatement), e); throw e; } } }
/** * Get the {@link ConfigModelReader} for the given {@code format}. * * @param format format of reader to get * @return the found reader * @throws IllegalArgumentException if no reader found for the given format * @throws NullPointerException if format is null */ static ConfigModelReader reader(String format) { Map<String, ConfigModelReader> readers = READERS.get(); ConfigModelReader reader = readers.get(Objects.requireNonNull(format)); if (reader == null) { throw new IllegalArgumentException(String.format("Can't find reader for format: %s, available formats: %s", format, readers.keySet())); } return reader; }
/** * Get the {@link ApplicationConfigReader} for the given {@code format}. * * @param format format of reader to get * @return the found reader * @throws IllegalArgumentException if no reader found for the given format * @throws NullPointerException if format is null */ static ApplicationConfigReader reader(String format) { Map<String, ApplicationConfigReader> readers = READERS.get(); ApplicationConfigReader reader = readers.get(Objects.requireNonNull(format)); if (reader == null) { throw new IllegalArgumentException(String.format("Can't find reader for format: %s, available formats: %s", format, readers.keySet())); } return reader; }
/** * Get the {@link ConfigModelWriter} for the given {@code format}. * * @param format format of writer to get * @return the found writer * @throws IllegalArgumentException if no writer found for the given format * @throws NullPointerException if format is null */ static ConfigModelWriter writer(String format) { Map<String, ConfigModelWriter> writers = WRITERS.get(); ConfigModelWriter writer = writers.get(Objects.requireNonNull(format)); if (writer == null) { throw new IllegalArgumentException(String.format("Can't find writer for format: %s, available formats: %s", format, writers.keySet())); } return writer; }
/** * Get the {@link ApplicationConfigWriter} for the given {@code format}. * * @param format format of writer to get * @return the found writer * @throws IllegalArgumentException if no writer found for the given format * @throws NullPointerException if format is null */ static ApplicationConfigWriter writer(String format) { Map<String, ApplicationConfigWriter> writers = WRITERS.get(); ApplicationConfigWriter writer = writers.get(Objects.requireNonNull(format)); if (writer == null) { throw new IllegalArgumentException(String.format("Can't find writer for format: %s, available formats: %s", format, writers.keySet())); } return writer; }
@Override public void close() throws IOException { if (source.withValue()) { source.get().close(); } }
public Context getContext() { checkNotClosed("context"); return context.get(); }
public Config getConfiguration() { checkNotClosed("configuration"); return configuration.get(); }
public ApplicationThreadFactory getThreadFactory() { checkNotClosed("threadFactory"); return threadFactory.get(); }
private ActionExecutor getExecutor() { checkNotClosed("executor"); return executor.get(); }
private void executeByBatch(Statement statement) throws SQLException { for (String sqlStatement : source.get()) { statementCount++; try { statement.addBatch(sqlStatement); statements.add(sqlStatement); } catch (Exception e) { log.error(String.format("Can't add sql statement (%d) in batch: %s", statementCount, sqlStatement), e); throw e; } if (statementCount > 0 && statementCount % batchSize == 0) { flush(statement); } } flush(statement); }
@Override public void close() throws IOException { if (source.withValue()) { source.get().close(); } }
public void startInThread() { Runtime.getRuntime().addShutdownHook(threadFactory.get().newThread(this::shutdown, "shutdown", false)); boolean shutdown = false; while (!shutdown) { Thread thread = threadFactory.get().newThread(this::start, "main", false); thread.start(); try { // lock boot lockBoot(); // boot is free to close or reload log.info(String.format("%s Application boot unlock...", BOOT_LOG_PREFIX)); } catch (InterruptedException e) { log.error(String.format("Main thread was interrupted for reason %s", e.getMessage()), e); } finally { if (reload) { try { close(); } catch (Exception e) { log.error(String.format("Could not close boot, will shutdown application: %s", e.getMessage()), e); // if can't close, then shutdown shutdown = true; } } else { // if no reload, this means shutdown shutdown = true; } } } shutdown(); }
while ((scanner = source.get().read()) != -1) { char character = (char) scanner;
public void close() { if (closed || closing) { return; } closing = true; try { if (context.withValue()) { context.get().close(); } if (executor.withValue()) { executor.get().close(); } } catch (Exception e) { throw new RuntimeException("Can't close boot for reason: " + e.getMessage(), e); } finally { cleanMemory(); configuration.clear(); context.clear(); executor.clear(); closed = true; } }