protected void doRegister(Object e, final boolean isAsync) { if (isAsync) GuiceHelper.getGuiceInjector().getInstance(AsyncEventBus.class).register(e); else GuiceHelper.getGuiceInjector().getInstance(EventBus.class).register(e); LOGGER.info("registered:" + e.toString() + " as " + isAsync); }
public static void addModules(AbstractModule... modules) { for (AbstractModule moduleClass : modules) addModule(moduleClass); }
public static void main(final String[] arguments) throws Exception { COMMAND_LINE_MODULE = getCommandLineModule(arguments); GuiceHelper.addModule(COMMAND_LINE_MODULE); GuiceHelper.setup(); try { COMMAND_LINE_MODULE.doRun(arguments); doExit("Finished execution, exiting ...", 0); } catch (Exception e) { LOGGER.error("Error running", e); doExit("Error running", 1); } }
public void register(Object instance, final boolean isAsync) { try { GuiceHelper.getGuiceInjector(); doRegister(instance, isAsync); } catch (Exception e) { LOGGER.warn("not yet initialized"); if (isAsync) asyncInstances.add(new WeakReference(instance)); else syncInstances.add(new WeakReference(instance)); } }
private static void doStartService(final Class<? extends Service> serviceClass) { try { final Service service = GuiceHelper.getGuiceInjector().getInstance(serviceClass); if (!service.isRunning()) service.startAsync(); else LOGGER.debug("service was already started, perhaps because it is an eager singleton?"); } catch (ConfigurationException e) { LOGGER.warn("Service may NOT be a Guice service, check configuration", e); } }
protected void doRunInternal() throws Exception { abstractCommandLineHandler = GuiceHelper.getGuiceInjector().getInstance(getCommandLineHandlerClass()); if (CommandLineDaemon.class.isAssignableFrom(abstractCommandLineHandler.getClass())) { doRunDaemon(abstractCommandLineHandler); } else abstractCommandLineHandler.run(arguments); }
private static void doStopService(final Class<? extends Service> serviceClass) { try { final Service service = GuiceHelper.getGuiceInjector().getInstance(serviceClass); if (service.isRunning()) service .stopAsync() .awaitTerminated( Long.valueOf(PropertyUtil.getValue(null, ServiceStopTimeout.class)), TimeUnit.SECONDS); else LOGGER.warn("Service:" + service + " is already stopped."); } catch (TimeoutException | IllegalStateException e) { LOGGER.warn("Service is still stopping, killing."); } } }