16
16
17
17
package org .springframework .http .server .reactive .bootstrap ;
18
18
19
+ import java .util .concurrent .atomic .AtomicReference ;
20
+
19
21
import reactor .core .Loopback ;
20
22
import reactor .ipc .netty .NettyContext ;
21
23
@@ -31,7 +33,7 @@ public class ReactorHttpServer extends HttpServerSupport implements HttpServer,
31
33
32
34
private reactor .ipc .netty .http .server .HttpServer reactorServer ;
33
35
34
- private NettyContext running ;
36
+ private AtomicReference < NettyContext > nettyContext = new AtomicReference <>() ;
35
37
36
38
37
39
@ Override
@@ -43,42 +45,39 @@ public void afterPropertiesSet() throws Exception {
43
45
Assert .notNull (getHttpHandler ());
44
46
this .reactorHandler = new ReactorHttpHandlerAdapter (getHttpHandler ());
45
47
}
46
- this .reactorServer = reactor .ipc .netty .http .server .HttpServer . create ( getHost (),
47
- getPort ());
48
+ this .reactorServer = reactor .ipc .netty .http .server .HttpServer
49
+ . create ( getHost (), getPort ());
48
50
}
49
51
50
52
51
53
@ Override
52
54
public boolean isRunning () {
53
- NettyContext running = this .running ;
54
- return running != null && running .channel ()
55
- .isActive ();
55
+ NettyContext context = this .nettyContext .get ();
56
+ return (context != null && context .channel ().isActive ());
56
57
}
57
58
58
59
@ Override
59
60
public Object connectedInput () {
60
- return reactorServer ;
61
+ return this . reactorServer ;
61
62
}
62
63
63
64
@ Override
64
65
public Object connectedOutput () {
65
- return reactorServer ;
66
+ return this . reactorServer ;
66
67
}
67
68
68
69
@ Override
69
70
public void start () {
70
- // TODO: should be made thread-safe (compareAndSet..)
71
- if (this .running == null ) {
72
- this .running = this .reactorServer .newHandler (reactorHandler ).block ();
71
+ if (this .nettyContext .get () == null ) {
72
+ this .nettyContext .set (this .reactorServer .newHandler (reactorHandler ).block ());
73
73
}
74
74
}
75
75
76
76
@ Override
77
77
public void stop () {
78
- NettyContext running = this .running ;
79
- if (running != null ) {
80
- this .running = null ;
81
- running .dispose ();
78
+ NettyContext context = this .nettyContext .getAndSet (null );
79
+ if (context != null ) {
80
+ context .dispose ();
82
81
}
83
82
}
84
83
}
0 commit comments