HADOOP-10839. Add unregisterSource() to MetricsSystem API. Contributed by Shanyu Zhao.
git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1611134 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
40e1bb9d31
commit
7f357d68cc
|
@ -409,6 +409,9 @@ Release 2.6.0 - UNRELEASED
|
|||
HADOOP-10845. Add common tests for ACLs in combination with viewfs.
|
||||
(Stephen Chu via cnauroth)
|
||||
|
||||
HADOOP-10839. Add unregisterSource() to MetricsSystem API.
|
||||
(Shanyu Zhao via cnauroth)
|
||||
|
||||
OPTIMIZATIONS
|
||||
|
||||
BUG FIXES
|
||||
|
|
|
@ -54,6 +54,12 @@ public abstract class MetricsSystem implements MetricsSystemMXBean {
|
|||
*/
|
||||
public abstract <T> T register(String name, String desc, T source);
|
||||
|
||||
/**
|
||||
* Unregister a metrics source
|
||||
* @param name of the source. This is the name you use to call register()
|
||||
*/
|
||||
public abstract void unregisterSource(String name);
|
||||
|
||||
/**
|
||||
* Register a metrics source (deriving name and description from the object)
|
||||
* @param <T> the actual type of the source object
|
||||
|
|
|
@ -232,6 +232,17 @@ public class MetricsSystemImpl extends MetricsSystem implements MetricsSource {
|
|||
return source;
|
||||
}
|
||||
|
||||
@Override public synchronized
|
||||
void unregisterSource(String name) {
|
||||
if (sources.containsKey(name)) {
|
||||
sources.get(name).stop();
|
||||
sources.remove(name);
|
||||
}
|
||||
if (allSources.containsKey(name)) {
|
||||
allSources.remove(name);
|
||||
}
|
||||
}
|
||||
|
||||
synchronized
|
||||
void registerSource(String name, String desc, MetricsSource source) {
|
||||
checkNotNull(config, "config");
|
||||
|
|
|
@ -380,6 +380,23 @@ public class TestMetricsSystemImpl {
|
|||
ms.shutdown();
|
||||
}
|
||||
|
||||
@Test public void testUnregisterSource() {
|
||||
MetricsSystem ms = new MetricsSystemImpl();
|
||||
TestSource ts1 = new TestSource("ts1");
|
||||
TestSource ts2 = new TestSource("ts2");
|
||||
ms.register("ts1", "", ts1);
|
||||
ms.register("ts2", "", ts2);
|
||||
MetricsSource s1 = ms.getSource("ts1");
|
||||
assertNotNull(s1);
|
||||
// should work when metrics system is not started
|
||||
ms.unregisterSource("ts1");
|
||||
s1 = ms.getSource("ts1");
|
||||
assertNull(s1);
|
||||
MetricsSource s2 = ms.getSource("ts2");
|
||||
assertNotNull(s2);
|
||||
ms.shutdown();
|
||||
}
|
||||
|
||||
private void checkMetricsRecords(List<MetricsRecord> recs) {
|
||||
LOG.debug(recs);
|
||||
MetricsRecord r = recs.get(0);
|
||||
|
|
Loading…
Reference in New Issue