File tree Expand file tree Collapse file tree 7 files changed +47
-15
lines changed
spring-boot-admin-server/src
main/java/de/codecentric/boot/admin/notify
test/java/de/codecentric/boot/admin/notify Expand file tree Collapse file tree 7 files changed +47
-15
lines changed Original file line number Diff line number Diff line change @@ -44,7 +44,9 @@ public void notify(ClientApplicationEvent event) {
4444}
4545
4646
47- protected abstract boolean shouldNotify (ClientApplicationEvent event );
47+ protected boolean shouldNotify (ClientApplicationEvent event ) {
48+ return true ;
49+ }
4850
4951protected abstract void doNotify (ClientApplicationEvent event ) throws Exception ;
5052
Original file line number Diff line number Diff line change 1515 */
1616package de .codecentric .boot .admin .notify ;
1717
18+ import org .springframework .util .Assert ;
19+
1820import de .codecentric .boot .admin .event .ClientApplicationEvent ;
1921
2022/**
2123 * A notifier delegating notifications to all specified notifiers.
2224 *
2325 * @author Sebastian Meiser
2426 */
25- public class CompositeNotifier implements Notifier {
26- private final Iterable <Notifier > notifiers ;
27+ public class CompositeNotifier extends AbstractEventNotifier {
28+ private final Iterable <Notifier > delegates ;
2729
28- public CompositeNotifier (Iterable <Notifier > notifiers ) {
29- this .notifiers = notifiers ;
30+ public CompositeNotifier (Iterable <Notifier > delegates ) {
31+ Assert .notNull (delegates , "'delegates' must not be null!" );
32+ this .delegates = delegates ;
3033}
3134
3235@ Override
33- public void notify (ClientApplicationEvent event ) {
34- for (Notifier notifier : notifiers ) {
36+ public void doNotify (ClientApplicationEvent event ) {
37+ for (Notifier notifier : delegates ) {
3538notifier .notify (event );
3639}
3740}
Original file line number Diff line number Diff line change 2020import java .util .concurrent .ConcurrentHashMap ;
2121import java .util .concurrent .TimeUnit ;
2222
23+ import org .springframework .util .Assert ;
24+
2325import de .codecentric .boot .admin .event .ClientApplicationDeregisteredEvent ;
2426import de .codecentric .boot .admin .event .ClientApplicationEvent ;
2527import de .codecentric .boot .admin .event .ClientApplicationStatusChangedEvent ;
2931 *
3032 * @author Johannes Edmeier
3133 */
32- public class RemindingNotifier implements Notifier {
34+ public class RemindingNotifier extends AbstractEventNotifier {
3335private final ConcurrentHashMap <String , Reminder > reminders = new ConcurrentHashMap <>();
3436private long reminderPeriod = TimeUnit .MINUTES .toMillis (10L );
3537private String [] reminderStatuses = { "DOWN" , "OFFLINE" };
3638private final Notifier delegate ;
3739
3840public RemindingNotifier (Notifier delegate ) {
41+ Assert .notNull (delegate , "'delegate' must not be null!" );
3942this .delegate = delegate ;
4043}
4144
4245@ Override
43- public void notify (ClientApplicationEvent event ) {
46+ public void doNotify (ClientApplicationEvent event ) {
4447delegate .notify (event );
4548if (shouldEndReminder (event )) {
4649reminders .remove (event .getApplication ().getId ());
Original file line number Diff line number Diff line change 2525
2626import org .slf4j .Logger ;
2727import org .slf4j .LoggerFactory ;
28+ import org .springframework .util .Assert ;
2829
2930import de .codecentric .boot .admin .event .ClientApplicationEvent ;
31+ import de .codecentric .boot .admin .notify .AbstractEventNotifier ;
3032import de .codecentric .boot .admin .notify .Notifier ;
3133
3234/**
3335 * Notifier that allows to filter certain events based on policies.
3436 *
3537 * @author Johannes Edmeier
3638 */
37- public class FilteringNotifier implements Notifier {
39+ public class FilteringNotifier extends AbstractEventNotifier {
3840private static final Logger LOGGER = LoggerFactory .getLogger (FilteringNotifier .class );
3941private final ConcurrentMap <String , NotificationFilter > filters = new ConcurrentHashMap <>();
4042private final Notifier delegate ;
@@ -43,11 +45,17 @@ public class FilteringNotifier implements Notifier {
4345private AtomicLong counter = new AtomicLong ();
4446
4547public FilteringNotifier (Notifier delegate ) {
48+ Assert .notNull (delegate , "'delegate' must not be null!" );
4649this .delegate = delegate ;
4750}
4851
4952@ Override
50- public void notify (ClientApplicationEvent event ) {
53+ protected boolean shouldNotify (ClientApplicationEvent event ) {
54+ return !filter (event );
55+ }
56+
57+ @ Override
58+ public void doNotify (ClientApplicationEvent event ) {
5159if (!filter (event )) {
5260delegate .notify (event );
5361}
Original file line number Diff line number Diff line change 44import static org .junit .Assert .assertThat ;
55
66import java .util .Arrays ;
7+ import java .util .Collections ;
78
89import org .junit .Test ;
910
@@ -19,6 +20,10 @@ public class CompositeNotifierTest {
1920.withStatusInfo (StatusInfo .ofDown ()).build (),
2021StatusInfo .ofUp (), StatusInfo .ofDown ());
2122
23+ @ Test (expected = IllegalArgumentException .class )
24+ public void test_ctor_assert () {
25+ new CompositeNotifier (null );
26+ }
2227
2328@ Test
2429public void test_all_notifiers_get_notified () throws Exception {
@@ -28,7 +33,7 @@ public void test_all_notifiers_get_notified() throws Exception {
2833
2934compositeNotifier .notify (APP_DOWN );
3035
31- assertThat (notifier1 .getEvents (), is (Arrays . asList (APP_DOWN )));
32- assertThat (notifier2 .getEvents (), is (Arrays . asList (APP_DOWN )));
36+ assertThat (notifier1 .getEvents (), is (Collections . singletonList (APP_DOWN )));
37+ assertThat (notifier2 .getEvents (), is (Collections . singletonList (APP_DOWN )));
3338}
3439}
Original file line number Diff line number Diff line change 44import static org .junit .Assert .assertThat ;
55
66import java .util .Arrays ;
7+ import java .util .Collections ;
78
89import org .junit .Test ;
910
@@ -29,6 +30,11 @@ public class RemindingNotifierTest {
2930.withStatusInfo (StatusInfo .ofUp ()).build (),
3031StatusInfo .ofDown (), StatusInfo .ofUp ());
3132
33+ @ Test (expected = IllegalArgumentException .class )
34+ public void test_ctor_assert () {
35+ new CompositeNotifier (null );
36+ }
37+
3238@ Test
3339public void test_remind () throws Exception {
3440TestNotifier notifier = new TestNotifier ();
@@ -67,7 +73,7 @@ public void test_no_remind_before_end() throws Exception {
6773reminder .notify (APP_DOWN );
6874reminder .sendReminders ();
6975
70- assertThat (notifier .getEvents (), is (Arrays . asList (APP_DOWN )));
76+ assertThat (notifier .getEvents (), is (Collections . singletonList (APP_DOWN )));
7177}
7278
7379}
Original file line number Diff line number Diff line change 11package de .codecentric .boot .admin .notify .filter ;
22
3+ import static org .junit .Assert .assertThat ;
34import static org .hamcrest .Matchers .hasItem ;
45import static org .hamcrest .Matchers .hasKey ;
56import static org .hamcrest .Matchers .not ;
6- import static org .junit .Assert .assertThat ;
77
88import org .junit .Test ;
99
@@ -17,6 +17,11 @@ public class FilteringNotifierTest {
1717private static final ClientApplicationRegisteredEvent EVENT = new ClientApplicationRegisteredEvent (
1818Application .create ("foo" ).withHealthUrl ("http://health" ).build ());
1919
20+ @ Test (expected = IllegalArgumentException .class )
21+ public void test_ctor_assert () {
22+ new FilteringNotifier (null );
23+ }
24+
2025@ Test
2126public void test_expired_removal () {
2227FilteringNotifier notifier = new FilteringNotifier (new TestNotifier ());
You can’t perform that action at this time.
0 commit comments