Example usage for org.apache.commons.lang ClassUtils getShortCanonicalName

List of usage examples for org.apache.commons.lang ClassUtils getShortCanonicalName

Introduction

In this page you can find the example usage for org.apache.commons.lang ClassUtils getShortCanonicalName.

Prototype

public static String getShortCanonicalName(Object object, String valueIfNull) 

Source Link

Document

Gets the canonical name minus the package name for an Object.

Usage

From source file:org.apache.hadoop.metrics2.sink.storm.StormTimelineMetricsReporter.java

private TimelineMetric createTimelineMetric(long currentTimeMillis, String component, String attributeName,
        String attributeValue) {//  w ww  . j  a v a 2  s  .  c o m
    TimelineMetric timelineMetric = new TimelineMetric();
    timelineMetric.setMetricName(attributeName);
    timelineMetric.setHostName(hostname);
    timelineMetric.setAppId(component);
    timelineMetric.setStartTime(currentTimeMillis);
    timelineMetric.setType(ClassUtils.getShortCanonicalName(attributeValue, "Number"));
    timelineMetric.getMetricValues().put(currentTimeMillis, Double.parseDouble(attributeValue));
    return timelineMetric;
}

From source file:org.apache.hadoop.metrics2.sink.timeline.HadoopTimelineMetricsSink.java

@Override
public void putMetrics(MetricsRecord record) {
    try {/*from  w w  w .j a  v a2  s  . c  o m*/
        String recordName = record.name();
        String contextName = record.context();

        StringBuilder sb = new StringBuilder();
        sb.append(contextName);
        sb.append('.');
        sb.append(recordName);

        appendPrefix(record, sb);
        sb.append(".");
        int sbBaseLen = sb.length();

        Collection<AbstractMetric> metrics = (Collection<AbstractMetric>) record.metrics();

        List<TimelineMetric> metricList = new ArrayList<TimelineMetric>();
        long startTime = record.timestamp();

        for (AbstractMetric metric : metrics) {
            sb.append(metric.name());
            String name = sb.toString();
            Number value = metric.value();
            TimelineMetric timelineMetric = new TimelineMetric();
            timelineMetric.setMetricName(name);
            timelineMetric.setHostName(hostName);
            timelineMetric.setAppId(serviceName);
            timelineMetric.setStartTime(startTime);
            timelineMetric.setType(ClassUtils.getShortCanonicalName(value, "Number"));
            timelineMetric.getMetricValues().put(startTime, value.doubleValue());
            // Put intermediate values into the cache until it is time to send
            boolean isCounter = MetricType.COUNTER == metric.type();
            metricsCache.putTimelineMetric(timelineMetric, isCounter);

            // Retrieve all values from cache if it is time to send
            TimelineMetric cachedMetric = metricsCache.getTimelineMetric(name);

            if (cachedMetric != null) {
                metricList.add(cachedMetric);
            }

            sb.setLength(sbBaseLen);
        }

        TimelineMetrics timelineMetrics = new TimelineMetrics();
        timelineMetrics.setMetrics(metricList);

        if (!metricList.isEmpty()) {
            emitMetrics(timelineMetrics);
        }
    } catch (UnableToConnectException uce) {
        LOG.warn("Unable to send metrics to collector by address:" + uce.getConnectUrl());
    } catch (IOException io) {
        throw new MetricsException("Failed to putMetrics", io);
    }
}

From source file:org.springframework.boot.actuate.metrics.ambari.buffer.MetricBuffer.java

private void putMetricType(Metric<?> metric) {
    if (!metricTypeMap.containsKey(metric.getName())) {
        String metricType = ClassUtils.getShortCanonicalName(metric.getValue(), "Number");
        metricTypeMap.putIfAbsent(metric.getName(), metricType);
    }/*  w  ww  .j  a va  2s . com*/
}