Skip to content

Commit 7edd8ba

Browse files
committed
Polish contribution
1 parent 1ce38e5 commit 7edd8ba

File tree

6 files changed

+24
-89
lines changed

6 files changed

+24
-89
lines changed

spring-boot-admin-server/src/main/java/de/codecentric/boot/admin/server/notify/NotificationTrigger.java

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2014-2018 the original author or authors.
2+
* Copyright 2014-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -27,32 +27,16 @@
2727

2828
public class NotificationTrigger extends AbstractEventHandler<InstanceEvent> {
2929
private final Notifier notifier;
30-
private Scheduler scheduler;
3130

3231
public NotificationTrigger(Notifier notifier, Publisher<InstanceEvent> publisher) {
3332
super(publisher, InstanceEvent.class);
3433
this.notifier = notifier;
3534
}
3635

37-
@Override
38-
public void start() {
39-
assert scheduler == null;
40-
scheduler = Schedulers.newSingle("notifications");
41-
super.start();
42-
}
43-
44-
@Override
45-
public void stop() {
46-
super.stop();
47-
if (scheduler != null) {
48-
scheduler.dispose();
49-
scheduler = null;
50-
}
51-
}
52-
5336
@Override
5437
protected Publisher<Void> handle(Flux<InstanceEvent> publisher) {
55-
return publisher.subscribeOn(scheduler).flatMap(this::sendNotifications);
38+
Scheduler scheduler = Schedulers.newSingle("notifications");
39+
return publisher.subscribeOn(scheduler).flatMap(this::sendNotifications).doFinally(s -> scheduler.dispose());
5640
}
5741

5842
protected Mono<Void> sendNotifications(InstanceEvent event) {

spring-boot-admin-server/src/main/java/de/codecentric/boot/admin/server/notify/RemindingNotifier.java

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2014-2018 the original author or authors.
2+
* Copyright 2014-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -52,7 +52,6 @@ public class RemindingNotifier extends AbstractEventNotifier {
5252
private String[] reminderStatuses = {"DOWN", "OFFLINE"};
5353
@Nullable
5454
private Disposable subscription;
55-
private Scheduler scheduler;
5655

5756
public RemindingNotifier(Notifier delegate, InstanceRepository repository) {
5857
super(repository);
@@ -72,16 +71,15 @@ public Mono<Void> doNotify(InstanceEvent event, Instance instance) {
7271
}
7372

7473
public void start() {
75-
assert scheduler == null;
76-
scheduler = Schedulers.newSingle("reminders");
74+
Scheduler scheduler = Schedulers.newSingle("reminders");
7775
this.subscription = Flux.interval(this.checkReminderInverval, scheduler)
7876
.log(log.getName(), Level.FINEST)
7977
.doOnSubscribe(s -> log.debug("Started reminders"))
8078
.flatMap(i -> this.sendReminders())
8179
.onErrorContinue((ex, value) -> log.warn(
8280
"Unexpected error while sending reminders",
8381
ex
84-
))
82+
)).doFinally(s -> scheduler.dispose())
8583
.subscribe();
8684
}
8785

@@ -90,10 +88,6 @@ public void stop() {
9088
log.debug("stopped reminders");
9189
this.subscription.dispose();
9290
}
93-
if (scheduler != null) {
94-
scheduler.dispose();
95-
scheduler = null;
96-
}
9791
}
9892

9993
protected Mono<Void> sendReminders() {

spring-boot-admin-server/src/main/java/de/codecentric/boot/admin/server/services/AbstractEventHandler.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2014-2018 the original author or authors.
2+
* Copyright 2014-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -43,8 +43,7 @@ public void start() {
4343
.log(log.getName(), Level.FINEST)
4444
.doOnSubscribe(s -> log.debug("Subscribed to {} events", eventType))
4545
.ofType(eventType)
46-
.cast(eventType)
47-
.compose(this::handle)
46+
.cast(eventType).transform(this::handle)
4847
.onErrorContinue((ex, value) -> log.warn("Unexpected error while handling {}", value, ex))
4948
.subscribe();
5049
}

spring-boot-admin-server/src/main/java/de/codecentric/boot/admin/server/services/EndpointDetectionTrigger.java

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2014-2018 the original author or authors.
2+
* Copyright 2014-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -28,35 +28,20 @@
2828

2929
public class EndpointDetectionTrigger extends AbstractEventHandler<InstanceEvent> {
3030
private final EndpointDetector endpointDetector;
31-
private Scheduler scheduler;
3231

3332
public EndpointDetectionTrigger(EndpointDetector endpointDetector, Publisher<InstanceEvent> publisher) {
3433
super(publisher, InstanceEvent.class);
3534
this.endpointDetector = endpointDetector;
3635
}
3736

38-
@Override
39-
public void start() {
40-
assert scheduler == null;
41-
scheduler = Schedulers.newSingle("endpoint-detector");
42-
super.start();
43-
}
44-
45-
@Override
46-
public void stop() {
47-
super.stop();
48-
if (scheduler != null) {
49-
scheduler.dispose();
50-
scheduler = null;
51-
}
52-
}
53-
5437
@Override
5538
protected Publisher<Void> handle(Flux<InstanceEvent> publisher) {
39+
Scheduler scheduler = Schedulers.newSingle("endpoint-detector");
5640
return publisher.subscribeOn(scheduler)
5741
.filter(event -> event instanceof InstanceStatusChangedEvent ||
5842
event instanceof InstanceRegistrationUpdatedEvent)
59-
.flatMap(this::detectEndpoints);
43+
.flatMap(this::detectEndpoints)
44+
.doFinally(s -> scheduler.dispose());
6045
}
6146

6247
protected Mono<Void> detectEndpoints(InstanceEvent event) {

spring-boot-admin-server/src/main/java/de/codecentric/boot/admin/server/services/InfoUpdateTrigger.java

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2014-2018 the original author or authors.
2+
* Copyright 2014-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -29,36 +29,21 @@
2929

3030
public class InfoUpdateTrigger extends AbstractEventHandler<InstanceEvent> {
3131
private final InfoUpdater infoUpdater;
32-
private Scheduler scheduler;
3332

3433
public InfoUpdateTrigger(InfoUpdater infoUpdater, Publisher<InstanceEvent> publisher) {
3534
super(publisher, InstanceEvent.class);
3635
this.infoUpdater = infoUpdater;
3736
}
3837

39-
@Override
40-
public void start() {
41-
assert scheduler == null;
42-
scheduler = Schedulers.newSingle("info-updater");
43-
super.start();
44-
}
45-
46-
@Override
47-
public void stop() {
48-
super.stop();
49-
if (scheduler != null) {
50-
scheduler.dispose();
51-
scheduler = null;
52-
}
53-
}
54-
5538
@Override
5639
protected Publisher<Void> handle(Flux<InstanceEvent> publisher) {
40+
Scheduler scheduler = Schedulers.newSingle("info-updater");
5741
return publisher.subscribeOn(scheduler)
5842
.filter(event -> event instanceof InstanceEndpointsDetectedEvent ||
5943
event instanceof InstanceStatusChangedEvent ||
6044
event instanceof InstanceRegistrationUpdatedEvent)
61-
.flatMap(this::updateInfo);
45+
.flatMap(this::updateInfo)
46+
.doFinally(s -> scheduler.dispose());
6247
}
6348

6449
protected Mono<Void> updateInfo(InstanceEvent event) {

spring-boot-admin-server/src/main/java/de/codecentric/boot/admin/server/services/StatusUpdateTrigger.java

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2014-2018 the original author or authors.
2+
* Copyright 2014-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -44,8 +44,6 @@ public class StatusUpdateTrigger extends AbstractEventHandler<InstanceEvent> {
4444
private Duration statusLifetime = Duration.ofSeconds(10);
4545
@Nullable
4646
private Disposable intervalSubscription;
47-
private Scheduler statusMonitorScheduler;
48-
private Scheduler statusUpdaterScheduler;
4947

5048
public StatusUpdateTrigger(StatusUpdater statusUpdater, Publisher<InstanceEvent> publisher) {
5149
super(publisher, InstanceEvent.class);
@@ -54,28 +52,26 @@ public StatusUpdateTrigger(StatusUpdater statusUpdater, Publisher<InstanceEvent>
5452

5553
@Override
5654
public void start() {
57-
assert statusMonitorScheduler == null;
58-
statusMonitorScheduler = Schedulers.newSingle("status-monitor");
59-
assert statusUpdaterScheduler == null;
60-
statusUpdaterScheduler = Schedulers.newSingle("status-updater");
6155
super.start();
56+
Scheduler scheduler = Schedulers.newSingle("status-monitor");
6257
intervalSubscription = Flux.interval(updateInterval)
6358
.doOnSubscribe(s -> log.debug("Scheduled status update every {}", updateInterval))
64-
.log(log.getName(), Level.FINEST)
65-
.subscribeOn(statusMonitorScheduler)
59+
.log(log.getName(), Level.FINEST).subscribeOn(scheduler)
6660
.concatMap(i -> this.updateStatusForAllInstances())
6761
.onErrorContinue((ex, value) -> log.warn("Unexpected error while updating statuses",
6862
ex
69-
))
63+
)).doFinally(s -> scheduler.dispose())
7064
.subscribe();
7165
}
7266

7367
@Override
7468
protected Publisher<Void> handle(Flux<InstanceEvent> publisher) {
75-
return publisher.subscribeOn(statusUpdaterScheduler)
69+
Scheduler scheduler = Schedulers.newSingle("status-updater");
70+
return publisher.subscribeOn(scheduler)
7671
.filter(event -> event instanceof InstanceRegisteredEvent ||
7772
event instanceof InstanceRegistrationUpdatedEvent)
78-
.flatMap(event -> updateStatus(event.getInstance()));
73+
.flatMap(event -> updateStatus(event.getInstance()))
74+
.doFinally(s -> scheduler.dispose());
7975
}
8076

8177
@Override
@@ -84,14 +80,6 @@ public void stop() {
8480
if (intervalSubscription != null) {
8581
intervalSubscription.dispose();
8682
}
87-
if (statusUpdaterScheduler != null) {
88-
statusUpdaterScheduler.dispose();
89-
statusUpdaterScheduler = null;
90-
}
91-
if (statusMonitorScheduler != null) {
92-
statusMonitorScheduler.dispose();
93-
statusMonitorScheduler = null;
94-
}
9583
}
9684

9785
protected Mono<Void> updateStatusForAllInstances() {

0 commit comments

Comments
 (0)