Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This commit introduces HealthIndicatorRegistry which handles registration of HealthIndicator instances. Registering new HealthIndicator instances is now possible in runtime.
- Loading branch information
Showing
9 changed files
with
299 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
...src/main/java/org/springframework/boot/actuate/health/DefaultHealthIndicatorRegistry.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/* | ||
* Copyright 2012-2016 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.springframework.boot.actuate.health; | ||
|
||
import java.util.Collections; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import org.springframework.util.Assert; | ||
|
||
/** | ||
* Default implementation of {@link HealthIndicatorRegistry}. | ||
* | ||
* @author Vedran Pavic | ||
*/ | ||
public class DefaultHealthIndicatorRegistry implements HealthIndicatorRegistry { | ||
|
||
private final Map<String, HealthIndicator> healthIndicators = | ||
new HashMap<String, HealthIndicator>(); | ||
|
||
@Override | ||
public void register(String name, HealthIndicator healthIndicator) { | ||
Assert.notNull(healthIndicator, "HealthIndicator must not be null"); | ||
synchronized (this.healthIndicators) { | ||
if (this.healthIndicators.get(name) != null) { | ||
throw new IllegalStateException( | ||
"HealthIndicator with name '" + name + "' already registered"); | ||
} | ||
this.healthIndicators.put(name, healthIndicator); | ||
} | ||
} | ||
|
||
@Override | ||
public HealthIndicator unregister(String name) { | ||
synchronized (this.healthIndicators) { | ||
return this.healthIndicators.remove(name); | ||
} | ||
} | ||
|
||
@Override | ||
public HealthIndicator get(String name) { | ||
synchronized (this.healthIndicators) { | ||
return this.healthIndicators.get(name); | ||
} | ||
} | ||
|
||
@Override | ||
public Map<String, HealthIndicator> getAll() { | ||
synchronized (this.healthIndicators) { | ||
return Collections.unmodifiableMap( | ||
new HashMap<String, HealthIndicator>(this.healthIndicators)); | ||
} | ||
} | ||
|
||
} |
65 changes: 65 additions & 0 deletions
65
...tuator/src/main/java/org/springframework/boot/actuate/health/HealthIndicatorRegistry.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/* | ||
* Copyright 2012-2016 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.springframework.boot.actuate.health; | ||
|
||
import java.util.Map; | ||
|
||
/** | ||
* A registry of {@link HealthIndicator}s. | ||
* <p> | ||
* Implementations <strong>must</strong> be thread-safe. | ||
* | ||
* @author Andy Wilkinson | ||
* @author Vedran Pavic | ||
*/ | ||
public interface HealthIndicatorRegistry { | ||
|
||
/** | ||
* Registers the given {@code healthIndicator}, associating it with the given | ||
* {@code name}. | ||
* @param name the name of the indicator | ||
* @param healthIndicator the indicator | ||
* @throws IllegalStateException if an indicator with the given {@code name} is | ||
* already registered. | ||
*/ | ||
void register(String name, HealthIndicator healthIndicator); | ||
|
||
/** | ||
* Unregisters the {@code HealthIndicator} previously registered with the given | ||
* {@code name}. | ||
* @param name the name of the indicator | ||
* @return the unregistered indicator, or {@code null} if no indicator was found in | ||
* the registry for the given {@code name}. | ||
*/ | ||
HealthIndicator unregister(String name); | ||
|
||
/** | ||
* Returns the health indicator registered with the given {@code name}. | ||
* @param name the name of the indicator | ||
* @return the health indicator, or {@code null} if no indicator was registered with | ||
* the given {@code name}. | ||
*/ | ||
HealthIndicator get(String name); | ||
|
||
/** | ||
* Returns a snapshot of the registered health indicators and their names. The | ||
* contents of the map do not reflect subsequent changes to the registry. | ||
* @return the snapshot of registered health indicators | ||
*/ | ||
Map<String, HealthIndicator> getAll(); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.