001/*
002 * OutputRecord.java
003 *
004 * Licensed to the Apache Software Foundation (ASF) under one
005 * or more contributor license agreements.  See the NOTICE file
006 * distributed with this work for additional information
007 * regarding copyright ownership.  The ASF licenses this file
008 * to you under the Apache License, Version 2.0 (the
009 * "License"); you may not use this file except in compliance
010 * with the License.  You may obtain a copy of the License at
011 *
012 *     http://www.apache.org/licenses/LICENSE-2.0
013 *
014 * Unless required by applicable law or agreed to in writing, software
015 * distributed under the License is distributed on an "AS IS" BASIS,
016 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017 * See the License for the specific language governing permissions and
018 * limitations under the License.
019 */
020
021package org.apache.hadoop.metrics.spi;
022
023import java.util.Collections;
024import java.util.Map;
025import java.util.Set;
026import java.util.TreeMap;
027import java.util.Map.Entry;
028
029import org.apache.hadoop.classification.InterfaceAudience;
030import org.apache.hadoop.classification.InterfaceStability;
031import org.apache.hadoop.metrics.spi.AbstractMetricsContext.MetricMap;
032import org.apache.hadoop.metrics.spi.AbstractMetricsContext.TagMap;
033
034/**
035 * Represents a record of metric data to be sent to a metrics system.
036 */
037@InterfaceAudience.Public
038@InterfaceStability.Evolving
039public class OutputRecord {
040    
041  private TagMap tagMap;
042  private MetricMap metricMap;
043    
044  /** Creates a new instance of OutputRecord */
045  OutputRecord(TagMap tagMap, MetricMap metricMap) {
046    this.tagMap = tagMap;
047    this.metricMap = metricMap;
048  }
049    
050  /**
051   * Returns the set of tag names
052   */
053  public Set<String> getTagNames() {
054    return Collections.unmodifiableSet(tagMap.keySet());
055  }
056    
057  /**
058   * Returns a tag object which is can be a String, Integer, Short or Byte.
059   *
060   * @return the tag value, or null if there is no such tag
061   */
062  public Object getTag(String name) {
063    return tagMap.get(name);
064  }
065    
066  /**
067   * Returns the set of metric names.
068   */
069  public Set<String> getMetricNames() {
070    return Collections.unmodifiableSet(metricMap.keySet());
071  }
072    
073  /**
074   * Returns the metric object which can be a Float, Integer, Short or Byte.
075   */
076  public Number getMetric(String name) {
077    return metricMap.get(name);
078  }
079  
080
081  /**
082   * Returns a copy of this record's tags.
083   */
084  public TagMap getTagsCopy() {
085    return new TagMap(tagMap);
086  }
087  
088  /**
089   * Returns a copy of this record's metrics.
090   */
091  public MetricMap getMetricsCopy() {
092    return new MetricMap(metricMap);
093  }
094}