Skip to content

Commit

Permalink
Completely remove Reactor 2
Browse files Browse the repository at this point in the history
  • Loading branch information
graemerocher committed Mar 28, 2017
1 parent 42b2c1d commit 229a888
Show file tree
Hide file tree
Showing 16 changed files with 82 additions and 482 deletions.
12 changes: 12 additions & 0 deletions grails-events-compat/src/main/groovy/grails/events/Events.groovy
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package grails.events

import groovy.transform.CompileStatic
import org.slf4j.LoggerFactory
import reactor.bus.Bus
import reactor.bus.Event
import reactor.bus.EventBus
Expand All @@ -22,6 +23,7 @@ trait Events {
* @see #on(reactor.bus.selector.Selector, reactor.fn.Consumer)
*/
def <E extends Event<?>> Subscription<Object, Consumer<E>> on(Class key, Closure consumer) {
LoggerFactory.getLogger(getClass()).warn("The class [${getClass()}] used the legacy Reactor 2 event bus and needs to be re-compiled")
on key.name, consumer
}

Expand All @@ -36,13 +38,16 @@ trait Events {
* @see #on(reactor.bus.selector.Selector, reactor.fn.Consumer)
*/
def <E extends Event<?> > Subscription<Object, Consumer<E>> on(key, Closure consumer) {
LoggerFactory.getLogger(getClass()).warn("The class [${getClass()}] used the legacy Reactor 2 event bus and needs to be re-compiled")

eventBus.on(key.toString(), consumer) as Subscription
}

/**
* @see #on(reactor.bus.selector.Selector, reactor.fn.Consumer)
*/
def <E extends Event<?> > Subscription<Object, Consumer<E>> on(key, Consumer<E> consumer) {
LoggerFactory.getLogger(getClass()).warn("The class [${getClass()}] used the legacy Reactor 2 event bus and needs to be re-compiled")
if(key instanceof CharSequence) {
key = key.toString()
}
Expand All @@ -55,6 +60,7 @@ trait Events {
* @see #on(reactor.bus.selector.Selector, reactor.fn.Consumer)
*/
def <E extends Event<?> > Subscription<Object, Consumer<E>> on(Class type, Consumer<E> consumer) {
LoggerFactory.getLogger(getClass()).warn("The class [${getClass()}] used the legacy Reactor 2 event bus and needs to be re-compiled")
on(type.name, consumer)
}

Expand All @@ -79,6 +85,7 @@ trait Events {
* @see reactor.bus.Bus#notify(java.lang.Object, java.lang.Object)
*/
Bus notify(Object key, Event<?> ev) {
LoggerFactory.getLogger(getClass()).warn("The class [${getClass()}] used the legacy Reactor 2 event bus and needs to be re-compiled")
if(eventBus == null) throw new IllegalStateException("EventBus not present. Event notification attempted outside of application context.")
if(ev.replyTo) {
eventBus.sendAndReceive( ev ) {
Expand All @@ -95,22 +102,26 @@ trait Events {
* @see reactor.bus.Bus#notify(java.lang.Object, reactor.bus.Event)
*/
Bus notify(Object key, data) {
LoggerFactory.getLogger(getClass()).warn("The class [${getClass()}] used the legacy Reactor 2 event bus and needs to be re-compiled")
eventBus.notify Event.wrap(key.toString(), data)
return eventBus
}

def <E extends Event<?>> Bus notify(Object key, Closure<E> supplier) {
if(eventBus == null) throw new IllegalStateException("EventBus not present. Event notification attempted outside of application context.")
LoggerFactory.getLogger(getClass()).warn("The class [${getClass()}] used the legacy Reactor 2 event bus and needs to be re-compiled")
eventBus.notify( (CharSequence)key.toString(), supplier.call() )
return eventBus
}

Bus sendAndReceive(Object key, data, Closure reply) {
LoggerFactory.getLogger(getClass()).warn("The class [${getClass()}] used the legacy Reactor 2 event bus and needs to be re-compiled")
eventBus.sendAndReceive(key.toString(), data, reply)
return eventBus
}

def <E extends Event<?>> Bus sendAndReceive(Object key, Closure reply) {
LoggerFactory.getLogger(getClass()).warn("The class [${getClass()}] used the legacy Reactor 2 event bus and needs to be re-compiled")
eventBus.sendAndReceive key.toString(), new grails.async.events.Event(key.toString(), new Object[0]), reply
return eventBus
}
Expand Down Expand Up @@ -156,6 +167,7 @@ trait Events {
* @return True if modifications were made
*/
boolean clearEventConsumers(key) {
LoggerFactory.getLogger(getClass()).warn("The class [${getClass()}] used the legacy Reactor 2 event bus and needs to be re-compiled")
if(eventBus) {
eventBus.unsubscribeAll(key.toString())
return true
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package reactor.bus

import groovy.util.logging.Slf4j
import reactor.bus.registry.Subscription
import reactor.bus.selector.Selector
import reactor.fn.Consumer
Expand All @@ -8,10 +9,15 @@ import reactor.fn.Consumer
* @deprecated Here for compatibility only. Do not use directly
*/
@Deprecated
@Slf4j
class EventBus implements Bus {

@Delegate grails.async.events.bus.EventBus eventBus

EventBus(grails.async.events.bus.EventBus eventBus) {
this.eventBus = eventBus
}

@Override
boolean respondsToKey(Object key) {
throw new UnsupportedOperationException()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package reactor.bus.registry

/**
* @deprecated Here for compatibility only. Do not use directly
*/
@Deprecated
interface Registration {
}
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,8 @@ class ActorEventBus extends AbstractEventBus implements Closeable {
}
}

@Override
boolean isActive() {
return actor.isActive()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ trait EventPublisher implements EventEmitter {
private EventBus eventBus

@Resource
void setEventBus(EventBus eventBus) {
void setTargetEventBus(EventBus eventBus) {
this.eventBus = eventBus
}

EventBus getEventBus() {
private EventBus getEventBus() {
if(this.eventBus == null) {
this.eventBus = EventBusFactory.create()
this.eventBus = new EventBusFactory().create()
}
return this.eventBus
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,10 @@ import grails.async.events.registry.EventRegistry
* @author Graeme Rocher
* @since 3.3
*/
interface EventBus extends EventEmitter, EventRegistry{
interface EventBus extends EventEmitter, EventRegistry {

/**
* @return Whether the event bus is active or has been shutdown
*/
boolean isActive()
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ import org.grails.async.events.bus.SynchronousEventBus
@Slf4j
class EventBusFactory {

static EventBus create() {
/**
* @return Tries to auto discover and create the event bus
*/
EventBus create() {
List<EventBus> eventBuses = ServiceLoader.load(EventBus).toList()
if(eventBuses.size() == 1) {
EventBus eventBus = eventBuses.get(0)
Expand All @@ -25,8 +28,12 @@ class EventBusFactory {
throw new IllegalStateException("More than one event bus implementation found on classpath ${eventBuses}. Remove one to continue.")
}
else {
log.warn("No event bus implementations found on classpath, using synchronous implementation.")
return new SynchronousEventBus()
return createDefaultEventBus()
}
}

protected EventBus createDefaultEventBus() {
log.warn("No event bus implementations found on classpath, using synchronous implementation.")
return new SynchronousEventBus()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ import grails.async.events.registry.Subscription
* @since 6.1
*/
abstract class AbstractEventBus implements EventBus {

@Override
boolean isActive() {
return true
}

@Override
EventEmitter notify(CharSequence eventId, Object... data) {
return notify(new Event(eventId.toString(), data.length == 1 ? data[0] : data))
Expand Down
1 change: 1 addition & 0 deletions grails-plugin-async/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ dependencies {
compileOnly 'javax:javaee-web-api:6.0'
compile "org.grails:grails-plugin-controllers:$grailsVersion"
compile project(':grails-plugin-events')
compile project(':grails-async')

testCompile "javax.servlet:javax.servlet-api:$servletApiVersion"
testCompile "org.springframework:spring-test:$springVersion"
Expand Down
13 changes: 1 addition & 12 deletions grails-plugin-events/build.gradle
Original file line number Diff line number Diff line change
@@ -1,15 +1,4 @@
dependencies {
compile "org.grails:grails-core:$grailsVersion"
compile project(":grails-async")

compile "io.projectreactor:reactor-core:$reactorCoreVersion"
compile "io.projectreactor:reactor-stream:$reactorCoreVersion"
compile "io.projectreactor:reactor-bus:$reactorCoreVersion"

compile "io.projectreactor.spring:reactor-spring-context:$reactorVersion", {
exclude module:'reactor-bus', group:'io.projectreactor'
exclude module:'json-path', group:'com.jayway.jsonpath'
}


compile project(":grails-events-compat")
}

This file was deleted.

Loading

0 comments on commit 229a888

Please sign in to comment.