summaryrefslogtreecommitdiffstats
path: root/messagebus/src/main/java/com/yahoo/messagebus/metrics/Metric.java
blob: 004f48e43f0fc85a18a2ea4d42306f88e93444eb (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.messagebus.metrics;

import com.yahoo.text.XMLWriter;
import com.yahoo.text.Utf8String;

import java.io.Writer;

/**
 * @author thomasg
 */
public abstract class Metric {
    String name;
    String xmlTagName = null;

    public Metric(String name) {
        this.name = name;
    }

    public String getName() {
        return name;
    }

    public String toHTML() {
        return toString();
    }

    public String getXmlTagName() {
        return xmlTagName;
    }

    public void setXmlTagName(String newName) {
        xmlTagName = newName;
    }

    static private final Utf8String attrName = new Utf8String("name");

    public void renderXmlName(XMLWriter writer) {
        if (xmlTagName != null) {
            writer.openTag(xmlTagName);
            writer.attribute(attrName, name);
        } else {
            writer.openTag(name);
        }
    }

    public abstract void toXML(XMLWriter writer);
}