88import reactor .core .publisher .MonoProcessor ;
99import reactor .core .publisher .UnicastProcessor ;
1010
11- abstract class KeepAliveHandler {
11+ abstract class KeepAliveHandler implements Disposable {
1212 private final KeepAlive keepAlive ;
1313 private final UnicastProcessor <Frame > sent = UnicastProcessor .create ();
1414 private final MonoProcessor <KeepAlive > timeout = MonoProcessor .create ();
15- private final Flux <Long > interval ;
1615 private Disposable intervalDisposable ;
1716 private volatile long lastReceivedMillis ;
1817
@@ -26,20 +25,17 @@ static KeepAliveHandler ofClient(KeepAlive keepAlive) {
2625
2726 private KeepAliveHandler (KeepAlive keepAlive ) {
2827 this .keepAlive = keepAlive ;
29- this .interval = Flux .interval (Duration .ofMillis (keepAlive .getTickPeriod ()));
30- }
31-
32- public void start () {
3328 this .lastReceivedMillis = System .currentTimeMillis ();
34- intervalDisposable = interval .subscribe (v -> onIntervalTick ());
29+ this .intervalDisposable =
30+ Flux .interval (Duration .ofMillis (keepAlive .getTickPeriod ()))
31+ .subscribe (v -> onIntervalTick ());
3532 }
3633
37- public void stop () {
34+ @ Override
35+ public void dispose () {
3836 sent .onComplete ();
3937 timeout .onComplete ();
40- if (intervalDisposable != null ) {
41- intervalDisposable .dispose ();
42- }
38+ intervalDisposable .dispose ();
4339 }
4440
4541 public void receive (Frame keepAliveFrame ) {
0 commit comments