HADOOP-10839. Merging change r1611134 from trunk to branch-2.

git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/branches/branch-2@1611136 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Chris Nauroth 2014-07-16 18:52:41 +00:00
parent 1c2fec20c9
commit 9fa9b91afe
4 changed files with 37 additions and 0 deletions

View File

@ -22,6 +22,9 @@ Release 2.6.0 - UNRELEASED
HADOOP-10845. Add common tests for ACLs in combination with viewfs. HADOOP-10845. Add common tests for ACLs in combination with viewfs.
(Stephen Chu via cnauroth) (Stephen Chu via cnauroth)
HADOOP-10839. Add unregisterSource() to MetricsSystem API.
(Shanyu Zhao via cnauroth)
OPTIMIZATIONS OPTIMIZATIONS
BUG FIXES BUG FIXES

View File

@ -43,6 +43,12 @@ public abstract class MetricsSystem implements MetricsSystemMXBean {
*/ */
public abstract <T> T register(String name, String desc, T source); 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) * Register a metrics source (deriving name and description from the object)
* @param <T> the actual type of the source object * @param <T> the actual type of the source object

View File

@ -232,6 +232,17 @@ public class MetricsSystemImpl extends MetricsSystem implements MetricsSource {
return source; 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 synchronized
void registerSource(String name, String desc, MetricsSource source) { void registerSource(String name, String desc, MetricsSource source) {
checkNotNull(config, "config"); checkNotNull(config, "config");

View File

@ -380,6 +380,23 @@ public class TestMetricsSystemImpl {
ms.shutdown(); 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) { private void checkMetricsRecords(List<MetricsRecord> recs) {
LOG.debug(recs); LOG.debug(recs);
MetricsRecord r = recs.get(0); MetricsRecord r = recs.get(0);