Browse Source

Await properly Reactor server start/stop

The goal is to try to fix #32
With this change de Reactor test seems to execute slowly.
pull/1111/head
Sebastien Deleuze 9 years ago
parent
commit
0042a65c53
  1. 22
      spring-web-reactive/src/main/java/org/springframework/reactive/web/http/reactor/ReactorHttpServer.java

22
spring-web-reactive/src/main/java/org/springframework/reactive/web/http/reactor/ReactorHttpServer.java

@ -18,7 +18,6 @@ package org.springframework.reactive.web.http.reactor;
import org.springframework.beans.factory.InitializingBean; import org.springframework.beans.factory.InitializingBean;
import org.springframework.reactive.web.http.HttpServer; import org.springframework.reactive.web.http.HttpServer;
import org.springframework.reactive.web.http.HttpServerSupport; import org.springframework.reactive.web.http.HttpServerSupport;
import org.springframework.reactive.web.http.reactor.RequestHandlerAdapter;
import org.springframework.util.Assert; import org.springframework.util.Assert;
import reactor.bus.selector.Selectors; import reactor.bus.selector.Selectors;
import reactor.io.buffer.Buffer; import reactor.io.buffer.Buffer;
@ -50,24 +49,33 @@ public class ReactorHttpServer extends HttpServerSupport implements Initializing
this.reactorHandler = new RequestHandlerAdapter(getHttpHandler()); this.reactorHandler = new RequestHandlerAdapter(getHttpHandler());
this.reactorServer = (getPort() != -1 ? this.reactorServer = (getPort() != -1 ?
NetStreams.httpServer(getPort()) : NetStreams.httpServer(getPort()) : NetStreams.httpServer());
NetStreams.httpServer());
} }
@Override @Override
public void start() { public void start() {
if (!this.running) { if (!this.running) {
this.running = true; try {
this.reactorServer.route(Selectors.matchAll(), this.reactorHandler).start(); this.reactorServer.route(Selectors.matchAll(), this.reactorHandler).start().await();
this.running = true;
}
catch (InterruptedException ex) {
throw new IllegalStateException(ex);
}
} }
} }
@Override @Override
public void stop() { public void stop() {
if (this.running) { if (this.running) {
this.running = false; try {
this.reactorServer.shutdown(); this.reactorServer.shutdown().await();
this.running = false;
}
catch (InterruptedException ex) {
throw new IllegalStateException(ex);
}
} }
} }

Loading…
Cancel
Save