Java 类com.google.common.eventbus.SubscriberExceptionHandler 实例源码

项目:CustomWorldGen    文件:LoadController.java   
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();

}
项目:nexus-public    文件:EventBusFactory.java   
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);
  }
}
项目:bazel    文件:BlazeWorkspace.java   
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());
}
项目:PortlandStateJava    文件:UnhandledExceptionEventTest.java   
@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));
}
项目:CustomWorldGen    文件:LoadController.java   
@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();
}
项目:mentor    文件:MentorEventBus.java   
MentorEventBus() {
    this(Executors.newWorkStealingPool(), new SubscriberExceptionHandler() {
        @Override
        public void handleException(Throwable exception, SubscriberExceptionContext context) {
            Log.error("Error in event handler ({})", context, exception);
        }
    });
}
项目:bazel    文件:WorkspaceBuilder.java   
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);
}
项目:PortlandStateJava    文件:EventBusThatPublishesUnhandledExceptionEvents.java   
public EventBusThatPublishesUnhandledExceptionEvents() {
  super(new SubscriberExceptionHandler() {
    @Override
    public void handleException(Throwable throwable, SubscriberExceptionContext subscriberExceptionContext) {
      postUncaughtExceptionEvent(throwable);
    }
  });

  errorMessageBus.register(this);
}
项目:AppBaseForVaadin    文件:AppEventBus.java   
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();
    }
  });
}
项目:ProjectAres    文件:ReentrantEventBus.java   
public ReentrantEventBus(SubscriberExceptionHandler subscriberExceptionHandler) {
    super(subscriberExceptionHandler);
    this.isDispatching = getIsDispatching();
}
项目:ProjectAres    文件:EventBusModule.java   
@Override
protected void configure() {
    bind(SubscriberExceptionHandler.class).to(EventExceptionHandler.class);
}
项目:ProjectAres    文件:EventBusModule.java   
@Provides @Singleton
EventBus eventBus(SubscriberExceptionHandler exceptionHandler) {
    return new ReentrantEventBus(exceptionHandler);
}
项目:mentor    文件:MentorEventBus.java   
MentorEventBus(ExecutorService executor, SubscriberExceptionHandler handler) {
    super(executor, handler);
    this.executor = executor;
}
项目:bazel    文件:BlazeRuntime.java   
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;
}
项目:bazel    文件:BlazeRuntime.java   
@VisibleForTesting
public Builder setEventBusExceptionHandler(
    SubscriberExceptionHandler eventBusExceptionHandler) {
  this.eventBusExceptionHandler = eventBusExceptionHandler;
  return this;
}
项目:vis-editor    文件:VisEventBus.java   
public VisEventBus (SubscriberExceptionHandler subscriberExceptionHandler) {
    super(subscriberExceptionHandler);
}