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.Set; 025import org.apache.hadoop.classification.InterfaceAudience; 026import org.apache.hadoop.classification.InterfaceStability; 027import org.apache.hadoop.metrics.spi.AbstractMetricsContext.MetricMap; 028import org.apache.hadoop.metrics.spi.AbstractMetricsContext.TagMap; 029 030/** 031 * Represents a record of metric data to be sent to a metrics system. 032 */ 033@InterfaceAudience.Public 034@InterfaceStability.Evolving 035public class OutputRecord { 036 037 private TagMap tagMap; 038 private MetricMap metricMap; 039 040 /** Creates a new instance of OutputRecord */ 041 OutputRecord(TagMap tagMap, MetricMap metricMap) { 042 this.tagMap = tagMap; 043 this.metricMap = metricMap; 044 } 045 046 /** 047 * Returns the set of tag names 048 */ 049 public Set<String> getTagNames() { 050 return Collections.unmodifiableSet(tagMap.keySet()); 051 } 052 053 /** 054 * Returns a tag object which is can be a String, Integer, Short or Byte. 055 * 056 * @return the tag value, or null if there is no such tag 057 */ 058 public Object getTag(String name) { 059 return tagMap.get(name); 060 } 061 062 /** 063 * Returns the set of metric names. 064 */ 065 public Set<String> getMetricNames() { 066 return Collections.unmodifiableSet(metricMap.keySet()); 067 } 068 069 /** 070 * Returns the metric object which can be a Float, Integer, Short or Byte. 071 */ 072 public Number getMetric(String name) { 073 return metricMap.get(name); 074 } 075 076 077 /** 078 * Returns a copy of this record's tags. 079 */ 080 public TagMap getTagsCopy() { 081 return new TagMap(tagMap); 082 } 083 084 /** 085 * Returns a copy of this record's metrics. 086 */ 087 public MetricMap getMetricsCopy() { 088 return new MetricMap(metricMap); 089 } 090}