1
1
/*
2
- * Copyright 2012-2015 the original author or authors.
2
+ * Copyright 2012-2016 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
27
27
* @author Tyler J. Frederick
28
28
* @author Phillip Webb
29
29
* @author Christian Dupuis
30
+ * @author Vedran Pavic
30
31
* @since 1.1.0
31
32
*/
32
33
public class CompositeHealthIndicator implements HealthIndicator {
@@ -35,6 +36,8 @@ public class CompositeHealthIndicator implements HealthIndicator {
35
36
36
37
private final HealthAggregator healthAggregator ;
37
38
39
+ private final HealthIndicatorRunner healthIndicatorRunner ;
40
+
38
41
/**
39
42
* Create a new {@link CompositeHealthIndicator}.
40
43
* @param healthAggregator the health aggregator
@@ -51,10 +54,35 @@ public CompositeHealthIndicator(HealthAggregator healthAggregator) {
51
54
*/
52
55
public CompositeHealthIndicator (HealthAggregator healthAggregator ,
53
56
Map <String , HealthIndicator > indicators ) {
57
+ this (healthAggregator , indicators , new SimpleHealthIndicatorRunner ());
58
+ }
59
+ /**
60
+ * Create a new {@link CompositeHealthIndicator}.
61
+ * @param healthAggregator the health aggregator
62
+ * @param healthIndicatorRunner the health indicator runner
63
+ */
64
+ public CompositeHealthIndicator (HealthAggregator healthAggregator ,
65
+ HealthIndicatorRunner healthIndicatorRunner ) {
66
+ this (healthAggregator , new LinkedHashMap <String , HealthIndicator >(),
67
+ healthIndicatorRunner );
68
+ }
69
+
70
+ /**
71
+ * Create a new {@link CompositeHealthIndicator} from the specified indicators.
72
+ * @param healthAggregator the health aggregator
73
+ * @param indicators a map of {@link HealthIndicator}s with the key being used as an
74
+ * indicator name.
75
+ * @param healthIndicatorRunner the health indicator runner
76
+ */
77
+ public CompositeHealthIndicator (HealthAggregator healthAggregator ,
78
+ Map <String , HealthIndicator > indicators ,
79
+ HealthIndicatorRunner healthIndicatorRunner ) {
54
80
Assert .notNull (healthAggregator , "HealthAggregator must not be null" );
55
81
Assert .notNull (indicators , "Indicators must not be null" );
82
+ Assert .notNull (healthIndicatorRunner , "HealthIndicatorRunner must not be null" );
56
83
this .indicators = new LinkedHashMap <String , HealthIndicator >(indicators );
57
84
this .healthAggregator = healthAggregator ;
85
+ this .healthIndicatorRunner = healthIndicatorRunner ;
58
86
}
59
87
60
88
public void addHealthIndicator (String name , HealthIndicator indicator ) {
@@ -63,11 +91,24 @@ public void addHealthIndicator(String name, HealthIndicator indicator) {
63
91
64
92
@ Override
65
93
public Health health () {
66
- Map <String , Health > healths = new LinkedHashMap <String , Health >();
67
- for (Map .Entry <String , HealthIndicator > entry : this .indicators .entrySet ()) {
68
- healths .put (entry .getKey (), entry .getValue ().health ());
69
- }
94
+ Map <String , Health > healths = this .healthIndicatorRunner .run (this .indicators );
70
95
return this .healthAggregator .aggregate (healths );
71
96
}
72
97
98
+ /**
99
+ * {@link HealthIndicatorRunner} for sequential execution of {@link HealthIndicator}s.
100
+ */
101
+ private static class SimpleHealthIndicatorRunner implements HealthIndicatorRunner {
102
+
103
+ @ Override
104
+ public Map <String , Health > run (Map <String , HealthIndicator > healthIndicators ) {
105
+ Map <String , Health > healths = new LinkedHashMap <String , Health >();
106
+ for (Map .Entry <String , HealthIndicator > entry : healthIndicators .entrySet ()) {
107
+ healths .put (entry .getKey (), entry .getValue ().health ());
108
+ }
109
+ return healths ;
110
+ }
111
+
112
+ }
113
+
73
114
}
0 commit comments