當前位置: 首頁>>代碼示例>>Java>>正文


Java EventBus類代碼示例

本文整理匯總了Java中com.google.common.eventbus.EventBus的典型用法代碼示例。如果您正苦於以下問題:Java EventBus類的具體用法?Java EventBus怎麽用?Java EventBus使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


EventBus類屬於com.google.common.eventbus包,在下文中一共展示了EventBus類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: configure

import com.google.common.eventbus.EventBus; //導入依賴的package包/類
@Override
protected void configure() {
    bind(EventBus.class).toInstance(new EventBus((exception, context) -> {
        exceptionOccurred = true;
        exception.printStackTrace();
    }));

    bind(CommandStack.class).in(Singleton.class);
    bind(TimelineModel.class).in(Singleton.class);
    bind(SceneModel.class).in(Singleton.class);
    bind(PropertyModel.class).in(Singleton.class);
    bind(InterpolatorListModel.class).in(Singleton.class);

    bind(MenuActionHandler.class).asEagerSingleton();
    bind(PropertyEditHandler.class).asEagerSingleton();
    bind(TimelineHandler.class).asEagerSingleton();
    bind(TimelineSceneSynchronizer.class).asEagerSingleton();
    bind(ScenePropertySynchronizer.class).asEagerSingleton();
    bind(SelectionDragHandler.class).asEagerSingleton();

    bind(FileChooserComponent.class).toInstance(Mockito.mock(FileChooserComponent.class));
    bind(PanningHelper.class).toInstance(Mockito.mock(PanningHelper.class));
    bind(SaveDialogComponent.class).toInstance(Mockito.mock(SaveDialogComponent.class));
}
 
開發者ID:rmfisher,項目名稱:fx-animation-editor,代碼行數:25,代碼來源:EventTest.java

示例2: 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

示例3: setup

import com.google.common.eventbus.EventBus; //導入依賴的package包/類
@Before
public void setup() {
  eventBus = new EventBus();

  taskList = new ArrayList<>();
  eventBus.register(new Object() {
    @Subscribe
    public void onEvent(MicroserviceInstanceRegisterTask task) {
      taskList.add(task);
    }
  });

  microservice = new Microservice();
  microservice.setAppId("app");
  microservice.setServiceName("ms");
  microservice.setServiceId("serviceId");

  microservice.setInstance(new MicroserviceInstance());

  HealthCheck healthCheck = new HealthCheck();
  healthCheck.setMode(HealthCheckMode.HEARTBEAT);
  microservice.getInstance().setHealthCheck(healthCheck);
}
 
開發者ID:apache,項目名稱:incubator-servicecomb-java-chassis,代碼行數:24,代碼來源:TestMicroserviceInstanceRegisterTask.java

示例4: setup

import com.google.common.eventbus.EventBus; //導入依賴的package包/類
@Before
public void setup() {
  eventBus = new EventBus();

  taskList = new ArrayList<>();
  eventBus.register(new Object() {
    @Subscribe
    public void onEvent(MicroserviceRegisterTask task) {
      taskList.add(task);
    }
  });

  microservice = new Microservice();
  microservice.setAppId("app");
  microservice.setServiceName("ms");

  microservice.setInstance(new MicroserviceInstance());
}
 
開發者ID:apache,項目名稱:incubator-servicecomb-java-chassis,代碼行數:19,代碼來源:TestMicroserviceRegisterTask.java

示例5: setUp

import com.google.common.eventbus.EventBus; //導入依賴的package包/類
@Before
public void setUp() {
    Injector injector = Guice.createInjector(new EventTestModule());
    eventBus = injector.getInstance(EventBus.class);
    sceneModel = injector.getInstance(SceneModel.class);
    timelineModel = injector.getInstance(TimelineModel.class);
    addInterpolators(injector.getInstance(InterpolatorListModel.class));
    configureMockFileChooser(injector.getInstance(FileChooserComponent.class));
    configureMockSaveDialog(injector.getInstance(SaveDialogComponent.class));

    KeyFrameModel keyFrame = new KeyFrameModel();
    timelineModel.getKeyFrames().add(keyFrame);
    timelineModel.setSelectedKeyFrame(keyFrame);

    actions.remove(MenuActionEvent.EXIT);
}
 
開發者ID:rmfisher,項目名稱:fx-animation-editor,代碼行數:17,代碼來源:EventTest.java

示例6: AnimationEditorComponent

import com.google.common.eventbus.EventBus; //導入依賴的package包/類
@Inject
public AnimationEditorComponent(MenuBarComponent menuBar, AnimationEditorPresenter presenter, TimelineEditorComponent timelineEditor,
                                PropertyEditorComponent propertyEditor, SceneComponent scene, PlayerComponent player, PropertyStore propertyStore,
                                SaveDialogComponent saveDialogComponent, EventBus eventBus) {

    this.menuBar = menuBar;
    this.timelineEditor = timelineEditor;
    this.propertyEditor = propertyEditor;
    this.scene = scene;
    this.player = player;
    this.propertyStore = propertyStore;
    this.saveDialogComponent = saveDialogComponent;
    initUi();
    initPresenter(presenter);
    configureDividerPosition();
    subscribeToEvents(eventBus);
}
 
開發者ID:rmfisher,項目名稱:fx-animation-editor,代碼行數:18,代碼來源:AnimationEditorComponent.java

示例7: MinecraftServiceImpl

