-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revert removal of deprecated grails-events-compat (#69)
* Revert "Remove deprecated grails-events-compat project." This reverts commit f5e36db. * build: Change groovy core library declaration name It's name was previously a sub-path of other groovy modules * build: Add dependency resolution of Groovy Snapshot versions
- Loading branch information
Showing
28 changed files
with
531 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
## grails-events-compat | ||
|
||
This subproject established a compatibility layer for plugins built with older versions of Grails that worked with Reactor 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
plugins { | ||
|
||
id 'groovy' | ||
id 'java-library' | ||
|
||
id 'maven-publish' | ||
id 'signing' | ||
|
||
} | ||
|
||
group = 'org.grails' | ||
|
||
dependencies { | ||
|
||
implementation project(':grails-events-core') | ||
implementation project(':grails-events-transform') | ||
|
||
implementation libs.groovy.core | ||
|
||
implementation libs.slf4j.api | ||
implementation libs.spring.tx | ||
|
||
} | ||
|
||
apply from: file("$rootProject.projectDir/gradle/java-config.gradle") | ||
apply from: file("$rootProject.projectDir/gradle/publishing.gradle") |
30 changes: 30 additions & 0 deletions
30
grails-events-compat/src/main/groovy/grails/artefact/Service.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* | ||
* Copyright 2014 original authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package grails.artefact | ||
|
||
import grails.events.Events | ||
|
||
|
||
/** | ||
* A trait implemented for services that implement events | ||
* | ||
* @author Graeme Rocher | ||
* @since 3.0 | ||
* @deprecated Here for compatibility, do not use directly | ||
*/ | ||
@Deprecated | ||
trait Service extends Events { | ||
} |
181 changes: 181 additions & 0 deletions
181
grails-events-compat/src/main/groovy/grails/events/Events.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,181 @@ | ||
package grails.events | ||
|
||
import groovy.transform.CompileDynamic | ||
import groovy.transform.CompileStatic | ||
import org.slf4j.LoggerFactory | ||
import reactor.bus.Bus | ||
import reactor.bus.Event | ||
import reactor.bus.EventBus | ||
import reactor.bus.registry.Registration | ||
import reactor.bus.registry.Subscription | ||
import reactor.bus.selector.Selector | ||
import reactor.fn.Consumer | ||
|
||
/** | ||
* Bridges the OLD API to the new | ||
* @deprecated Here for compatibility only. Do not use directly | ||
*/ | ||
@Deprecated | ||
@CompileStatic | ||
trait Events { | ||
|
||
EventBus eventBus | ||
|
||
/** | ||
* @see #on(reactor.bus.selector.Selector, reactor.fn.Consumer) | ||
*/ | ||
def <E extends Event<?>> Registration<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 | ||
} | ||
|
||
/** | ||
* @see #on(reactor.bus.selector.Selector, reactor.fn.Consumer) | ||
*/ | ||
def <E extends Event<?> > Registration<Object, Consumer<E>> on(Selector key, Closure consumer) { | ||
throw new UnsupportedOperationException("Events of type [Selector] are no longer supported. Use string ids") | ||
} | ||
|
||
/** | ||
* @see #on(reactor.bus.selector.Selector, reactor.fn.Consumer) | ||
*/ | ||
def <E extends Event<?> > Registration<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 Registration | ||
} | ||
|
||
/** | ||
* @see #on(reactor.bus.selector.Selector, reactor.fn.Consumer) | ||
*/ | ||
def <E extends Event<?> > Registration<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() | ||
} | ||
on(key) { | ||
consumer.accept(it as E) | ||
} | ||
} | ||
|
||
/** | ||
* @see #on(reactor.bus.selector.Selector, reactor.fn.Consumer) | ||
*/ | ||
def <E extends Event<?> > Registration<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) | ||
} | ||
|
||
/** | ||
* Register a {@link reactor.fn.Consumer} to be triggered when a notification matches the given {@link | ||
* Selector}. | ||
* | ||
* @param sel | ||
* The {@literal Selector} to be used for matching | ||
* @param consumer | ||
* The {@literal Consumer} to be triggered | ||
* @param <E> | ||
* The type of the {@link Event} | ||
* | ||
* @return A {@link Subscription} object that allows the caller to interact with the given mapping | ||
*/ | ||
def <E extends Event<?> > Registration<Object, Consumer<E>> on(Selector sel, Consumer<E> consumer) { | ||
throw new UnsupportedOperationException("Events of type [Selector] are no longer supported. Use string ids") | ||
} | ||
|
||
/** | ||
* @see reactor.bus.Bus#notify(java.lang.Object, java.lang.Object) | ||
*/ | ||
@CompileDynamic | ||
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 ) { | ||
eventBus.notify(ev.replyTo.toString(), it) | ||
} | ||
} | ||
else { | ||
eventBus.notify key, ev | ||
} | ||
return eventBus | ||
} | ||
|
||
/** | ||
* @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.from(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.events.Event(key.toString(), new Object[0]), reply | ||
return eventBus | ||
} | ||
|
||
|
||
|
||
/** | ||
* Creates an {@link Event} for the given data | ||
* | ||
* @param data The data | ||
* @return The event | ||
*/ | ||
def <T> Event<T> eventFor(T data) { | ||
throw new UnsupportedOperationException("Use [grails.events.Event] instead") | ||
} | ||
|
||
/** | ||
* Creates an {@link Event} for the given headers and data | ||
* | ||
* @param headers The headers | ||
* @param data The data | ||
* @return The event | ||
*/ | ||
def <T> Event<T> eventFor(Map<String, Object> headers, T data) { | ||
throw new UnsupportedOperationException("Use [grails.events.Event] instead") | ||
} | ||
|
||
/** | ||
* Creates an {@link Event} for the given headers, data and error consumer | ||
* | ||
* @param headers The headers | ||
* @param data The data | ||
* @param errorConsumer The errors consumer | ||
* @return The event | ||
*/ | ||
def <T> Event<T> eventFor(Map<String, Object> headers, T data, Closure<Throwable> errorConsumer) { | ||
throw new UnsupportedOperationException("Use [grails.events.Event] instead") | ||
} | ||
|
||
/** | ||
* Clears event consumers for the given key | ||
* @param key The key | ||
* @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 | ||
} | ||
return false | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package reactor.bus; | ||
|
||
import reactor.bus.registry.Subscription; | ||
import reactor.bus.selector.Selector; | ||
import reactor.fn.Consumer; | ||
|
||
/** | ||
* Basic unit of event handling in Reactor. | ||
* | ||
* @author Jon Brisbin | ||
* @author Stephane Maldini | ||
* @author Andy Wilkinson | ||
* @deprecated Here for compatibility only. Do not use directly | ||
*/ | ||
@Deprecated | ||
public interface Bus<T> { | ||
|
||
/** | ||
* Are there any {@link Subscription}s with {@link Selector Selectors} that match the given {@code key}. | ||
* | ||
* @param key The key to be matched by {@link Selector Selectors} | ||
* @return {@literal true} if there are any matching {@literal Subscription}s, {@literal false} otherwise | ||
*/ | ||
boolean respondsToKey(Object key); | ||
|
||
/** | ||
* Register a {@link reactor.fn.Consumer} to be triggered when a notification matches the given {@link | ||
* Selector}. | ||
* | ||
* @param selector The {@literal Selector} to be used for matching | ||
* @param consumer The {@literal Consumer} to be triggered | ||
* @return A {@link Subscription} object that allows the caller to interact with the given mapping | ||
*/ | ||
<V extends T> Subscription<Object, Consumer<? extends T>> on(final Selector selector, | ||
final Consumer<V> consumer); | ||
|
||
|
||
/** | ||
* Notify this component that an {@link Event} is ready to be processed. | ||
* | ||
* @param key The key to be matched by {@link Selector Selectors} | ||
* @param ev The {@literal Event} | ||
* @return {@literal this} | ||
*/ | ||
Bus notify(Object key, T ev); | ||
} |
Oops, something went wrong.