List of usage examples for com.google.common.eventbus SubscriberExceptionContext getSubscriber
public Object getSubscriber()
From source file:org.asoem.greyfish.cli.GreyfishCLIApplication.java
public static void main(final String[] args) { final Optional<String> commitHash = getCommitHash(GreyfishCLIApplication.class); if (commitHash.isPresent()) { logger.debug("Git Commit Hash for current Jar: %s", commitHash.get()); }/*from w ww .j a v a 2 s . com*/ Runtime.getRuntime().addShutdownHook(new Thread() { @Override public void run() { try { closer.close(); } catch (IOException e) { logger.warn("Exception while closing resources", e); } } }); try { final OptionSet optionSet = optionParser.parse(args); if (optionSet.has(helpOptionSpec)) { printHelp(); System.exit(0); } final Module commandLineModule = createCommandLineModule(optionSet); final RandomGenerator randomGenerator = RandomGenerators .threadLocalGenerator(new Supplier<RandomGenerator>() { @Override public RandomGenerator get() { return new Well19937c(); } }); final EventBus eventBus = new EventBus(new SubscriberExceptionHandler() { @Override public void handleException(final Throwable exception, final SubscriberExceptionContext context) { context.getEventBus() .post(new AssertionError("The EventBus could not dispatch event: " + context.getSubscriber() + " to " + context.getSubscriberMethod(), exception.getCause())); } }); final Module coreModule = new CoreModule(randomGenerator, eventBus); final Injector injector = Guice.createInjector(coreModule, commandLineModule); final ExperimentExecutionService experimentExecutionService = injector .getInstance(ExperimentExecutionService.class); if (!optionSet.has(quietOptionSpec)) { final ExperimentMonitorService monitorService = new ExperimentMonitorService(System.out, eventBus); monitorService.addListener(new Service.Listener() { @Override public void starting() { } @Override public void running() { } @Override public void stopping(final Service.State from) { } @Override public void terminated(final Service.State from) { } @Override public void failed(final Service.State from, final Throwable failure) { logger.error("Monitor service failed", failure); } }, MoreExecutors.sameThreadExecutor()); experimentExecutionService.addListener(new MonitorServiceController(monitorService), MoreExecutors.sameThreadExecutor()); } // start getSimulation experimentExecutionService.startAsync(); // stop getSimulation on shutdown request (^C) Runtime.getRuntime().addShutdownHook(new Thread() { @Override public void run() { if (experimentExecutionService.isRunning()) { experimentExecutionService.stopAsync().awaitTerminated(); } } }); try { experimentExecutionService.awaitTerminated(); } catch (IllegalStateException e) { exitWithErrorMessage("Simulation execution failed", e); } } catch (OptionException e) { exitWithErrorMessage("Failed parsing options: ", e, true); } catch (Throwable e) { exitWithErrorMessage(String.format( "Exception during simulation execution: %s\n" + "Check log file for a stack trace.", e.getCause() != null ? e.getCause().getMessage() : e.getMessage()), e); } System.exit(0); }
From source file:uk.jamierocks.mana.carbon.util.event.Slf4jEventLoggingHandler.java
private static String message(SubscriberExceptionContext context) { Method method = context.getSubscriberMethod(); return "Exception thrown by subscriber method " + method.getName() + '(' + method.getParameterTypes()[0].getName() + ')' + " on subscriber " + context.getSubscriber() + " when dispatching event: " + context.getEvent(); }
From source file:me.jamiemansfield.guide.event.Slf4jSubscriberExceptionHandler.java
/** * Produces the message to use as an exception is logged. * * @param context The exception context/*from w w w .j av a 2 s . c o m*/ * @return The message to log */ private static String message(final SubscriberExceptionContext context) { final Method method = context.getSubscriberMethod(); return "Exception thrown by subscriber method " + method.getName() + '(' + method.getParameterTypes()[0].getName() + ')' + " on subscriber " + context.getSubscriber() + " when dispatching event: " + context.getEvent(); }
From source file:org.muhia.app.psi.portal.eventbus.AsyncEventbusService.java
@Override public void handleException(Throwable exception, SubscriberExceptionContext context) { Logger.getLogger(this.getClass().getName()).log(Level.SEVERE, "Handler " + context.getSubscriber() + " could not handle " + context.getEvent().getClass().getName() + "[" + context.getEvent() + "]: " + exception.getMessage(), exception);// w w w. j a va 2 s. c om }
From source file:org.jbb.lib.eventbus.EventExceptionHandler.java
@Override public void handleException(Throwable exception, SubscriberExceptionContext context) { log.error("Error during event [{}] consuming by client {} in method {}", context.getEvent(), exception, context.getSubscriber(), context.getSubscriberMethod()); }
From source file:org.muhia.app.psi.portal.eventbus.SyncEventBusService.java
@Override public void handleException(@Nonnull Throwable exception, SubscriberExceptionContext context) { Logger.getLogger(this.getClass().getName()).log(Level.SEVERE, "Handler " + context.getSubscriber() + " could not handle " + context.getEvent().getClass().getName() + "[" + context.getEvent() + "]: " + exception.getMessage(), exception);// w w w . ja va2 s .c om }
From source file:org.sonatype.nexus.common.event.Slf4jSubscriberExceptionHandler.java
@Override public void handleException(final Throwable exception, final SubscriberExceptionContext context) { logger.error("Could not dispatch event {} to subscriber {} method [{}]", context.getEvent(), context.getSubscriber(), context.getSubscriberMethod(), exception); }
From source file:tech.mcprison.prison.util.EventExceptionHandler.java
@Override public void handleException(Throwable exception, SubscriberExceptionContext context) { Method method = context.getSubscriberMethod(); Output.get().logError("&c&l!!! Event Exception!!!"); Output.get()/* w ww.j av a 2s . c o m*/ .logError("&cException thrown by subscriber method " + method.getName() + '(' + method.getParameterTypes()[0].getName() + ')' + " on listener " + context.getSubscriber().getClass().getName()); Output.get().logError("&6Here's the stack trace:", exception); Output.get().logError( "&6Report this entire message to the developers if you can't solve the problem yourself."); Output.get().logError("&c&l!!! Event Exception!!!"); }
From source file:com.vsct.dt.strowgr.admin.gui.StrowgrMain.java
private String subscriberExceptionContextToString(SubscriberExceptionContext subscriberExceptionContext) { return "event: " + subscriberExceptionContext.getEvent() + ", eventbus identifier: " + subscriberExceptionContext.getEventBus().identifier() + ", subscriber: " + subscriberExceptionContext.getSubscriber() + ", subscriber method name: " + subscriberExceptionContext.getSubscriberMethod().getName(); }