private void initLogging() { System.setProperty("systemRuntime.logDir", getLogDir()); Configurator.initialize("Logging", null, new File(getConfigDir() + lowerCaseFirstLetter(projectName) + ".log4j.xml").toURI()); log = LoggerFactory.getLogger(BaseRuntime.class); }
@Override public void logVersion() { log.info(projectName + " v" + getVersion()); }
public void init() { if (!isInit) { initLogging(); if (projectName == null || projectName.isEmpty()) { log.error("ProjectName should be defined in systemRuntime.properties as 'systemRuntime.projectName'"); } else { initProjectName(projectName); } logVersion(); initExecutorServiceShutdownHook(); SystemRuntime.setRuntime(this); isInit = true; } else { log.warn("SystemRuntime has already been initialized!"); } }
@Override public <T> ScheduledFuture<?> submitScheduledCallable(final Callable<T> callable, long delay, TimeUnit timeUnit, final Map<Object, Object> threadBindings) { return executorService.schedule(() -> { submitCallable(callable, threadBindings); }, delay, timeUnit); }
private void initProjectName(String projectName) { System.setProperty("systemRuntime.projectName", lowerCaseFirstLetter(projectName)); }
@Override public <T> Future<T> submitCallable(final Callable<T> callable, final IFinishedExecution<T> callback, final Map<Object, Object> threadBindings) { return getExecutorService().submit(() -> { try { if (threadBindings != null) { ThreadContext.setResources(threadBindings); } final T result = callable.call(); callback.onComplete(result); return result; } catch (Throwable t) { log.error(t.getLocalizedMessage(), t); callback.onFailure(t); return null; } finally { ThreadContext.remove(); } }); }
@Override public <T> Future<T> submitCallable(final Callable<T> callable, final Map<Object, Object> threadBindings) { return submitCallable(callable, new IgnoredCallableResult<>(), threadBindings); }