Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
...
  • 3 commits
  • 4 files changed
  • 0 commit comments
  • 1 contributor
View
2  application.properties
@@ -1,5 +1,5 @@
#Grails Metadata file
-#Wed Mar 21 10:05:32 GMT 2012
+#Thu Mar 29 17:35:06 CEST 2012
app.grails.version=2.0.1
app.name=PlatformCore
plugins.svn=1.0.2
View
2  grails-app/conf/BuildConfig.groovy
@@ -30,7 +30,7 @@ grails.project.dependency.resolution = {
plugins {
build(":tomcat:$grailsVersion",
- ":release:1.0.2-SNAPSHOT") {
+ ":release:2.0.0.BUILD-SNAPSHOT") {
export = false
}
View
38 src/groovy/org/grails/plugin/platform/events/Events.groovy
@@ -18,15 +18,13 @@
package org.grails.plugin.platform.events
import grails.util.GrailsNameUtils
-import java.lang.reflect.Method
import org.apache.log4j.Logger
+import org.grails.plugin.platform.events.dispatcher.DefaultEventsDispatcher
import org.grails.plugin.platform.events.publisher.EventsPublisher
import org.grails.plugin.platform.events.registry.EventsRegistry
-import org.grails.plugin.platform.util.PluginUtils
import org.springframework.context.ApplicationContext
-import org.springframework.context.ApplicationContextAware
-import org.codehaus.groovy.grails.plugins.metadata.GrailsPlugin
-import org.grails.plugin.platform.events.dispatcher.DefaultEventsDispatcher
+
+import java.lang.reflect.Method
class Events {
@@ -37,14 +35,14 @@ class Events {
DefaultEventsDispatcher grailsEventsDispatcher
private ApplicationContext applicationContext
def grailsApplication
-
+
def injectedMethods = { theContext ->
'controller, domain, service' { Class clazz ->
String scope = null
//PluginUtils.getNameOfDefiningPlugin(theContext, clazz)
def self = theContext.grailsEvents
-
+
event {String topic, data = null, Map params = null ->
self._event(scope, topic, data, params)
}
@@ -54,7 +52,7 @@ class Events {
eventAsync {String topic, data, Closure callback, params = null ->
self._eventAsyncClosure(scope, topic, data, callback, params)
}
- eventAsync {String topic, Closure callback , params = null ->
+ eventAsync {String topic, Closure callback, params = null ->
self._eventAsyncClosure(scope, topic, null, callback, params)
}
copyFrom(self.grailsEventsPublisher, 'waitFor')
@@ -76,7 +74,7 @@ class Events {
grailsEventsPublisher.eventAsync(new EventObject(source: scope, event: topic, data: data))
}
- void _eventAsyncClosure(String scope, String topic, data, Closure callback, Map params = null) {
+ void _eventAsyncClosure(String scope, String topic, data, Closure callback, Map params = null) {
if (log.debugEnabled) {
log.debug "Sending event of scope [$scope] and topic [$topic] with data [${data}] with callback Closure and params [${params}]"
}
@@ -94,23 +92,29 @@ class Events {
log.info "events removed : $removedListeners"
}
- void registerListeners(Collection<Class<?>> serviceClasses) {
+ static void eachListener(Collection<Class<?>> serviceClasses, Closure c) {
for (Class<?> serviceClass in serviceClasses) {
-// grailsEventsDispatcher.scanClassForMappings(serviceClass)
for (Method method: serviceClass.declaredMethods) {
Listener annotation = method.getAnnotation(Listener)
if (annotation) {
- log.info "Register event listener $serviceClass.name#$method.name for topic ${annotation.value() ?: method.name}"
- grailsEventsRegistry.addListener(
- annotation.value() ?: method.name,
- applicationContext.getBean(GrailsNameUtils.getPropertyName(serviceClass)),
- method
- )
+ c(annotation.value() ?: method.name, method, serviceClass)
}
}
}
}
+ void registerListeners(Collection<Class<?>> serviceClasses) {
+// grailsEventsDispatcher.scanClassForMappings(serviceClass)
+ eachListener(serviceClasses) {String listenerId, Method method, Class serviceClass->
+ log.info "Register event listener $serviceClass.name#$method.name for topic $listenerId"
+ grailsEventsRegistry.addListener(
+ listenerId,
+ applicationContext.getBean(GrailsNameUtils.getPropertyName(serviceClass)),
+ method
+ )
+ }
+ }
+
void initListeners() {
this.applicationContext = grailsApplication.mainContext
registerListeners(grailsApplication.serviceClasses*.clazz)
View
11 src/java/org/grails/plugin/platform/events/ListenerId.java
@@ -39,6 +39,7 @@
private static final String ID_CLASS_SEPARATOR = ":";
private static final String ID_METHOD_SEPARATOR = "#";
private static final String ID_HASHCODE_SEPARATOR = "@";
+
private static final Pattern idRegex = Pattern.compile(
"([^" + ID_CLASS_SEPARATOR + "]*)?" +
"(" + ID_CLASS_SEPARATOR + "([^" + ID_METHOD_SEPARATOR + "]*))?"
@@ -97,12 +98,18 @@ public void setHashCode(String hashCode) {
this.hashCode = hashCode;
}
+ //format : topic:package.Class#method@hashCode
public String toString() {
- return (topic != null ? topic : "") + (className != null ? ID_CLASS_SEPARATOR + className : "")
- + (methodName != null ? ID_METHOD_SEPARATOR + methodName : "")
+ return toStringWithoutHash()
+ (hashCode != null ? ID_HASHCODE_SEPARATOR + hashCode : "");
}
+ // format : topic:package.Class#method
+ public String toStringWithoutHash() {
+ return (topic != null ? topic : "") + (className != null ? ID_CLASS_SEPARATOR + className : "")
+ + (methodName != null ? ID_METHOD_SEPARATOR + methodName : "");
+ }
+
static public ListenerId build(String topic, Object target, Method callback) {
return new ListenerId(topic, target.getClass().getName(), callback.getName(), Integer.toString(target.hashCode()));
}

No commit comments for this range

Something went wrong with that request. Please try again.