Giter VIP home page Giter VIP logo

events4j's Introduction

Events4J

Latest Bugs Code Smells Duplicated Lines (%) SonarCloud Coverage

Click the module name in the table below for specific import instructions. (gradle, maven, ...)

Module Javadoc Description
Lib Javadoc contains all interfaces
Lib Javadoc contains the EventManager implementation
Lib improvements for usage in kotlin projects
Lib Javadoc a simple synchronous event handler
Lib Javadoc a event dispatcher using project reactor
Lib Javadoc forward events to spring ApplicationEventPublisher

Description

Events4J provides the following features:

  • publish events
  • register consumers / listeners for events
  • comes with a few prebuilt handlers that you can use out of the box
  • provide your custom implementation to process events however you want

Usage

Initialization

EventManager eventManager = new EventManager(); // new instance
eventManager.autoDiscovery(); // register modules automatically

Event Producer

TestEvent testEvent = new TestEvent();
eventManager.publish(testEvent);

Event Consumer

Subscriber-based

IEventManager eventManager = new EventManager();
ReactorEventHandler reactorEventHandler = new ReactorEventHandler(eventManager);
eventManager.registerEventHandler(reactorEventHandler);

The Consumer

reactorEventHandler.onEvent(TestEvent.class).subscribe(event -> {
    log.info("TestEvent received");
});

Simple

If you want to use annotation-based events, you need to enable this feature. Annotation-based event consumers are disabled by default.

IEventManager eventManager = new EventManager();
SimpleEventHandler simpleEventHandler = new SimpleEventHandler();
eventManager.registerEventHandler(simpleEventHandler);

The Consumer

public class TestEventListener {

    @EventSubscriber
    public void onTestEvent(TestEvent testEvent) {
        System.out.println("TestEvent received");
    }

}

Register the Consumer

eventManager.registerListener(new TestEventListener());

Spring Events

Configure the following in your application.properties to enable spring application events:

events4j.handler.spring.enabled: true

The Consumer

@EventListener
public void handleContextStart(TestEvent testEvent) {
    System.out.println("TestEvent received");
}

Kotlin

The kotlin module allows the usage of flows to consume events.

eventManager.flowOn<TestEvent>()
    .collect { testEvent ->
        println("TestEvent received")
    }

License

Released under the MIT License.

events4j's People

Contributors

dependabot[bot] avatar github-actions[bot] avatar iprodigy avatar philippheuer avatar renovate[bot] avatar samfundev avatar sethfalco avatar subside 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.