(Quick Reference)

3 Usage

Version: 7.0.0-SNAPSHOT

Table of Contents

3 Usage

3.1 Async Plugin

To use the Async framework you should add a dependency on the async plugin to your build.gradle file:

build.gradle
implementation "org.graceframework:grace-plugin-async"
grace-plugin-async have been merged into the Grace framework.

By default the Promises static methods use an instance of PromiseFactory. This PromiseFactory interface has various implementations. The default implementation is CachedThreadPoolPromiseFactory which uses a thread pool that will create threads as needed (the same as java.util.concurrent.Executors.newCachedThreadPool())

However, the design of the promises framework is such that you can swap out the underlying implementation for your own or one of the pre-supported implementations. For example to use RxJava 1.x simply add the RxJava dependency to build.gradle:

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

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

Table 1. PromiseFactory Implementations
Framework Dependency Implementation Class

GPars 1.2.x

grace-async-gpars

org.grails.async.factory.gpars.GparsPromiseFactory

RxJava 1.2.x

grace-async-rxjava

org.grails.async.factory.rxjava.RxPromiseFactory

RxJava 2.x

grace-async-rxjava2

org.grails.async.factory.rxjava2.RxPromiseFactory

RxJava 3.x

grace-async-rxjava3

org.grails.async.factory.rxjava3.RxPromiseFactory

3.2 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