use of org.lastaflute.di.core.external.GenericExternalContext in project fess by codelibs.
the class ThumbnailGenerator method main.
public static void main(final String[] args) {
final Options options = new Options();
final CmdLineParser parser = new CmdLineParser(options);
try {
parser.parseArgument(args);
} catch (final CmdLineException e) {
System.err.println(e.getMessage());
System.err.println("java " + ThumbnailGenerator.class.getCanonicalName() + " [options...] arguments...");
parser.printUsage(System.err);
return;
}
if (logger.isDebugEnabled()) {
try {
ManagementFactory.getRuntimeMXBean().getInputArguments().stream().forEach(s -> logger.debug("Parameter: {}", s));
System.getProperties().entrySet().stream().forEach(e -> logger.debug("Property: {}={}", e.getKey(), e.getValue()));
System.getenv().entrySet().forEach(e -> logger.debug("Env: {}={}", e.getKey(), e.getValue()));
logger.debug("Option: {}", options);
} catch (final Exception e) {
// ignore
}
}
final String httpAddress = System.getProperty(Constants.FESS_ES_HTTP_ADDRESS);
if (StringUtil.isNotBlank(httpAddress)) {
System.setProperty(FesenClient.HTTP_ADDRESS, httpAddress);
}
TimeoutTask systemMonitorTask = null;
int exitCode;
try {
SingletonLaContainerFactory.setConfigPath("app.xml");
SingletonLaContainerFactory.setExternalContext(new GenericExternalContext());
SingletonLaContainerFactory.setExternalContextComponentDefRegister(new GenericExternalContextComponentDefRegister());
SingletonLaContainerFactory.init();
final Thread shutdownCallback = new Thread("ShutdownHook") {
@Override
public void run() {
if (logger.isDebugEnabled()) {
logger.debug("Destroying LaContainer..");
}
destroyContainer();
}
};
Runtime.getRuntime().addShutdownHook(shutdownCallback);
systemMonitorTask = TimeoutManager.getInstance().addTimeoutTarget(new SystemMonitorTarget(), ComponentUtil.getFessConfig().getThumbnailSystemMonitorIntervalAsInteger(), true);
final int totalCount = process(options);
if (totalCount != 0) {
logger.info("Created {} thumbnail files.", totalCount);
} else {
logger.info("No new thumbnails found.");
}
exitCode = 0;
} catch (final ContainerNotAvailableException e) {
if (logger.isDebugEnabled()) {
logger.debug("ThumbnailGenerator is stopped.", e);
} else if (logger.isInfoEnabled()) {
logger.info("ThumbnailGenerator is stopped.");
}
exitCode = Constants.EXIT_FAIL;
} catch (final Throwable t) {
logger.error("ThumbnailGenerator does not work correctly.", t);
exitCode = Constants.EXIT_FAIL;
} finally {
if (systemMonitorTask != null) {
systemMonitorTask.cancel();
}
destroyContainer();
}
System.exit(exitCode);
}
use of org.lastaflute.di.core.external.GenericExternalContext in project fess by codelibs.
the class SuggestCreator method main.
public static void main(final String[] args) {
final Options options = new Options();
final CmdLineParser parser = new CmdLineParser(options);
try {
parser.parseArgument(args);
} catch (final CmdLineException e) {
System.err.println(e.getMessage());
System.err.println("java " + SuggestCreator.class.getCanonicalName() + " [options...] arguments...");
parser.printUsage(System.err);
return;
}
if (logger.isDebugEnabled()) {
try {
ManagementFactory.getRuntimeMXBean().getInputArguments().stream().forEach(s -> logger.debug("Parameter: {}", s));
System.getProperties().entrySet().stream().forEach(e -> logger.debug("Property: {}={}", e.getKey(), e.getValue()));
System.getenv().entrySet().forEach(e -> logger.debug("Env: {}={}", e.getKey(), e.getValue()));
logger.debug("Option: {}", options);
} catch (final Exception e) {
// ignore
}
}
final String httpAddress = System.getProperty(Constants.FESS_ES_HTTP_ADDRESS);
if (StringUtil.isNotBlank(httpAddress)) {
System.setProperty(FesenClient.HTTP_ADDRESS, httpAddress);
}
TimeoutTask systemMonitorTask = null;
int exitCode;
try {
SingletonLaContainerFactory.setConfigPath("app.xml");
SingletonLaContainerFactory.setExternalContext(new GenericExternalContext());
SingletonLaContainerFactory.setExternalContextComponentDefRegister(new GenericExternalContextComponentDefRegister());
SingletonLaContainerFactory.init();
final Thread shutdownCallback = new Thread("ShutdownHook") {
@Override
public void run() {
if (logger.isDebugEnabled()) {
logger.debug("Destroying LaContainer..");
}
destroyContainer();
}
};
Runtime.getRuntime().addShutdownHook(shutdownCallback);
systemMonitorTask = TimeoutManager.getInstance().addTimeoutTarget(new SystemMonitorTarget(), ComponentUtil.getFessConfig().getSuggestSystemMonitorIntervalAsInteger(), true);
exitCode = process(options);
} catch (final ContainerNotAvailableException e) {
if (logger.isDebugEnabled()) {
logger.debug("SuggestCreator is stopped.", e);
} else if (logger.isInfoEnabled()) {
logger.info("SuggestCreator is stopped.");
}
exitCode = Constants.EXIT_FAIL;
} catch (final Throwable t) {
logger.error("Suggest creator does not work correctly.", t);
exitCode = Constants.EXIT_FAIL;
} finally {
if (systemMonitorTask != null) {
systemMonitorTask.cancel();
}
destroyContainer();
}
logger.info("Finished SuggestCreator.");
System.exit(exitCode);
}
use of org.lastaflute.di.core.external.GenericExternalContext in project fess by codelibs.
the class Crawler method main.
public static void main(final String[] args) {
final Options options = new Options();
final CmdLineParser parser = new CmdLineParser(options);
try {
parser.parseArgument(args);
} catch (final CmdLineException e) {
System.err.println(e.getMessage());
System.err.println("java " + Crawler.class.getCanonicalName() + " [options...] arguments...");
parser.printUsage(System.err);
return;
}
if (logger.isDebugEnabled()) {
try {
ManagementFactory.getRuntimeMXBean().getInputArguments().stream().forEach(s -> logger.debug("Parameter: {}", s));
System.getProperties().entrySet().stream().forEach(e -> logger.debug("Property: {}={}", e.getKey(), e.getValue()));
System.getenv().entrySet().forEach(e -> logger.debug("Env: {}={}", e.getKey(), e.getValue()));
logger.debug("Option: {}", options);
} catch (final Exception e) {
// ignore
}
}
initializeProbes();
final String httpAddress = System.getProperty(Constants.FESS_ES_HTTP_ADDRESS);
if (StringUtil.isNotBlank(httpAddress)) {
System.setProperty(FesenClient.HTTP_ADDRESS, httpAddress);
}
TimeoutTask systemMonitorTask = null;
Thread commandThread = null;
int exitCode;
try {
running.set(true);
SingletonLaContainerFactory.setConfigPath("app.xml");
SingletonLaContainerFactory.setExternalContext(new GenericExternalContext());
SingletonLaContainerFactory.setExternalContextComponentDefRegister(new GenericExternalContextComponentDefRegister());
SingletonLaContainerFactory.init();
final Thread shutdownCallback = new Thread("ShutdownHook") {
@Override
public void run() {
destroyContainer();
}
};
Runtime.getRuntime().addShutdownHook(shutdownCallback);
commandThread = new Thread(() -> {
try (BufferedReader reader = new BufferedReader(new InputStreamReader(System.in))) {
String command;
while (true) {
try {
while (!reader.ready()) {
ThreadUtil.sleep(1000L);
}
command = reader.readLine().trim();
if (logger.isDebugEnabled()) {
logger.debug("Process command: {}", command);
}
if (Constants.CRAWLER_PROCESS_COMMAND_THREAD_DUMP.equals(command)) {
ThreadDumpUtil.printThreadDump();
} else {
logger.warn("Unknown process command: {}", command);
}
if (Thread.interrupted()) {
return;
}
} catch (final InterruptedRuntimeException e) {
return;
}
}
} catch (final IOException e) {
logger.debug("I/O exception.", e);
}
}, "ProcessCommand");
commandThread.start();
systemMonitorTask = TimeoutManager.getInstance().addTimeoutTarget(new SystemMonitorTarget(), ComponentUtil.getFessConfig().getCrawlerSystemMonitorIntervalAsInteger(), true);
exitCode = process(options);
} catch (final ContainerNotAvailableException e) {
if (logger.isDebugEnabled()) {
logger.debug("Crawler is stopped.", e);
} else if (logger.isInfoEnabled()) {
logger.info("Crawler is stopped.");
}
exitCode = Constants.EXIT_FAIL;
} catch (final Throwable t) {
logger.error("Crawler does not work correctly.", t);
exitCode = Constants.EXIT_FAIL;
} finally {
if (commandThread != null && commandThread.isAlive()) {
commandThread.interrupt();
}
if (systemMonitorTask != null) {
systemMonitorTask.cancel();
}
destroyContainer();
}
if (exitCode != Constants.EXIT_OK) {
System.exit(exitCode);
}
}
Aggregations