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    
019    package org.apache.hadoop.metrics.spi;
020    
021    import org.apache.hadoop.classification.InterfaceAudience;
022    import org.apache.hadoop.classification.InterfaceStability;
023    import 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
039    public 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      @InterfaceAudience.Private
049      public void init(String contextName, ContextFactory factory) {
050        super.init(contextName, factory);
051        parseAndSetPeriod(PERIOD_PROPERTY);
052      }
053       
054        
055      /**
056       * Do-nothing version of emitRecord
057       */
058      @InterfaceAudience.Private
059      protected void emitRecord(String contextName, String recordName,
060                                OutputRecord outRec) 
061      {}
062        
063      /**
064       * Do-nothing version of update
065       */
066      @InterfaceAudience.Private
067      protected void update(MetricsRecordImpl record) {
068      }
069        
070      /**
071       * Do-nothing version of remove
072       */
073      @InterfaceAudience.Private
074      protected void remove(MetricsRecordImpl record) {
075      }
076    }