/** * Register listener. */ public void register() { eventBus.register(this); }
/** * Register listener. */ public void register() { eventBus.register(this); }
@Inject public InputEventListener(EventBus eventBus, InputLauncher inputLauncher, InputRegistry inputRegistry, InputService inputService, NodeId nodeId) { this.inputLauncher = inputLauncher; this.inputRegistry = inputRegistry; this.inputService = inputService; this.nodeId = nodeId; eventBus.register(this); }
public LogicSchema(final String name, final Map<String, YamlDataSourceParameter> dataSources) { this.name = name; // TODO :jiaqi only use JDBC need connect db via JDBC, netty style should use SQL packet to get metadata this.dataSources = dataSources; backendDataSource = new JDBCBackendDataSource(dataSources); eventBus.register(this); }
public LogicSchema(final String name, final Map<String, YamlDataSourceParameter> dataSources) { this.name = name; // TODO :jiaqi only use JDBC need connect db via JDBC, netty style should use SQL packet to get metadata this.dataSources = dataSources; backendDataSource = new JDBCBackendDataSource(dataSources); eventBus.register(this); }
public AbstractOrchestrationDataSource(final ShardingOrchestrationFacade shardingOrchestrationFacade) { this.shardingOrchestrationFacade = shardingOrchestrationFacade; ShardingOrchestrationEventBus.getInstance().register(this); }
public void testMissingSubscribe() { bus.register(new Object()); }
@Inject public OrderedAuthenticatingRealms(Map<String, AuthenticatingRealm> realms, ClusterConfigService clusterConfigService, EventBus eventBus) { this.availableRealms = realms; this.clusterConfigService = clusterConfigService; eventBus.register(this); sortRealms(); // sortRealms should have produced a reasonable default Objects.requireNonNull(orderedRealms.get()); }
@Override protected void startUp() throws Exception { eventBus.register(this); MetricUtils.safelyRegisterAll(metricRegistry, new CacheStatsSet(name(ConfigurationService.class, "etag-cache"), cache)); }
@Override public void run() { StringCatcher catcher = new StringCatcher(); bus.register(catcher); catchers.add(catcher); } }
public void testEventOrderingIsPredictable() { EventProcessor processor = new EventProcessor(); bus.register(processor); EventRecorder recorder = new EventRecorder(); bus.register(recorder); bus.post(FIRST); assertEquals( "EventRecorder expected events in order", Lists.<Object>newArrayList(FIRST, SECOND), recorder.eventsReceived); }
public void testNoReentrantEvents() { ReentrantEventsHater hater = new ReentrantEventsHater(); bus.register(hater); bus.post(FIRST); assertEquals( "ReentrantEventHater expected 2 events", Lists.<Object>newArrayList(FIRST, SECOND), hater.eventsReceived); }
/** * Tests that bridge methods are not subscribed to events. In Java 8, annotations are included on * the bridge method in addition to the original method, which causes both the original and bridge * methods to be subscribed (since both are annotated @Subscribe) without specifically checking * for bridge methods. */ public void testRegistrationWithBridgeMethod() { final AtomicInteger calls = new AtomicInteger(); bus.register( new Callback<String>() { @Subscribe @Override public void call(String s) { calls.incrementAndGet(); } }); bus.post("hello"); assertEquals(1, calls.get()); }
@Override protected void setUp() throws Exception { subscriber = createSubscriber(); EventBus bus = new EventBus(); bus.register(subscriber); bus.post(EVENT); }
public void testSubscriberThrowsExceptionHandlerThrowsException() throws Exception { final EventBus eventBus = new EventBus( new SubscriberExceptionHandler() { @Override public void handleException(Throwable exception, SubscriberExceptionContext context) { throw new RuntimeException(); } }); final Object subscriber = new Object() { @Subscribe public void throwExceptionOn(String message) { throw new RuntimeException(); } }; eventBus.register(subscriber); try { eventBus.post(EVENT); } catch (RuntimeException e) { fail("Exception should not be thrown."); } }
public void testAnonymous() { final AtomicReference<String> holder = new AtomicReference<>(); final AtomicInteger deliveries = new AtomicInteger(); EventBus bus = new EventBus(); bus.register( new Object() { @Subscribe public void accept(String str) { holder.set(str); deliveries.incrementAndGet(); } }); String EVENT = "Hello!"; bus.post(EVENT); assertEquals("Only one event should be delivered.", 1, deliveries.get()); assertEquals("Correct string should be delivered.", EVENT, holder.get()); } }
public void testBasicCatcherDistribution() { StringCatcher catcher = new StringCatcher(); bus.register(catcher); bus.post(EVENT); List<String> events = catcher.getEvents(); assertEquals("Only one event should be delivered.", 1, events.size()); assertEquals("Correct string should be delivered.", EVENT, events.get(0)); }
public void testDeadEventForwarding() { GhostCatcher catcher = new GhostCatcher(); bus.register(catcher); // A String -- an event for which noone has registered. bus.post(EVENT); List<DeadEvent> events = catcher.getEvents(); assertEquals("One dead event should be delivered.", 1, events.size()); assertEquals("The dead event should wrap the original event.", EVENT, events.get(0).getEvent()); }
public void testDeadEventPosting() { GhostCatcher catcher = new GhostCatcher(); bus.register(catcher); bus.post(new DeadEvent(this, EVENT)); List<DeadEvent> events = catcher.getEvents(); assertEquals("The explicit DeadEvent should be delivered.", 1, events.size()); assertEquals("The dead event must not be re-wrapped.", EVENT, events.get(0).getEvent()); }
public void testSubscriberThrowsException() throws Exception { final RecordingSubscriberExceptionHandler handler = new RecordingSubscriberExceptionHandler(); final EventBus eventBus = new EventBus(handler); final RuntimeException exception = new RuntimeException("but culottes have a tendancy to ride up!"); final Object subscriber = new Object() { @Subscribe public void throwExceptionOn(String message) { throw exception; } }; eventBus.register(subscriber); eventBus.post(EVENT); assertEquals("Cause should be available.", exception, handler.exception); assertEquals("EventBus should be available.", eventBus, handler.context.getEventBus()); assertEquals("Event should be available.", EVENT, handler.context.getEvent()); assertEquals("Subscriber should be available.", subscriber, handler.context.getSubscriber()); assertEquals( "Method should be available.", subscriber.getClass().getMethod("throwExceptionOn", String.class), handler.context.getSubscriberMethod()); }