Search in sources :

Example 1 with EventBus

use of com.google.common.eventbus.EventBus in project MinecraftForge by MinecraftForge.

the class LoadController method disableMod.

void disableMod(ModContainer mod) {
    HashMap<String, EventBus> temporary = Maps.newHashMap(eventChannels);
    String modId = mod.getModId();
    EventBus bus = temporary.remove(modId);
    bus.post(new FMLModDisabledEvent());
    if (errors.get(modId).isEmpty()) {
        eventChannels = ImmutableMap.copyOf(temporary);
        modStates.put(modId, ModState.DISABLED);
        modObjectList.remove(mod);
        activeModList.remove(mod);
    }
}
Also used : FMLModDisabledEvent(net.minecraftforge.fml.common.event.FMLModDisabledEvent) EventBus(com.google.common.eventbus.EventBus)

Example 2 with EventBus

use of com.google.common.eventbus.EventBus in project MinecraftForge by MinecraftForge.

the class LoadController method buildModList.

@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();
}
Also used : SubscriberExceptionHandler(com.google.common.eventbus.SubscriberExceptionHandler) SubscriberExceptionContext(com.google.common.eventbus.SubscriberExceptionContext) EventBus(com.google.common.eventbus.EventBus) Subscribe(com.google.common.eventbus.Subscribe)

Example 3 with EventBus

use of com.google.common.eventbus.EventBus in project bazel by bazelbuild.

the class WorkerSpawnStrategy method exec.

@Override
public void exec(Spawn spawn, ActionExecutionContext actionExecutionContext, AtomicReference<Class<? extends SpawnActionContext>> writeOutputFiles) throws ExecException, InterruptedException {
    Executor executor = actionExecutionContext.getExecutor();
    if (!spawn.getExecutionInfo().containsKey("supports-workers") || !spawn.getExecutionInfo().get("supports-workers").equals("1")) {
        StandaloneSpawnStrategy standaloneStrategy = Preconditions.checkNotNull(executor.getContext(StandaloneSpawnStrategy.class));
        executor.getEventHandler().handle(Event.warn(String.format(ERROR_MESSAGE_PREFIX + REASON_NO_EXECUTION_INFO, spawn.getMnemonic())));
        standaloneStrategy.exec(spawn, actionExecutionContext);
        return;
    }
    EventBus eventBus = actionExecutionContext.getExecutor().getEventBus();
    ActionExecutionMetadata owner = spawn.getResourceOwner();
    eventBus.post(ActionStatusMessage.schedulingStrategy(owner));
    try (ResourceHandle handle = ResourceManager.instance().acquireResources(owner, spawn.getLocalResources())) {
        eventBus.post(ActionStatusMessage.runningStrategy(spawn.getResourceOwner(), "worker"));
        actuallyExec(spawn, actionExecutionContext, writeOutputFiles);
    }
}
Also used : ActionExecutionMetadata(com.google.devtools.build.lib.actions.ActionExecutionMetadata) Executor(com.google.devtools.build.lib.actions.Executor) ResourceHandle(com.google.devtools.build.lib.actions.ResourceManager.ResourceHandle) StandaloneSpawnStrategy(com.google.devtools.build.lib.standalone.StandaloneSpawnStrategy) EventBus(com.google.common.eventbus.EventBus)

Example 4 with EventBus

use of com.google.common.eventbus.EventBus in project bazel by bazelbuild.

the class MemoizingEvaluatorTest method initializeReporter.

private void initializeReporter() {
    eventCollector = new EventCollector();
    reporter = new Reporter(new EventBus(), eventCollector);
    tester.resetPlayedEvents();
}
Also used : EventCollector(com.google.devtools.build.lib.events.EventCollector) Reporter(com.google.devtools.build.lib.events.Reporter) EventBus(com.google.common.eventbus.EventBus)

Example 5 with EventBus

use of com.google.common.eventbus.EventBus in project bazel by bazelbuild.

the class ParallelBuilderTest method testReportsActionExecutedEvent.

@Test
public void testReportsActionExecutedEvent() throws Exception {
    Artifact pear = createDerivedArtifact("pear");
    ActionEventRecorder recorder = new ActionEventRecorder();
    EventBus eventBus = new EventBus();
    eventBusRef.set(eventBus);
    eventBus.register(recorder);
    Action action = registerAction(new TestAction(Runnables.doNothing(), emptySet, asSet(pear)));
    buildArtifacts(createBuilder(DEFAULT_NUM_JOBS, true), pear);
    assertThat(recorder.actionExecutedEvents).hasSize(1);
    assertEquals(action, recorder.actionExecutedEvents.get(0).getAction());
}
Also used : Action(com.google.devtools.build.lib.actions.Action) TestAction(com.google.devtools.build.lib.actions.util.TestAction) EventBus(com.google.common.eventbus.EventBus) Artifact(com.google.devtools.build.lib.actions.Artifact) TestAction(com.google.devtools.build.lib.actions.util.TestAction) Test(org.junit.Test)

Aggregations

EventBus (com.google.common.eventbus.EventBus)142 Test (org.junit.Test)67 Before (org.junit.Before)23 BuckEventBus (com.facebook.buck.event.BuckEventBus)21 FakeClock (com.facebook.buck.timing.FakeClock)19 Subscribe (com.google.common.eventbus.Subscribe)19 EasyMock.anyObject (org.easymock.EasyMock.anyObject)18 Reporter (com.google.devtools.build.lib.events.Reporter)15 HashMap (java.util.HashMap)14 WatchEvent (java.nio.file.WatchEvent)12 ArrayList (java.util.ArrayList)12 AnalysisResult (com.google.devtools.build.lib.analysis.BuildView.AnalysisResult)8 List (java.util.List)8 Path (com.google.devtools.build.lib.vfs.Path)7 FakeWatchmanClient (com.facebook.buck.io.FakeWatchmanClient)6 Test (org.junit.jupiter.api.Test)6 File (java.io.File)5 ExecutorService (java.util.concurrent.ExecutorService)5 RefreshEndpointEvent (org.apache.servicecomb.http.client.event.RefreshEndpointEvent)5 BuildLangTypedAttributeValuesMap (com.google.devtools.build.lib.packages.RuleFactory.BuildLangTypedAttributeValuesMap)4