List of usage examples for com.google.common.eventbus SubscriberExceptionHandler SubscriberExceptionHandler
SubscriberExceptionHandler
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 w w . jav a2 s. c om*/ 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:com.esofthead.mycollab.spring.AppEventBus.java
@Bean public AsyncEventBus asyncEventBus() { return new AsyncEventBus(Executors.newCachedThreadPool(), new SubscriberExceptionHandler() { @Override/* ww w .j ava2s.co m*/ public void handleException(Throwable throwable, SubscriberExceptionContext subscriberExceptionContext) { LOG.error("Error in event bus execution", throwable); } }); }
From source file:org.apache.isis.core.runtime.services.eventbus.adapter.EventBusImplementationForGuava.java
protected SubscriberExceptionHandler newEventBusSubscriberExceptionHandler() { return new SubscriberExceptionHandler() { @Override/*from ww w.ja v a2 s . c om*/ public void handleException(final Throwable exception, final SubscriberExceptionContext context) { final Object event = context.getEvent(); processException(exception, event); } }; }
From source file:com.github.marabou.Main.java
private static void setupMainWindow(ApplicationProperties applicationProperties, UserProperties userProperties) { ImageLoader imageLoader = new ImageLoader(); AboutWindow aboutWindow = new AboutWindow(applicationProperties.getVersion()); AudioFileFilter audioFileFilter = new AudioFileFilter(); AudioFileService audioFileService = new AudioFileService(audioFileFilter); SubscriberExceptionHandler eventBusExceptionHandler = new SubscriberExceptionHandler() { @Override/*from w w w. j a va 2 s .co m*/ public void handleException(Throwable exception, SubscriberExceptionContext context) { log.error("A terrible thing happened in marabou." + "If you read this please copy the whole text and report a bug at the project web site.", exception); } }; EventBus bus = new EventBus(eventBusExceptionHandler); Model model = new Model(bus); MainMenuController mainMenuController = new MainMenuController(bus, model, audioFileFilter, userProperties, audioFileService, aboutWindow); MainMenu mainMenu = new MainMenu(mainMenuController); mainMenu.init(); Composite MainWindowComposite = new Composite(BaseGuiClass.shell, SWT.NONE); SashForm mainWindowSashForm = new SashForm(MainWindowComposite, SWT.HORIZONTAL); SidePanel sidePanel = new SidePanel(mainWindowSashForm); new SidePanelController(bus, sidePanel); MainWindow mainWindow = new MainWindow(bus, mainMenu, imageLoader, userProperties, MainWindowComposite, mainWindowSashForm); Table table = new Table(mainWindow.getTableComposite(), SWT.MULTI); new TableController(bus, table, model); mainWindow.init(); }