Search in sources :

Example 36 with EventBus

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

the class DeadEventLoggingListenerTest method testEventListenerWithEventBus.

@Test
public void testEventListenerWithEventBus() {
    final EventBus eventBus = new EventBus("test");
    final SimpleEvent event = new SimpleEvent("test");
    final DeadEventLoggingListener listener = spy(new DeadEventLoggingListener());
    eventBus.register(listener);
    eventBus.post(event);
    verify(listener, times(1)).handleDeadEvent(any(DeadEvent.class));
}
Also used : EventBus(com.google.common.eventbus.EventBus) DeadEvent(com.google.common.eventbus.DeadEvent) Test(org.junit.Test)

Example 37 with EventBus

use of com.google.common.eventbus.EventBus in project trex-stateless-gui by cisco-system-traffic-generator.

the class MainViewController method initialize.

@Override
public void initialize(URL url, ResourceBundle rb) {
    portManager = PortsManager.getInstance();
    portManager.setPortManagerHandler(this);
    statsTableGenerator = new StatsTableGenerator();
    leftArrow = new Image("/icons/arrow_left.png");
    rightArrow = new Image("/icons/arrow_right.png");
    initializeInlineComponent();
    logsContainer.setDisable(false);
    eventBus = TrexApp.injector.getInstance(EventBus.class);
    portView.visibleProperty().bind(portViewVisibilityProperty);
    statTableContainer.visibleProperty().bindBidirectional(systemInfoVisibilityProperty);
    // Handle update port state event
    AsyncResponseManager.getInstance().asyncEventObjectProperty().addListener((observable, oldValue, newVal) -> {
        TrexEvent event = newVal;
        int portId = event.getData().getAsJsonPrimitive("port_id").getAsInt();
        PortModel portModel = portManager.getPortModel(portId);
        switch(event.getType()) {
            case PORT_RELEASED:
            case PORT_ACQUIRED:
            case PORT_ATTR_CHANGED:
            case PORT_STARTED:
            case PORT_STOPPED:
                if (ConnectionManager.getInstance().isConnected()) {
                    Platform.runLater(() -> {
                        portManager.updatedPorts(Arrays.asList(portModel.getIndex()));
                        onPortListUpdated(true);
                    });
                    boolean isAllPortsStopped = true;
                    for (final Port port : portManager.getPortList()) {
                        if (port.getIndex() == port.getIndex()) {
                            continue;
                        }
                        final String portStatus = port.getStatus();
                        if (portStatus.equals("TX") || portStatus.equals("PAUSE")) {
                            isAllPortsStopped = false;
                            break;
                        }
                    }
                }
                break;
            case SERVER_STOPPED:
                resetApplication(true);
                break;
        }
    });
}
Also used : TrexEvent(com.exalttech.trex.core.TrexEvent) PortModel(com.exalttech.trex.ui.models.PortModel) Port(com.exalttech.trex.ui.models.Port) StatsTableGenerator(com.exalttech.trex.ui.views.statistics.StatsTableGenerator) EventBus(com.google.common.eventbus.EventBus) Image(javafx.scene.image.Image)

Example 38 with EventBus

use of com.google.common.eventbus.EventBus in project MantaroBot by Mantaro.

the class MantaroCore method startMainComponents.

public MantaroCore startMainComponents(boolean single) throws Exception {
    if (config == null)
        throw new IllegalArgumentException("Config cannot be null!");
    if (useSentry)
        Sentry.init(config.sentryDSN);
    if (useBanner)
        new BannerPrinter(1).printBanner();
    if (commandsPackage == null)
        throw new IllegalArgumentException("Cannot look for commands if you don't specify where!");
    if (optsPackage == null)
        throw new IllegalArgumentException("Cannot look for options if you don't specify where!");
    Future<Set<Class<?>>> commands = lookForAnnotatedOn(commandsPackage, Module.class);
    Future<Set<Class<?>>> options = lookForAnnotatedOn(optsPackage, Option.class);
    if (single) {
        startSingleShardInstance();
    } else {
        startShardedInstance();
    }
    shardEventBus = new EventBus();
    for (Class<?> aClass : commands.get()) {
        try {
            shardEventBus.register(aClass.newInstance());
        } catch (Exception e) {
            log.error("Invalid module: no zero arg public constructor found for " + aClass);
        }
    }
    for (Class<?> clazz : options.get()) {
        try {
            shardEventBus.register(clazz.newInstance());
        } catch (Exception e) {
            log.error("Invalid module: no zero arg public constructor found for " + clazz);
        }
    }
    Async.thread("Mantaro EventBus-Post", () -> {
        // For now, only used by AsyncInfoMonitor startup and Anime Login Task.
        shardEventBus.post(new PreLoadEvent());
        // Registers all commands
        shardEventBus.post(DefaultCommandProcessor.REGISTRY);
        // Registers all options
        shardEventBus.post(new OptionRegistryEvent());
    });
    return this;
}
Also used : Set(java.util.Set) OptionRegistryEvent(net.kodehawa.mantarobot.options.event.OptionRegistryEvent) BannerPrinter(net.kodehawa.mantarobot.utils.banner.BannerPrinter) EventBus(com.google.common.eventbus.EventBus) PreLoadEvent(net.kodehawa.mantarobot.core.listeners.events.PreLoadEvent)

Example 39 with EventBus

use of com.google.common.eventbus.EventBus in project camel by apache.

the class GuavaEventBusConsumerConfigurationTest method invalidConfiguration.

@Test
public void invalidConfiguration() throws Exception {
    // Given
    SimpleRegistry registry = new SimpleRegistry();
    registry.put("eventBus", new EventBus());
    CamelContext context = new DefaultCamelContext(registry);
    context.addRoutes(new RouteBuilder() {

        @Override
        public void configure() throws Exception {
            from("guava-eventbus:eventBus?listenerInterface=org.apache.camel.component.guava.eventbus.CustomListener&eventClass=org.apache.camel.component.guava.eventbus.MessageWrapper").to("mock:customListenerEvents");
        }
    });
    try {
        context.start();
        fail("Should throw exception");
    } catch (FailedToCreateRouteException e) {
        IllegalStateException ise = assertIsInstanceOf(IllegalStateException.class, e.getCause());
        assertEquals("You cannot set both 'eventClass' and 'listenerInterface' parameters.", ise.getMessage());
    }
}
Also used : CamelContext(org.apache.camel.CamelContext) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) FailedToCreateRouteException(org.apache.camel.FailedToCreateRouteException) RouteBuilder(org.apache.camel.builder.RouteBuilder) SimpleRegistry(org.apache.camel.impl.SimpleRegistry) EventBus(com.google.common.eventbus.EventBus) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) FailedToCreateRouteException(org.apache.camel.FailedToCreateRouteException) Test(org.junit.Test)

Example 40 with EventBus

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

the class StandaloneSpawnStrategy method exec.

/**
   * Executes the given {@code spawn}.
   */
@Override
public void exec(Spawn spawn, ActionExecutionContext actionExecutionContext) throws ExecException, InterruptedException {
    EventBus eventBus = actionExecutionContext.getExecutor().getEventBus();
    ActionExecutionMetadata owner = spawn.getResourceOwner();
    eventBus.post(ActionStatusMessage.schedulingStrategy(owner));
    try (ResourceHandle handle = resourceManager.acquireResources(owner, spawn.getLocalResources())) {
        eventBus.post(ActionStatusMessage.runningStrategy(owner, "standalone"));
        actuallyExec(spawn, actionExecutionContext);
    }
}
Also used : ActionExecutionMetadata(com.google.devtools.build.lib.actions.ActionExecutionMetadata) ResourceHandle(com.google.devtools.build.lib.actions.ResourceManager.ResourceHandle) EventBus(com.google.common.eventbus.EventBus)

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