Java Code Examples for com.google.common.eventbus.EventBus#register()
The following examples show how to use
com.google.common.eventbus.EventBus#register() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TaskStatusStatsTest.java From attic-aurora with Apache License 2.0 | 5 votes |
@Before public void setUp() { statsProvider = createMock(StatsProvider.class); clock = new FakeClock(); eventBus = new EventBus(); eventBus.register(new TaskStatusStats(statsProvider, clock)); }
Example 2
Source File: ClientDefaultInitializer.java From servicecomb-java-chassis with Apache License 2.0 | 5 votes |
@Override public void init(EventBus eventBus, AccessLogConfig accessLogConfig) { if (!accessLogConfig.isClientLogEnabled()) { return; } accessLogGenerator = new AccessLogGenerator(accessLogConfig.getClientLogPattern()); eventBus.register(this); }
Example 3
Source File: DefaultLogPublisher.java From servicecomb-java-chassis with Apache License 2.0 | 5 votes |
@Override public void init(GlobalRegistry globalRegistry, EventBus eventBus, MetricsBootstrapConfig config) { if (!DynamicPropertyFactory.getInstance() .getBooleanProperty(ENABLED, false) .get()) { return; } initLatencyDistribution(); eventBus.register(this); }
Example 4
Source File: DummyTaskReaderListener.java From DataLink with Apache License 2.0 | 5 votes |
@Override public void init() { EventBus eventBus = EventBusFactory.getEventBus(); eventBus.register(new Object() { @Subscribe public void listener(String s) { } }); }
Example 5
Source File: EventBusTest.java From javabase with Apache License 2.0 | 5 votes |
/** * * @param args */ public static void main(String[] args) { EventBus eventBus=new EventBus(SEND_ORDER_MESSAGE); //注册订阅者 eventBus.register(new OrderEventListener()); eventBus.register(new EmailEventListener()); //发布事件 eventBus.post("123"); }
Example 6
Source File: ActionExecutionStatusReporterTest.java From bazel with Apache License 2.0 | 5 votes |
@Before public final void initializeEventBus() throws Exception { events = new EventCollectionApparatus(EventKind.ALL_EVENTS); statusReporter = ActionExecutionStatusReporter.create(events.reporter(), clock); eventBus = new EventBus(); eventBus.register(statusReporter); }
Example 7
Source File: InvalidStateExceptionTest.java From micro-server with Apache License 2.0 | 5 votes |
@Before public void setup() { bus = new ErrorBus(); EventBus ebus = new EventBus(); ebus.register(this); ErrorBus.setErrorBus(ebus); }
Example 8
Source File: SSEEventSourceServlet.java From airpal with Apache License 2.0 | 5 votes |
@Inject public SSEEventSourceServlet(ObjectMapper objectMapper, EventBus eventBus, @Named("sse") ExecutorService executorService, MetricRegistry registry, AirpalUserFactory userFactory) { this.jobUpdateToSSERelay = new JobUpdateToSSERelay(objectMapper, executorService, registry); this.userFactory = userFactory; eventBus.register(jobUpdateToSSERelay); }
Example 9
Source File: EventBusTest.java From onetwo with Apache License 2.0 | 5 votes |
@Test public void testEventBus(){ EventBus eventBus = new EventBus(); eventBus.register(new Object(){ @Subscribe public void listener(TestEvent event){ System.out.println("listener1:"+event.name); } }); /*eventBus.register(new Object(){ @Subscribe public void listener(TestEvent event){ System.out.println("listener2:"+event.name); if(true) throw new BaseException("error"); } }); eventBus.register(new Object(){ @Subscribe public void listener(TestEvent event){ System.out.println("listener3:"+event.name); if(true) throw new BaseException("error"); } });*/ eventBus.post(new TestEvent("test")); eventBus.post(new TestEvent("test")); }
Example 10
Source File: GuavaEventBusUnitTest.java From tutorials with MIT License | 5 votes |
@Before public void setUp() { eventBus = new EventBus(); listener = new EventListener(); eventBus.register(listener); }
Example 11
Source File: TestWorkUnitStreamSource.java From incubator-gobblin with Apache License 2.0 | 4 votes |
/** * This test uses a slow source to verify that we can stream work units through local job launcher, with available units * being processes eagerly even if not all work units are available. */ @Test public void test() throws Exception { String eventBusId = UUID.randomUUID().toString(); MyListener listener = new MyListener(); EventBus eventBus = TestingEventBuses.getEventBus(eventBusId); eventBus.register(listener); EmbeddedGobblin embeddedGobblin = new EmbeddedGobblin("testStreamedSource") .setConfiguration(EventBusPublishingTaskFactory.EVENTBUS_ID_KEY, eventBusId) .setConfiguration(ConfigurationKeys.SOURCE_CLASS_KEY, MySource.class.getName()) .setConfiguration(EventBusPublishingTaskFactory.Source.NUM_TASKS_KEY, "5"); JobExecutionDriver driver = embeddedGobblin.runAsync(); if (!listener.iteratorReady.tryAcquire(2, TimeUnit.SECONDS)) { throw new RuntimeException("Failed to get start signal."); } Assert.assertFalse(listener.tasksRun.tryAcquire(50, TimeUnit.MILLISECONDS)); eventBus.post(new MySource.NextWorkUnit()); Assert.assertTrue(listener.tasksRun.tryAcquire(500, TimeUnit.MILLISECONDS)); Assert.assertFalse(listener.tasksRun.tryAcquire(50, TimeUnit.MILLISECONDS)); eventBus.post(new MySource.NextWorkUnit()); Assert.assertTrue(listener.tasksRun.tryAcquire(500, TimeUnit.MILLISECONDS)); Assert.assertFalse(listener.tasksRun.tryAcquire(50, TimeUnit.MILLISECONDS)); eventBus.post(new MySource.NextWorkUnit()); eventBus.post(new MySource.NextWorkUnit()); eventBus.post(new MySource.NextWorkUnit()); JobExecutionResult result = driver.get(5, TimeUnit.SECONDS); Assert.assertTrue(result.isSuccessful()); SetMultimap<String, Integer> eventsSeen = listener.getEventsSeenMap(); Set<Integer> expected = Sets.newHashSet(0, 1, 2, 3, 4); Assert.assertEquals(eventsSeen.get(EventBusPublishingTaskFactory.RUN_EVENT), expected); Assert.assertEquals(eventsSeen.get(EventBusPublishingTaskFactory.COMMIT_EVENT), expected); Assert.assertEquals(eventsSeen.get(EventBusPublishingTaskFactory.PUBLISH_EVENT), expected); }
Example 12
Source File: RequestTypes.java From micro-server with Apache License 2.0 | 4 votes |
public RequestTypes(EventBus bus, boolean queryCapture) { this.bus = bus; if (queryCapture) bus.register(this); }
Example 13
Source File: TickDynamicMod.java From TickDynamic with MIT License | 4 votes |
@Override public boolean registerBus(EventBus bus, LoadController controller) { bus.register(this); return true; }
Example 14
Source File: CouchbaseResource.java From micro-server with Apache License 2.0 | 4 votes |
@Autowired public CouchbaseResource(DistributedMap client, EventBus bus) { this.client = client; bus.register(this); }
Example 15
Source File: OpenModsCore.java From OpenModsLib with MIT License | 4 votes |
@Override public boolean registerBus(EventBus bus, LoadController controller) { bus.register(this); return true; }
Example 16
Source File: CouchbaseResource.java From micro-server with Apache License 2.0 | 4 votes |
@Autowired public CouchbaseResource(DistributedMap client, EventBus bus) { this.client = client; bus.register(this); }
Example 17
Source File: RequestsBeingExecuted.java From micro-server with Apache License 2.0 | 4 votes |
public RequestsBeingExecuted(EventBus bus, String type) { this.bus = bus; this.type = type; bus.register(this); }
Example 18
Source File: NovaMinecraftPreloader.java From NOVA-Core with GNU Lesser General Public License v3.0 | 4 votes |
@Override public boolean registerBus(EventBus bus, LoadController controller) { bus.register(this); return true; }
Example 19
Source File: GobblinHelixTaskTest.java From incubator-gobblin with Apache License 2.0 | 4 votes |
@Test public void testPrepareTask() throws IOException, InterruptedException { EventBus eventBus = EventBusFactory.get(ContainerHealthCheckFailureEvent.CONTAINER_HEALTH_CHECK_EVENT_BUS_NAME, SharedResourcesBrokerFactory.getImplicitBroker()); eventBus.register(this); countDownLatchForFailInTaskCreation = new CountDownLatch(1); // Serialize the JobState that will be read later in GobblinHelixTask Path jobStateFilePath = new Path(appWorkDir, TestHelper.TEST_JOB_ID + "." + AbstractJobLauncher.JOB_STATE_FILE_NAME); JobState jobState = new JobState(); jobState.setJobName(TestHelper.TEST_JOB_NAME); jobState.setJobId(TestHelper.TEST_JOB_ID); SerializationUtils.serializeState(this.localFs, jobStateFilePath, jobState); // Prepare the WorkUnit WorkUnit workUnit = WorkUnit.createEmpty(); prepareWorkUnit(workUnit); // Prepare the source Json file File sourceJsonFile = new File(this.appWorkDir.toString(), TestHelper.TEST_JOB_NAME + ".json"); TestHelper.createSourceJsonFile(sourceJsonFile); workUnit.setProp(SimpleJsonSource.SOURCE_FILE_KEY, sourceJsonFile.getAbsolutePath()); // Serialize the WorkUnit into a file // expected path is appWorkDir/_workunits/job_id/job_id.wu Path workUnitDirPath = new Path(this.appWorkDir, GobblinClusterConfigurationKeys.INPUT_WORK_UNIT_DIR_NAME); FsStateStore<WorkUnit> wuStateStore = new FsStateStore<>(this.localFs, workUnitDirPath.toString(), WorkUnit.class); Path workUnitFilePath = new Path(new Path(workUnitDirPath, TestHelper.TEST_JOB_ID), TestHelper.TEST_JOB_NAME + ".wu"); wuStateStore.put(TestHelper.TEST_JOB_ID, TestHelper.TEST_JOB_NAME + ".wu", workUnit); Assert.assertTrue(this.localFs.exists(workUnitFilePath)); // Prepare the GobblinHelixTask Map<String, String> taskConfigMap = Maps.newHashMap(); taskConfigMap.put(GobblinClusterConfigurationKeys.WORK_UNIT_FILE_PATH, workUnitFilePath.toString()); taskConfigMap.put(ConfigurationKeys.JOB_NAME_KEY, TestHelper.TEST_JOB_NAME); taskConfigMap.put(ConfigurationKeys.JOB_ID_KEY, TestHelper.TEST_JOB_ID); taskConfigMap.put(ConfigurationKeys.TASK_KEY_KEY, Long.toString(Id.parse(TestHelper.TEST_JOB_ID).getSequence())); TaskConfig taskConfig = new TaskConfig("", taskConfigMap, true); TaskCallbackContext taskCallbackContext = Mockito.mock(TaskCallbackContext.class); when(taskCallbackContext.getTaskConfig()).thenReturn(taskConfig); when(taskCallbackContext.getManager()).thenReturn(this.helixManager); TaskDriver taskDriver = createTaskDriverWithMockedAttributes(taskCallbackContext, taskConfig); TaskRunnerSuiteBase.Builder builder = new TaskRunnerSuiteBase.Builder(ConfigFactory.empty() .withValue(RETRY_TYPE, ConfigValueFactory.fromAnyRef(RetryerFactory.RetryType.FIXED_ATTEMPT.name())) .withValue(RETRY_TIMES, ConfigValueFactory.fromAnyRef(2)) ); TaskRunnerSuiteBase sb = builder.setInstanceName("TestInstance") .setApplicationName("TestApplication") .setAppWorkPath(appWorkDir) .setContainerMetrics(Optional.absent()) .setFileSystem(localFs) .setJobHelixManager(this.helixManager) .setApplicationId("TestApplication-1") .build(); GobblinHelixTaskFactory gobblinHelixTaskFactory = new GobblinHelixTaskFactory(builder, sb.metricContext, this.taskStateTracker, ConfigFactory.empty(), Optional.of(taskDriver)); // Expect to go through. this.gobblinHelixTask = (GobblinHelixTask) gobblinHelixTaskFactory.createNewTask(taskCallbackContext); // Mock the method getFs() which get called in SingleTask constructor, so that SingleTask could fail and trigger retry, // which would also fail eventually with timeout. TaskRunnerSuiteBase.Builder builderSpy = Mockito.spy(builder); when(builderSpy.getFs()).thenThrow(new RuntimeException("failure on purpose")); gobblinHelixTaskFactory = new GobblinHelixTaskFactory(builderSpy, sb.metricContext, this.taskStateTracker, ConfigFactory.empty(), Optional.of(taskDriver)); // Expecting the eventBus containing the failure signal when run is called try { gobblinHelixTaskFactory.createNewTask(taskCallbackContext).run(); } catch (Throwable t){ return; } Assert.fail(); }
Example 20
Source File: MainController.java From scava with Eclipse Public License 2.0 | 4 votes |
public MainController(Controller parent, MainModel model, EventBus eventBus) { super(parent, model); this.eventBus = eventBus; eventBus.register(this); }