Guava EventBus - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Guava EventBus class.

This code example shows how to use the following methods:register, sleep
 * Time: 5:53 PM 
 */ 
public class EventCoalescorTest { 
    @Test
    public void should_coalesce() throws Exception {
        EventBus eventBus = new EventBus();
        final List<String> messages = new ArrayList<>();
 
        eventBus.register(new Object() {
            @Subscribe 
            public void onMessage(String msg) { 
                messages.add(msg); 
            } 
        }); 
 
        EventCoalescor coalescor = new EventCoalescor(eventBus, 30);
 
        coalescor.post("test1");
        coalescor.post("test2");
        coalescor.post("test1");

7
CodeRank
This code example shows how to use the following methods:post, register, unregister
 
    @Test
    public void shouldNotReceiveEventAfterUnsubscribe() throws Exception {
 
        // given 
        EventBus eventBus = new EventBus("test");
        EventListener listener = new EventListener(); 
        EventReader reader = new EventReader();
 
        eventBus.register(listener);
        eventBus.register(reader);
 
        // when 
        eventBus.post(new OurTestEvent(200));
 
 
        // then 
        assertThat(reader.getLastMessage()).isEqualTo(200);
        assertThat(listener.getLastMessage()).isEqualTo(200); 
         

7
CodeRank
This code example shows how to use the following methods:post
 
    @Override 
    public void process(Exchange exchange) throws Exception {
        Object body = exchange.getIn().getBody();
        if (body != null) { 
            log.debug("Posting: {} to EventBus: {}", body, eventBus);
            eventBus.post(body);
        } else { 
            log.debug("Body is null, cannot post to EventBus"); 
        } 
    } 
 
} 
7
CodeRank
This code example shows how to use the following methods:post
 
    private ChunkMonitor() { 
    } 
 
    private static void post(Object event) { 
        EVENT_BUS.post(event);
    } 
 
    private static synchronized ChunkMonitorEntry registerChunk(Chunk chunk) {
        Preconditions.checkNotNull(chunk, "The parameter 'chunk' must not be null");
        final Vector3i pos = chunk.getPosition();
        ChunkMonitorEntry entry = CHUNKS.get(pos);
        if (entry == null) {
            entry = new ChunkMonitorEntry(pos);
            CHUNKS.put(pos, entry);
        } 
        entry.addChunk(chunk);
        return entry;
    } 
 
6
CodeRank
This code example shows how to use the following methods:register
@SuppressWarnings("serial") 
public class AggregateView extends CustomComponent { 
 
	public AggregateView() { 
 
		EventBus bus = new EventBus();
 
		FormLayout layout = new FormLayout();
 
		FirstComponent first = new FirstComponent(bus);
 
		SecondComponent second = new SecondComponent();
 
		bus.register(second);
 
		layout.addComponent(first);
		layout.addComponent(second);
 
		setCompositionRoot(layout);
	} 
6
CodeRank
This code example shows how to use the following methods:register
    * Provides asynchronous {@link EventBus}. 
    */ 
   @Provides 
   @Singleton 
   EventBus provideSyncEventBus(DeadEventLoggingHandler deadEventsHandler) { // NO_UCD
      EventBus syncBus = new EventBus("jclouds-sync-event-bus");
      syncBus.register(deadEventsHandler);
      return syncBus;
   } 
 
   /** 
    * Configures the {@link EventBus} to be singleton and enables the {@link AsyncBus} annotation. 
    */ 
   @Override 
   protected void configure() { 
      bind(EventBus.class).annotatedWith(AsyncBus.class).to(AsyncEventBus.class).in(SINGLETON);
   } 
} 
6
CodeRank
This code example shows how to use the following methods:register
 
		navigator = new Navigator(getPage(), viewDisplay);
		 
		navigator.addListener(new ViewChangeSecurityChecker());
 
		navigator.addView(LOGIN_VIEW_NAME, new LoginView(bus));
		navigator.addView(MAIN_VIEW_NAME, new MainView(bus));
 
		navigator.navigateTo(LOGIN_VIEW_NAME);
 
		bus.register(this);
	} 
 
	@Subscribe 
	public void login(LoginEvent event) {
 
		AuthenticationService authHandler = new AuthenticationService();
 
		try { 
 
6
CodeRank
This code example shows how to use the following methods:register
                           VelocityEngine velocityEngine,
                           GeneratorUtil generatorUtil,
                           EventBus eventBus) {
        super(typeOracle, logger, velocityContextProvider, velocityEngine, generatorUtil);
 
        eventBus.register(this);
    } 
 
    public String generate(JType type) throws UnableToCompleteException {
        this.type = type;
 
        String implName = type.getParameterizedQualifiedSourceName();
        implName = implName.replaceAll("[ ,<>\\.\\?]", "_");
        implName += "Mapper";
 
        mergeTemplate(TEMPLATE, implName);
        return implName;
    } 
 
    @Override 
6
CodeRank
This code example shows how to use the following methods:register
                                    VelocityEngine velocityEngine,
                                    GeneratorUtil generatorUtil,
                                    EventBus eventBus) {
        super(typeOracle, logger, velocityContextProvider, velocityEngine, generatorUtil);
 
        eventBus.register(this);
    } 
 
    public void generate() throws UnableToCompleteException { 
        String implName = ActionMetadataProvider.class.getSimpleName() + SUFFIX;
        mergeTemplate(TEMPLATE, implName);
    } 
 
    @Subscribe 
    public void handleRegisterMetadata(RegisterMetadataEvent event) {
        String metadata = event.getMetadata();
        MetadataType metadataType = event.getMetadataType();
        String actionClass = event.getActionClass();
 
        RegisterMetadataHolder metadataHolder = new RegisterMetadataHolder(actionClass, metadataType, metadata);
6
CodeRank
This code example shows how to use the following methods:post
        this.eventStore = eventStore;
    } 
 
    @Override 
    public void publishEvent(DomainEvent event) {
        eventBus.post(event);
        eventStore.append(event);
    } 
 
    @Override 
    public void registerSubscriber(Object subscriber) { 
        eventBus.register(subscriber);
    } 
 
    @Override 
    public void unregisterSubscriber(Object subscriber) { 
        eventBus.unregister(subscriber);
    } 
} 
6
CodeRank
See Code Examples for Guava EventBus Methods: