当前位置: 首页>>代码示例>>Java>>正文


Java EventBus.post方法代码示例

本文整理汇总了Java中com.google.common.eventbus.EventBus.post方法的典型用法代码示例。如果您正苦于以下问题:Java EventBus.post方法的具体用法?Java EventBus.post怎么用?Java EventBus.post使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.google.common.eventbus.EventBus的用法示例。


在下文中一共展示了EventBus.post方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: onPullMicroserviceVersionsInstancesEvent

import com.google.common.eventbus.EventBus; //导入方法依赖的package包/类
@Test
public void onPullMicroserviceVersionsInstancesEvent(@Injectable ServiceRegistryConfig config,
    @Injectable MicroserviceDefinition definition, @Mocked MicroserviceVersions microserviceVersions) {
  PullMicroserviceVersionsInstancesEvent event = new PullMicroserviceVersionsInstancesEvent(microserviceVersions, 1);

  ScheduledThreadPoolExecutor taskPool = new MockUp<ScheduledThreadPoolExecutor>() {
    @Mock
    ScheduledFuture<?> schedule(Runnable command,
        long delay,
        TimeUnit unit) {
      Assert.assertEquals(1, delay);
      throw new Error("ok");
    }
  }.getMockInstance();

  expectedException.expect(Error.class);
  expectedException.expectMessage(Matchers.is("ok"));

  EventBus bus = new EventBus();
  RemoteServiceRegistry remote = new TestingRemoteServiceRegistry(bus, config, definition);
  bus.register(remote);
  Deencapsulation.setField(remote, "taskPool", taskPool);
  bus.post(event);
}
 
开发者ID:apache,项目名称:incubator-servicecomb-java-chassis,代码行数:25,代码来源:TestRemoteServiceRegistry.java

示例2: testAnonymous

import com.google.common.eventbus.EventBus; //导入方法依赖的package包/类
public void testAnonymous() {
  final AtomicReference<String> holder = new AtomicReference<String>();
  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());
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:19,代码来源:OutsideEventBusTest.java

示例3: start

import com.google.common.eventbus.EventBus; //导入方法依赖的package包/类
@Override
public void start(Stage stage) {
    Injector injector = Guice.createInjector(new GlobalModule());
    FilePersistence filePersistence = injector.getInstance(FilePersistence.class);
    EventBus eventBus = injector.getInstance(EventBus.class);
    injector.getInstance(FileChooserComponent.class).setOwner(stage);

    Scene scene = new Scene(injector.getInstance(AnimationEditorComponent.class).getRoot(), INITIAL_WIDTH, INITIAL_HEIGHT);
    scene.getStylesheets().add(getClass().getResource(STYLESHEET).toExternalForm());

    stage.setScene(scene);
    if (OsHelper.isWindows()) {
        stage.getIcons().add(new Image(getClass().getResource(ICON).toExternalForm()));
    }
    stage.titleProperty().bind(filePersistence.getTitle());
    stage.setOnCloseRequest(event -> {
        eventBus.post(MenuActionEvent.EXIT);
        event.consume();
    });
    injector.getInstance(StageConfigurer.class).initialize(stage);
    stage.setOpacity(0);
    stage.show();

    eventBus.post(LifecycleEvent.STAGE_ABOUT_TO_SHOW);

    Platform.runLater(() -> {
        stage.setOpacity(1);
        if (filePersistence.loadLastEditedFileIfExists()) {
            injector.getInstance(PanningHelper.class).panToContent();
        }
    });
}
 
开发者ID:rmfisher,项目名称:fx-animation-editor,代码行数:33,代码来源:AnimationEditorApp.java

示例4: setUp

import com.google.common.eventbus.EventBus; //导入方法依赖的package包/类
@Override
protected void setUp() throws Exception {
  subscriber = createSubscriber();
  EventBus bus = new EventBus();
  bus.register(subscriber);
  bus.post(EVENT);
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:8,代码来源:AnnotatedSubscriberFinderTests.java

示例5: disableMod

import com.google.common.eventbus.EventBus; //导入方法依赖的package包/类
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);
    }
}
 
开发者ID:F1r3w477,项目名称:CustomWorldGen,代码行数:15,代码来源:LoadController.java

示例6: testLifeCycle

import com.google.common.eventbus.EventBus; //导入方法依赖的package包/类
@Test
public void testLifeCycle(@Injectable ServiceRegistryConfig config, @Injectable MicroserviceDefinition definition,
    @Injectable ServiceRegistry registry) {
  ArrayList<IpPort> ipPortList = new ArrayList<>();
  ipPortList.add(new IpPort("127.0.0.1", 9980));
  ipPortList.add(new IpPort("127.0.0.1", 9981));

  new Expectations() {
    {
      definition.getConfiguration();
      result = ConfigUtil.createLocalConfig();
      config.getIpPort();
      result = ipPortList;
      config.getTransport();
      result = "rest";
      config.isRegistryAutoDiscovery();
      result = true;
      config.getHeartbeatInterval();
      result = 30;
      config.getInstancePullInterval();
      result = 30;
      config.isWatch();
      result = false;
    }
  };

  ServiceRegistry oldRegistry = RegistryUtils.getServiceRegistry();
  RegistryUtils.setServiceRegistry(registry);
  EventBus bus = new EventBus();
  RemoteServiceRegistry remote = new TestingRemoteServiceRegistry(bus, config, definition);
  remote.init();
  remote.run();
  Assert.assertTrue(2 <= remote.getTaskPool().getTaskCount()); // includes complete tasks

  bus.post(new ShutdownEvent());

  remote.getTaskPool().schedule(new Runnable() {
    @Override
    public void run() {
      // TODO Auto-generated method stub

    }
  }, 0, TimeUnit.SECONDS);
  Assert.assertTrue(remote.getTaskPool().isShutdown());
  RegistryUtils.setServiceRegistry(oldRegistry);
}
 
开发者ID:apache,项目名称:incubator-servicecomb-java-chassis,代码行数:47,代码来源:TestRemoteServiceRegistry.java

示例7: testBasicConfiguration

import com.google.common.eventbus.EventBus; //导入方法依赖的package包/类
@Test
public void testBasicConfiguration() throws Exception {

  EventBus eventBus = new EventBus("test-event-bus");

  MaterializedConfiguration materializedConfiguration = new
      SimpleMaterializedConfiguration();

  SourceRunner sourceRunner = mockLifeCycle(SourceRunner.class);
  materializedConfiguration.addSourceRunner("test", sourceRunner);

  SinkRunner sinkRunner = mockLifeCycle(SinkRunner.class);
  materializedConfiguration.addSinkRunner("test", sinkRunner);

  Channel channel = mockLifeCycle(Channel.class);
  materializedConfiguration.addChannel("test", channel);


  ConfigurationProvider configurationProvider = mock(ConfigurationProvider.class);
  when(configurationProvider.getConfiguration()).thenReturn(materializedConfiguration);

  Application application = new Application();
  eventBus.register(application);
  eventBus.post(materializedConfiguration);
  application.start();

  Thread.sleep(1000L);

  verify(sourceRunner).start();
  verify(sinkRunner).start();
  verify(channel).start();

  application.stop();

  Thread.sleep(1000L);

  verify(sourceRunner).stop();
  verify(sinkRunner).stop();
  verify(channel).stop();
}
 
开发者ID:moueimei,项目名称:flume-release-1.7.0,代码行数:41,代码来源:TestApplication.java


注:本文中的com.google.common.eventbus.EventBus.post方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。