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; 024 025/** 026 * A null context which has a thread calling 027 * periodically when monitoring is started. This keeps the data sampled 028 * correctly. 029 * In all other respects, this is like the NULL context: No data is emitted. 030 * This is suitable for Monitoring systems like JMX which reads the metrics 031 * when someone reads the data from JMX. 032 * 033 * The default impl of start and stop monitoring: 034 * is the AbstractMetricsContext is good enough. 035 * 036 */ 037@InterfaceAudience.Public 038@InterfaceStability.Evolving 039public class NullContextWithUpdateThread extends AbstractMetricsContext { 040 041 private static final String PERIOD_PROPERTY = "period"; 042 043 /** Creates a new instance of NullContextWithUpdateThread */ 044 @InterfaceAudience.Private 045 public NullContextWithUpdateThread() { 046 } 047 048 @Override 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 @Override 060 @InterfaceAudience.Private 061 protected void emitRecord(String contextName, String recordName, 062 OutputRecord outRec) 063 {} 064 065 /** 066 * Do-nothing version of update 067 */ 068 @Override 069 @InterfaceAudience.Private 070 protected void update(MetricsRecordImpl record) { 071 } 072 073 /** 074 * Do-nothing version of remove 075 */ 076 @Override 077 @InterfaceAudience.Private 078 protected void remove(MetricsRecordImpl record) { 079 } 080}