import com.google.common.eventbus.EventBus; //導入依賴的package包/類
@Inject MinecraftServiceImpl(Loggers loggers,
                             EventBus eventBus,
                             SyncExecutor syncExecutor,
                             ServerService serverService,
                             MinecraftApiConfiguration apiConfiguration,
                             MessageQueue serverQueue,
                             LocalServerDocument localServerDocument,
                             StartupServerDocument startupDocument) {

    this.logger = loggers.get(getClass());
    this.eventBus = eventBus;
    this.syncExecutor = syncExecutor;
    this.serverService = serverService;
    this.apiConfiguration = apiConfiguration;
    this.serverQueue = serverQueue;

    this.everfreshLocalServer = ProxyUtils.newProxy(Server.class, new MethodHandleInvoker() {
        @Override
        protected Object targetFor(Method method) {
            if(server != null) return server;
            if(Methods.respondsTo(localServerDocument, method)) return localServerDocument;
            throw new ApiNotConnected();
        }
    });
    this.startupDocument = startupDocument;
}
 
開發者ID:OvercastNetwork,項目名稱:ProjectAres,代碼行數:27,代碼來源:MinecraftServiceImpl.java

示例8: 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

示例9: testFLUME1854

import com.google.common.eventbus.EventBus; //導入依賴的package包/類
@Test
public void testFLUME1854() throws Exception {
  File configFile = new File(baseDir, "flume-conf.properties");
  Files.copy(new File(getClass().getClassLoader()
      .getResource("flume-conf.properties").getFile()), configFile);
  Random random = new Random();
  for (int i = 0; i < 3; i++) {
    EventBus eventBus = new EventBus("test-event-bus");
    PollingPropertiesFileConfigurationProvider configurationProvider =
        new PollingPropertiesFileConfigurationProvider("host1",
            configFile, eventBus, 1);
    List<LifecycleAware> components = Lists.newArrayList();
    components.add(configurationProvider);
    Application application = new Application(components);
    eventBus.register(application);
    application.start();
    Thread.sleep(random.nextInt(10000));
    application.stop();
  }
}
 
開發者ID:moueimei,項目名稱:flume-release-1.7.0,代碼行數:21,代碼來源:TestApplication.java

示例10: setUp

import com.google.common.eventbus.EventBus; //導入依賴的package包/類
@Before
public void setUp() throws Exception {

  baseDir = Files.createTempDir();

  configFile = new File(baseDir, TESTFILE.getName());
  Files.copy(TESTFILE, configFile);

  eventBus = new EventBus("test");
  provider =
      new PollingPropertiesFileConfigurationProvider("host1",
          configFile, eventBus, 1);
  provider.start();
  LifecycleController.waitForOneOf(provider, LifecycleState.START_OR_ERROR);
}
 
開發者ID:moueimei,項目名稱:flume-release-1.7.0,代碼行數:16,代碼來源:TestPollingPropertiesFileConfigurationProvider.java

示例11: 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:paul-hammant,項目名稱:googles-monorepo-demo,代碼行數:19,代碼來源:OutsideEventBusTest.java

示例12: LoadController

import com.google.common.eventbus.EventBus; //導入依賴的package包/類
public LoadController(Loader loader)
{
    this.loader = loader;
    this.masterChannel = new EventBus(new SubscriberExceptionHandler()
    {
        @Override
        public void handleException(Throwable exception, SubscriberExceptionContext context)
        {
            FMLLog.log("FMLMainChannel", Level.ERROR, exception, "Could not dispatch event: %s to %s", context.getEvent(), context.getSubscriberMethod());
        }
    });
    this.masterChannel.register(this);

    state = LoaderState.NOINIT;
    packageOwners = ArrayListMultimap.create();

}
 
開發者ID:F1r3w477,項目名稱:CustomWorldGen,代碼行數:18,代碼來源:LoadController.java

示例13: registerBus

import com.google.common.eventbus.EventBus; //導入依賴的package包/類
@Override
public boolean registerBus(EventBus bus, LoadController controller)
{
    if (this.enabled)
    {
        FMLLog.log(getModId(), Level.DEBUG, "Enabling mod %s", getModId());
        this.eventBus = bus;
        this.controller = controller;
        eventBus.register(this);
        return true;
    }
    else
    {
        return false;
    }
}
 
開發者ID:F1r3w477,項目名稱:CustomWorldGen,代碼行數:17,代碼來源:FMLModContainer.java

示例14: AbstractServiceRegistry

import com.google.common.eventbus.EventBus; //導入依賴的package包/類
public AbstractServiceRegistry(EventBus eventBus, ServiceRegistryConfig serviceRegistryConfig,
    MicroserviceDefinition microserviceDefinition) {
  this.eventBus = eventBus;
  this.serviceRegistryConfig = serviceRegistryConfig;
  this.microserviceDefinition = microserviceDefinition;
  this.microservice = microserviceFactory.create(microserviceDefinition);
}
 
開發者ID:apache,項目名稱:incubator-servicecomb-java-chassis,代碼行數:8,代碼來源:AbstractServiceRegistry.java

示例15: createLocal

import com.google.common.eventbus.EventBus; //導入依賴的package包/類
public static ServiceRegistry createLocal() {
  EventBus eventBus = new EventBus();
  ServiceRegistryConfig serviceRegistryConfig = ServiceRegistryConfig.INSTANCE;
  MicroserviceConfigLoader loader = new MicroserviceConfigLoader();
  loader.loadAndSort();

  MicroserviceDefinition microserviceDefinition = new MicroserviceDefinition(loader.getConfigModels());
  return new LocalServiceRegistry(eventBus, serviceRegistryConfig, microserviceDefinition);
}
 
開發者ID:apache,項目名稱:incubator-servicecomb-java-chassis,代碼行數:10,代碼來源:ServiceRegistryFactory.java


注:本文中的com.google.common.eventbus.EventBus類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。