public LoadController(Loader loader) { this.loader = loader; this.masterChannel = new EventBus(new SubscriberExceptionHandler() { @Override public void handleException(Throwable exception, SubscriberExceptionContext context) { FMLLog.log("FMLMainChannel", Level.ERROR, exception, "Could not dispatch event: %s to %s", context.getEvent(), context.getSubscriberMethod()); } }); this.masterChannel.register(this); state = LoaderState.NOINIT; packageOwners = ArrayListMultimap.create(); }
private static EventBus newEventBus(final String name, final Executor executor) { try { Class<?> dispatcherClass = EventBus.class.getClassLoader().loadClass("com.google.common.eventbus.Dispatcher"); // immediate dispatcher means events are always processed in a reentrant fashion Method immediateDispatcherMethod = dispatcherClass.getDeclaredMethod("immediate"); immediateDispatcherMethod.setAccessible(true); // EventBus constructor that accepts custom executor is not yet part of the public API Constructor<EventBus> eventBusConstructor = EventBus.class.getDeclaredConstructor( String.class, Executor.class, dispatcherClass, SubscriberExceptionHandler.class); eventBusConstructor.setAccessible(true); Object immediateDispatcher = immediateDispatcherMethod.invoke(null); SubscriberExceptionHandler exceptionHandler = new Slf4jSubscriberExceptionHandler(name); return eventBusConstructor.newInstance(name, executor, immediateDispatcher, exceptionHandler); } catch (Exception e) { Throwables.throwIfUnchecked(e); throw new LinkageError("Unable to create EventBus with custom executor", e); } }
public BlazeWorkspace( BlazeRuntime runtime, BlazeDirectories directories, SkyframeExecutor skyframeExecutor, SubscriberExceptionHandler eventBusExceptionHandler, WorkspaceStatusAction.Factory workspaceStatusActionFactory, BinTools binTools, @Nullable AllocationTracker allocationTracker) { this.runtime = runtime; this.eventBusExceptionHandler = eventBusExceptionHandler; this.workspaceStatusActionFactory = workspaceStatusActionFactory; this.binTools = binTools; this.allocationTracker = allocationTracker; this.directories = directories; this.skyframeExecutor = skyframeExecutor; if (directories.inWorkspace()) { writeOutputBaseReadmeFile(); writeDoNotBuildHereFile(); } setupExecRoot(); // Here we use outputBase instead of outputPath because we need a file system to create the // latter. this.outputBaseFilesystemTypeName = FileSystemUtils.getFileSystem(getOutputBase()); }
@Test public void unhandledExceptionInEventThreadCallsSubscriberExceptionHandler() { SubscriberExceptionHandler handler = mock(SubscriberExceptionHandler.class); EventBus bus = new EventBus(handler); final IllegalStateException exception = new IllegalStateException("Excepted Unhandled Exception"); bus.register(new Object() { @Subscribe public void throwUnhandledException(TriggerUnhandledException event) { throw exception; } }); bus.post(new TriggerUnhandledException()); verify(handler).handleException(eq(exception), any(SubscriberExceptionContext.class)); }
@Subscribe public void buildModList(FMLLoadEvent event) { Builder<String, EventBus> eventBus = ImmutableMap.builder(); for (final ModContainer mod : loader.getModList()) { //Create mod logger, and make the EventBus logger a child of it. EventBus bus = new EventBus(new SubscriberExceptionHandler() { @Override public void handleException(final Throwable exception, final SubscriberExceptionContext context) { LoadController.this.errorOccurred(mod, exception); } }); boolean isActive = mod.registerBus(bus, this); if (isActive) { activeModList.add(mod); modStates.put(mod.getModId(), ModState.UNLOADED); eventBus.put(mod.getModId(), bus); FMLCommonHandler.instance().addModToResourcePack(mod); } else { FMLLog.log(mod.getModId(), Level.WARN, "Mod %s has been disabled through configuration", mod.getModId()); modStates.put(mod.getModId(), ModState.UNLOADED); modStates.put(mod.getModId(), ModState.DISABLED); } modNames.put(mod.getModId(), mod.getName()); } eventChannels = eventBus.build(); }
MentorEventBus() { this(Executors.newWorkStealingPool(), new SubscriberExceptionHandler() { @Override public void handleException(Throwable exception, SubscriberExceptionContext context) { Log.error("Error in event handler ({})", context, exception); } }); }
BlazeWorkspace build( BlazeRuntime runtime, PackageFactory packageFactory, ConfiguredRuleClassProvider ruleClassProvider, SubscriberExceptionHandler eventBusExceptionHandler) throws AbruptExitException { // Set default values if none are set. if (skyframeExecutorFactory == null) { skyframeExecutorFactory = new SequencedSkyframeExecutorFactory(); } SkyframeExecutor skyframeExecutor = skyframeExecutorFactory.create( packageFactory, runtime.getFileSystem(), directories, runtime.getActionKeyContext(), workspaceStatusActionFactory, ruleClassProvider.getBuildInfoFactories(), diffAwarenessFactories.build(), skyFunctions.build(), customDirtinessCheckers.build()); return new BlazeWorkspace( runtime, directories, skyframeExecutor, eventBusExceptionHandler, workspaceStatusActionFactory, binTools, allocationTracker); }
public EventBusThatPublishesUnhandledExceptionEvents() { super(new SubscriberExceptionHandler() { @Override public void handleException(Throwable throwable, SubscriberExceptionContext subscriberExceptionContext) { postUncaughtExceptionEvent(throwable); } }); errorMessageBus.register(this); }
public AppEventBus() { eventbus = new EventBus(new SubscriberExceptionHandler() { @Override public void handleException(Throwable exception, SubscriberExceptionContext context) { log.error("Could not dispatch event: " + context.getSubscriber() + " to " + context.getSubscriberMethod()); exception.printStackTrace(); } }); }
public ReentrantEventBus(SubscriberExceptionHandler subscriberExceptionHandler) { super(subscriberExceptionHandler); this.isDispatching = getIsDispatching(); }
@Override protected void configure() { bind(SubscriberExceptionHandler.class).to(EventExceptionHandler.class); }
@Provides @Singleton EventBus eventBus(SubscriberExceptionHandler exceptionHandler) { return new ReentrantEventBus(exceptionHandler); }
MentorEventBus(ExecutorService executor, SubscriberExceptionHandler handler) { super(executor, handler); this.executor = executor; }
private BlazeRuntime( FileSystem fileSystem, QueryEnvironmentFactory queryEnvironmentFactory, ImmutableList<QueryFunction> queryFunctions, ImmutableList<OutputFormatter> queryOutputFormatters, PackageFactory pkgFactory, ConfiguredRuleClassProvider ruleClassProvider, ImmutableList<ConfigurationFragmentFactory> configurationFragmentFactories, ImmutableMap<String, InfoItem> infoItems, ActionKeyContext actionKeyContext, Clock clock, Runnable abruptShutdownHandler, OptionsProvider startupOptionsProvider, Iterable<BlazeModule> blazeModules, SubscriberExceptionHandler eventBusExceptionHandler, ProjectFile.Provider projectFileProvider, InvocationPolicy moduleInvocationPolicy, Iterable<BlazeCommand> commands, String productName, PathConverter pathToUriConverter) { // Server state this.fileSystem = fileSystem; this.blazeModules = blazeModules; overrideCommands(commands); this.packageFactory = pkgFactory; this.projectFileProvider = projectFileProvider; this.moduleInvocationPolicy = moduleInvocationPolicy; this.ruleClassProvider = ruleClassProvider; this.configurationFragmentFactories = configurationFragmentFactories; this.infoItems = infoItems; this.actionKeyContext = actionKeyContext; this.clock = clock; this.abruptShutdownHandler = abruptShutdownHandler; this.startupOptionsProvider = startupOptionsProvider; this.queryEnvironmentFactory = queryEnvironmentFactory; this.queryFunctions = queryFunctions; this.queryOutputFormatters = queryOutputFormatters; this.eventBusExceptionHandler = eventBusExceptionHandler; this.defaultsPackageContent = ruleClassProvider.getDefaultsPackageContent(getModuleInvocationPolicy()); CommandNameCache.CommandNameCacheInstance.INSTANCE.setCommandNameCache( new CommandNameCacheImpl(getCommandMap())); this.productName = productName; this.pathToUriConverter = pathToUriConverter; }
@VisibleForTesting public Builder setEventBusExceptionHandler( SubscriberExceptionHandler eventBusExceptionHandler) { this.eventBusExceptionHandler = eventBusExceptionHandler; return this; }
public VisEventBus (SubscriberExceptionHandler subscriberExceptionHandler) { super(subscriberExceptionHandler); }