Search in sources :

Example 31 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 32 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 33 with EventBus

use of com.google.common.eventbus.EventBus in project graylog2-server by Graylog2.

the class StaticFieldFilterTest method testFilter.

@Test
@SuppressForbidden("Executors#newSingleThreadExecutor() is okay for tests")
public void testFilter() throws Exception {
    Message msg = new Message("hello", "junit", Tools.nowUTC());
    msg.setSourceInputId("someid");
    when(input.getId()).thenReturn("someid");
    when(inputService.all()).thenReturn(Collections.singletonList(input));
    when(inputService.find(eq("someid"))).thenReturn(input);
    when(inputService.getStaticFields(eq(input))).thenReturn(Collections.singletonList(Maps.immutableEntry("foo", "bar")));
    final StaticFieldFilter filter = new StaticFieldFilter(inputService, new EventBus(), Executors.newSingleThreadScheduledExecutor());
    filter.filter(msg);
    assertEquals("hello", msg.getMessage());
    assertEquals("junit", msg.getSource());
    assertEquals("bar", msg.getField("foo"));
}
Also used : Message(org.graylog2.plugin.Message) EventBus(com.google.common.eventbus.EventBus) Test(org.junit.Test) SuppressForbidden(org.graylog2.shared.SuppressForbidden)

Example 34 with EventBus

use of com.google.common.eventbus.EventBus in project graylog2-server by Graylog2.

the class GrokPatternRegistryTest method setUp.

@Before
public void setUp() {
    eventBus = new EventBus("Test");
    executor = Executors.newSingleThreadScheduledExecutor(new ThreadFactoryBuilder().setNameFormat("updater-%d").build());
    when(grokPatternService.loadAll()).thenReturn(GROK_PATTERNS);
    grokPatternRegistry = new GrokPatternRegistry(eventBus, grokPatternService, executor);
}
Also used : ThreadFactoryBuilder(com.google.common.util.concurrent.ThreadFactoryBuilder) EventBus(com.google.common.eventbus.EventBus) Before(org.junit.Before)

Example 35 with EventBus

use of com.google.common.eventbus.EventBus in project graylog2-server by Graylog2.

the class IOStateTest method testNotEqualIfDifferentInput.

@Test
public void testNotEqualIfDifferentInput() throws Exception {
    EventBus eventBus = mock(EventBus.class);
    MessageInput messageInput1 = mock(MessageInput.class);
    MessageInput messageInput2 = mock(MessageInput.class);
    IOState<MessageInput> inputState1 = new IOState<>(eventBus, messageInput1);
    IOState<MessageInput> inputState2 = new IOState<>(eventBus, messageInput2);
    assertFalse(inputState1.equals(inputState2));
    assertFalse(inputState2.equals(inputState1));
}
Also used : IOState(org.graylog2.plugin.IOState) EventBus(com.google.common.eventbus.EventBus) Test(org.junit.Test)

Aggregations

EventBus (com.google.common.eventbus.EventBus)85 Test (org.junit.Test)56 BuckEventBus (com.facebook.buck.event.BuckEventBus)21 FakeClock (com.facebook.buck.timing.FakeClock)19 EasyMock.anyObject (org.easymock.EasyMock.anyObject)18 Reporter (com.google.devtools.build.lib.events.Reporter)15 WatchEvent (java.nio.file.WatchEvent)12 Subscribe (com.google.common.eventbus.Subscribe)11 AnalysisResult (com.google.devtools.build.lib.analysis.BuildView.AnalysisResult)8 Before (org.junit.Before)8 Path (com.google.devtools.build.lib.vfs.Path)7 FakeWatchmanClient (com.facebook.buck.io.FakeWatchmanClient)6 ActionExecutionMetadata (com.google.devtools.build.lib.actions.ActionExecutionMetadata)4 ResourceHandle (com.google.devtools.build.lib.actions.ResourceManager.ResourceHandle)4 BuildLangTypedAttributeValuesMap (com.google.devtools.build.lib.packages.RuleFactory.BuildLangTypedAttributeValuesMap)4 HashMap (java.util.HashMap)4 Executor (com.google.devtools.build.lib.actions.Executor)3 Event (com.google.devtools.build.lib.events.Event)3 SuiteHint (com.carrotsearch.ant.tasks.junit4.balancers.SuiteHint)2 AggregatedQuitEvent (com.carrotsearch.ant.tasks.junit4.events.aggregated.AggregatedQuitEvent)2