Coder Social home page Coder Social logo

guava-eventbus-spring's Introduction

This project provides Spring schema-based extension for scanning and registering Guava EventBus event handlers

How to build

Clone from GIT and then use Gradle:

$ git clone ...
$ gradle build (or './gradlew build' if you don't have gradle in your path)

How to use

Here is a simple example:

public interface EventHandler { void handle(T event); }

implementation:

public class AlertEventHandler implements EventHandler<String> {

    private static final Logger LOGGER = LoggerFactory.getLogger(AlertEventHandler.class);

    @Override
    @Subscribe
    public void handle(String event) {
        LOGGER.info("GOT EVENT: {}", event);
    }
}

spring definition:

<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:eventbus="http://sargis.info/eventbus"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
       http://sargis.info/eventbus http://sargis.info/eventbus/eventbus-spring-1.0.xsd">

    <eventbus:handler-scan base-package="info.sargis.spring.eventbus" eventbus-ref="eventBus">
        <eventbus:include type="assignable" expression="info.sargis.spring.eventbus.EventHandler"/>
        <!-- We can use other filters as well
        <eventbus:include type="annotation" expression="..."/>
        <eventbus:include type="regex" expression="..."/>
        <eventbus:include type="custom" expression="..."/>
        -->
    </eventbus:handler-scan>

    <bean id="eventBus" class="com.google.common.eventbus.EventBus"/>

</beans>

test application:

public class GuavaEventBusTest {
    public static void main(String[] args) {
        GenericApplicationContext applicationContext = .... // Starting spring context

        EventBus bean = applicationContext.getBean(EventBus.class);
        bean.post("Hello Guava EventBus");
    }
}

and I get the following output:

20:17:33.646 [main] INFO i.s.s.eventbus.AlertEventHandler - GOT EVENT: Hello Guava EventBus

guava-eventbus-spring's People

Contributors

armsargis avatar

Stargazers

 avatar

Watchers

Kenyatta Clark avatar James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.