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));
}
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;
}
});
}
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;
}
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());
}
}
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);
}
}
Aggregations