Fix ReactorHttpServer with latest changes on shutdown behavior
This commit is contained in:
parent
0042a65c53
commit
985640b6ce
|
@ -13,21 +13,23 @@
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.springframework.reactive.web.http.reactor;
|
package org.springframework.reactive.web.http.reactor;
|
||||||
|
|
||||||
|
import reactor.bus.selector.Selectors;
|
||||||
|
import reactor.io.buffer.Buffer;
|
||||||
|
import reactor.io.net.NetStreams;
|
||||||
|
|
||||||
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.util.Assert;
|
import org.springframework.util.Assert;
|
||||||
import reactor.bus.selector.Selectors;
|
|
||||||
import reactor.io.buffer.Buffer;
|
|
||||||
import reactor.io.net.NetStreams;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Stephane Maldini
|
* @author Stephane Maldini
|
||||||
*/
|
*/
|
||||||
public class ReactorHttpServer extends HttpServerSupport implements InitializingBean, HttpServer {
|
public class ReactorHttpServer extends HttpServerSupport
|
||||||
|
implements InitializingBean, HttpServer {
|
||||||
|
|
||||||
private RequestHandlerAdapter reactorHandler;
|
private RequestHandlerAdapter reactorHandler;
|
||||||
|
|
||||||
|
@ -35,29 +37,27 @@ public class ReactorHttpServer extends HttpServerSupport implements Initializing
|
||||||
|
|
||||||
private boolean running;
|
private boolean running;
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isRunning() {
|
public boolean isRunning() {
|
||||||
return this.running;
|
return this.running;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void afterPropertiesSet() throws Exception {
|
public void afterPropertiesSet() throws Exception {
|
||||||
|
|
||||||
Assert.notNull(getHttpHandler());
|
Assert.notNull(getHttpHandler());
|
||||||
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) {
|
||||||
try {
|
try {
|
||||||
this.reactorServer.route(Selectors.matchAll(), this.reactorHandler).start().await();
|
this.reactorServer.route(Selectors.matchAll(), this.reactorHandler)
|
||||||
|
.start().await();
|
||||||
this.running = true;
|
this.running = true;
|
||||||
}
|
}
|
||||||
catch (InterruptedException ex) {
|
catch (InterruptedException ex) {
|
||||||
|
@ -69,13 +69,8 @@ public class ReactorHttpServer extends HttpServerSupport implements Initializing
|
||||||
@Override
|
@Override
|
||||||
public void stop() {
|
public void stop() {
|
||||||
if (this.running) {
|
if (this.running) {
|
||||||
try {
|
this.reactorServer.shutdown();
|
||||||
this.reactorServer.shutdown().await();
|
this.running = false;
|
||||||
this.running = false;
|
|
||||||
}
|
|
||||||
catch (InterruptedException ex) {
|
|
||||||
throw new IllegalStateException(ex);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue