/** * Get the singleton {@link RootMetricContext}. * @return singleton instance of {@link RootMetricContext}. */ public synchronized static RootMetricContext get() { return get(Lists.<Tag<?>>newArrayList()); }
@Test public void testReporterCanBeAddedToStartedContext() throws Exception { RootMetricContext.get().startReporting(); ContextStoreReporter reporter = new ContextStoreReporter("testReporter", ConfigFactory.empty()); Assert.assertTrue(reporter.isStarted()); RootMetricContext.get().stopReporting(); }
public ContextAwareReporter(String name, Config config) { this.name = name; this.config = config; this.started = false; RootMetricContext.get().addNewReporter(this); this.notificationTargetUUID = RootMetricContext.get().addNotificationTarget(new Function<Notification, Void>() { @Nullable @Override public Void apply(Notification input) { notificationCallback(input); return null; } }); this.contextFilter = ContextFilterFactory.createContextFilter(config); this.contextsToReport = Sets.newConcurrentHashSet(); for (MetricContext context : this.contextFilter.getMatchingContexts()) { this.contextsToReport.add(context.getInnerMetricContext()); } }
/** * Removes {@link ContextAwareReporter} records from the {@link RootMetricContext}. * This method should be considered irreversible and destructive to the {@link ContextAwareReporter}. * @throws IOException */ @Override public void close() throws IOException { RootMetricContext.get().removeNotificationTarget(this.notificationTargetUUID); RootMetricContext.get().removeReporter(this); }
public ContextWeakReference(MetricContext referent, InnerMetricContext innerContext) { super(referent, RootMetricContext.get().getReferenceQueue()); this.innerContext = innerContext; }
@Override public void run() { stopReporting(); try { close(); } catch (IOException e) { log.warn("Unable to close " + this.getClass().getCanonicalName(), e); } } });
RootMetricContext.get().startReporting();
RootMetricContext.get().stopReporting();
RootMetricContext.get().addNotificationTarget(store); Assert.assertTrue(RootMetricContext.get().getChildContextsAsMap().containsKey(name)); Assert.assertEquals(RootMetricContext.get().getChildContextsAsMap().get(name), metricContext); ensureGarbageCollected(innerMetricContextWeakReference); RootMetricContext.get().removeReporter(reporter);
protected MetricContext(String name, MetricContext parent, List<Tag<?>> tags, boolean isRoot) throws NameConflictException { Preconditions.checkArgument(!Strings.isNullOrEmpty(name)); this.closer = Closer.create(); try { this.innerMetricContext = this.closer.register(new InnerMetricContext(this, name, parent, tags)); } catch(ExecutionException ee) { throw Throwables.propagate(ee); } this.contextAwareMetricsSet = Sets.newConcurrentHashSet(); this.notificationTargets = Maps.newConcurrentMap(); this.executorServiceOptional = Optional.absent(); this.notificationTimer = new ContextAwareTimer(this, GOBBLIN_METRICS_NOTIFICATIONS_TIMER_NAME); register(this.notificationTimer); if (!isRoot) { RootMetricContext.get().addMetricContext(this); } }
@BeforeMethod public void setUp() throws Exception { System.gc(); RootMetricContext.get().clearNotificationTargets(); }
private static void initialize(List<Tag<?>> tags) { try { INSTANCE = new RootMetricContext(tags); } catch (NameConflictException nce) { // Should never happen, as there is no parent, so no conflict. throw new IllegalStateException("Failed to generate root metric context. This is an error in the code.", nce); } }
RootMetricContext.get().startReporting();
/** * Removes {@link ContextAwareReporter} records from the {@link RootMetricContext}. * This method should be considered irreversible and destructive to the {@link ContextAwareReporter}. * @throws IOException */ @Override public void close() throws IOException { RootMetricContext.get().removeNotificationTarget(this.notificationTargetUUID); RootMetricContext.get().removeReporter(this); }
RootMetricContext.get().stopReporting();
public ContextWeakReference(MetricContext referent, InnerMetricContext innerContext) { super(referent, RootMetricContext.get().getReferenceQueue()); this.innerContext = innerContext; }
protected MetricContext(String name, MetricContext parent, List<Tag<?>> tags, boolean isRoot) throws NameConflictException { Preconditions.checkArgument(!Strings.isNullOrEmpty(name)); this.closer = Closer.create(); try { this.innerMetricContext = this.closer.register(new InnerMetricContext(this, name, parent, tags)); } catch(ExecutionException ee) { throw Throwables.propagate(ee); } this.contextAwareMetricsSet = Sets.newConcurrentHashSet(); this.notificationTargets = Maps.newConcurrentMap(); this.executorServiceOptional = Optional.absent(); this.notificationTimer = new ContextAwareTimer(this, GOBBLIN_METRICS_NOTIFICATIONS_TIMER_NAME); register(this.notificationTimer); if (!isRoot) { RootMetricContext.get().addMetricContext(this); } }
@AfterMethod public void tearDown() throws Exception { CACHE.invalidateAll(); System.gc(); RootMetricContext.get().clearNotificationTargets(); }
@Override public void run() { stopReporting(); try { close(); } catch (IOException e) { log.warn("Unable to close " + this.getClass().getCanonicalName(), e); } } });