001/* 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, software 013 * distributed under the License is distributed on an "AS IS" BASIS, 014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 015 * See the License for the specific language governing permissions and 016 * limitations under the License. 017 */ 018 019package org.apache.hadoop.metrics.spi; 020 021import org.apache.hadoop.classification.InterfaceAudience; 022import org.apache.hadoop.classification.InterfaceStability; 023import org.apache.hadoop.metrics.ContextFactory; 024import org.apache.hadoop.metrics.MetricsException; 025 026/** 027 * A null context which has a thread calling 028 * periodically when monitoring is started. This keeps the data sampled 029 * correctly. 030 * In all other respects, this is like the NULL context: No data is emitted. 031 * This is suitable for Monitoring systems like JMX which reads the metrics 032 * when someone reads the data from JMX. 033 * 034 * The default impl of start and stop monitoring: 035 * is the AbstractMetricsContext is good enough. 036 * 037 */ 038@InterfaceAudience.Public 039@InterfaceStability.Evolving 040public class NullContextWithUpdateThread extends AbstractMetricsContext { 041 042 private static final String PERIOD_PROPERTY = "period"; 043 044 /** Creates a new instance of NullContextWithUpdateThread */ 045 @InterfaceAudience.Private 046 public NullContextWithUpdateThread() { 047 } 048 049 @InterfaceAudience.Private 050 public void init(String contextName, ContextFactory factory) { 051 super.init(contextName, factory); 052 parseAndSetPeriod(PERIOD_PROPERTY); 053 } 054 055 056 /** 057 * Do-nothing version of emitRecord 058 */ 059 @InterfaceAudience.Private 060 protected void emitRecord(String contextName, String recordName, 061 OutputRecord outRec) 062 {} 063 064 /** 065 * Do-nothing version of update 066 */ 067 @InterfaceAudience.Private 068 protected void update(MetricsRecordImpl record) { 069 } 070 071 /** 072 * Do-nothing version of remove 073 */ 074 @InterfaceAudience.Private 075 protected void remove(MetricsRecordImpl record) { 076 } 077}