1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.hadoop.metrics2.impl;
20
21 import java.util.concurrent.ScheduledFuture;
22 import java.util.concurrent.TimeUnit;
23
24 import org.apache.commons.logging.Log;
25 import org.apache.commons.logging.LogFactory;
26 import org.apache.hadoop.hbase.classification.InterfaceAudience;
27 import org.apache.hadoop.metrics2.MetricsExecutor;
28 import org.apache.hadoop.metrics2.lib.DefaultMetricsSystem;
29 import org.apache.hadoop.metrics2.lib.MetricsExecutorImpl;
30
31
32
33
34
35
36
37
38
39 @edu.umd.cs.findbugs.annotations.SuppressWarnings(
40 value="LI_LAZY_INIT_STATIC",
41 justification="Yeah, its weird but its what we want")
42 @InterfaceAudience.Private
43 public class JmxCacheBuster {
44 private static final Log LOG = LogFactory.getLog(JmxCacheBuster.class);
45 private static Object lock = new Object();
46 private static ScheduledFuture fut = null;
47 private static MetricsExecutor executor = new MetricsExecutorImpl();
48
49
50
51
52 public static void clearJmxCache() {
53
54
55 synchronized (lock) {
56 if (fut == null || (!fut.isDone() && fut.getDelay(TimeUnit.MILLISECONDS) > 100)) return;
57 fut = executor.getExecutor().schedule(new JmxCacheBusterRunnable(), 5, TimeUnit.SECONDS);
58 }
59 }
60
61 static class JmxCacheBusterRunnable implements Runnable {
62
63 @Override
64 public void run() {
65 LOG.trace("Clearing JMX mbean cache.");
66
67
68
69 try {
70 if (DefaultMetricsSystem.instance() != null ) {
71 DefaultMetricsSystem.instance().stop();
72 DefaultMetricsSystem.instance().start();
73 }
74
75 } catch (Exception exception ) {
76 LOG.debug("error clearing the jmx it appears the metrics system hasn't been started", exception);
77 }
78 }
79 }
80 }