reactor.groovy.config.StreamRouter Maven / Gradle / Ivy
package reactor.groovy.config;
import org.reactivestreams.Processor;
import org.reactivestreams.Subscriber;
import org.reactivestreams.Subscription;
import reactor.bus.Event;
import reactor.bus.filter.Filter;
import reactor.bus.registry.Registration;
import reactor.bus.registry.Registry;
import reactor.bus.routing.ConsumerFilteringRouter;
import reactor.fn.Consumer;
import java.util.List;
/**
* @author Stephane Maldini
*/
public class StreamRouter extends ConsumerFilteringRouter {
private final Registry, Event>>> processorRegistry;
public StreamRouter(Filter filter,
Registry, Event>>> processorRegistry) {
super(filter);
this.processorRegistry = processorRegistry;
}
@Override
@SuppressWarnings("unchecked")
public > void route(final Object key, final E event,
final List>>> consumers,
final Consumer completionConsumer,
final Consumer errorConsumer) {
Processor, Event>> processor;
for (Registration extends Processor, Event>>> registration : processorRegistry.select(key)){
processor = registration.getObject();
processor.onNext(event);
processor.subscribe(new Subscriber>() {
@Override
public void onSubscribe(Subscription subscription) {
subscription.request(Integer.MAX_VALUE);
}
@Override
public void onNext(Event> hydratedEvent) {
StreamRouter.super.route(hydratedEvent.getKey(), (E) hydratedEvent, consumers, completionConsumer,
errorConsumer);
}
@Override
public void onComplete() {
}
@Override
public void onError(Throwable cause) {
event.consumeError(cause);
}
});
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy