Collection<ReactorBuilder> pushBuilders =
grailsEvents.getGroovyEnvironment().reactorBuildersByExtension(EventsPushConstants.TO_BROWSERS);
Closure broadcastClientFilter;
Object cursor;
Selector selector;
Object key;
Iterator iterableConfiguration;
Set<Registration<?>> registrations = new HashSet<Registration<?>>();
for (ReactorBuilder pushBuilder : pushBuilders) {
cursor = pushBuilder.ext(EventsPushConstants.TO_BROWSERS);
if (!Map.class.isAssignableFrom(cursor.getClass()) && !Collection.class.isAssignableFrom(cursor.getClass())) {
continue;
}
iterableConfiguration = Map.class.isAssignableFrom(cursor.getClass()) ?
((Map) cursor).entrySet().iterator() :
((Collection) cursor).iterator();
while (iterableConfiguration.hasNext()) {
cursor = iterableConfiguration.next();
broadcastClientFilter = null;
if (Map.Entry.class.isAssignableFrom(cursor.getClass())) {
key = ((Map.Entry) cursor).getKey();
if (((Map.Entry) cursor).getValue() != null &&
Map.class.isAssignableFrom(((Map.Entry) cursor).getValue().getClass())) {
broadcastClientFilter = (Closure) ((Map) ((Map.Entry) cursor).getValue()).get(CLIENT_FILTER_PARAM);
}
} else {
key = cursor;
}
if (key != null) {
selector = Selector.class.isAssignableFrom(key.getClass()) ?
(Selector) key :
Selectors.$(key);
if (selector.matches(topic)) {
registrations.add(pushBuilder.get().on(Selectors.$(topic),
new AtmosphereConsumer(resource, broadcastClientFilter)));
}
}
}