(Quick Reference)

3 Usage

Version: 7.0.0-SNAPSHOT

Table of Contents

3 Usage

3.1 Events Plugin

This project introduces a new Events API that replaces the previous implementation that was based on Reactor 2.x (which is no longer maintained and deprecated).

The Events framework introduces a new EventBus abstraction. Like the PromiseFactory notion, there are implementations of the EventBus interface for common asynchronous frameworks like GPars and RxJava.

To use the Events abstraction you should add a dependency on the events plugin to your build.gradle file:

build.gradle
implementation "org.graceframework:grace-plugin-events"
Since 7.0, Grace events modules have already been split into its' own repository grace-events. And grace-plugin-events have been merged into the Grace framework.

If no asynchronous framework in present on the classpath then by default Grace creates an EventBus based off of the currently active PromiseFactory. The default implementation is CachedThreadPoolPromiseFactory which uses a thread pool that will create threads as needed (the same as java.util.concurrent.Executors.newCachedThreadPool()).

If you wish to use a popular async framework such as RxJava as the EventBus implementation then you will need to add the appropriate dependency. For example for RxJava 1.x:

build.gradle
implementation "org.graceframework:grace-events-rxjava:7.0.0-SNAPSHOT"

The following table summarizes async framework support and the necessary dependency:

Table 1. EventBus Implementations
Framework Dependency Implementation Class

GPars 1.2.x

grace-events-gpars

org.grails.events.gpars.ActorEventBus

RxJava 1.2.x

grace-events-rxjava

org.grails.events.rxjava.RxEventBus

RxJava 2.x

grace-events-rxjava2

org.grails.events.rxjava2.RxEventBus

RxJava 3.x

grace-events-rxjava3

org.grails.events.rxjava3.RxEventBus