Search in sources :

Example 1 with IShellMetric

use of backtype.storm.metric.api.rpc.IShellMetric in project jstorm by alibaba.

the class ShellBolt method handleMetrics.

private void handleMetrics(ShellMsg shellMsg) {
    // get metric name
    String name = shellMsg.getMetricName();
    if (name.isEmpty()) {
        throw new RuntimeException("Receive Metrics name is empty");
    }
    // get metric by name
    IMetric iMetric = _context.getRegisteredMetricByName(name);
    if (iMetric == null) {
        throw new RuntimeException("Could not find metric by name[" + name + "] ");
    }
    if (!(iMetric instanceof IShellMetric)) {
        throw new RuntimeException("Metric[" + name + "] is not IShellMetric, can not call by RPC");
    }
    IShellMetric iShellMetric = (IShellMetric) iMetric;
    // call updateMetricFromRPC with params
    Object paramsObj = shellMsg.getMetricParams();
    try {
        iShellMetric.updateMetricFromRPC(paramsObj);
    } catch (RuntimeException re) {
        throw re;
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : IMetric(backtype.storm.metric.api.IMetric) IShellMetric(backtype.storm.metric.api.rpc.IShellMetric) ReportedFailedException(backtype.storm.topology.ReportedFailedException)

Example 2 with IShellMetric

use of backtype.storm.metric.api.rpc.IShellMetric in project jstorm by alibaba.

the class ShellSpout method handleMetrics.

private void handleMetrics(ShellMsg shellMsg) {
    // get metric name
    String name = shellMsg.getMetricName();
    if (name.isEmpty()) {
        throw new RuntimeException("Receive Metrics name is empty");
    }
    // get metric by name
    IMetric iMetric = _context.getRegisteredMetricByName(name);
    if (iMetric == null) {
        throw new RuntimeException("Could not find metric by name[" + name + "] ");
    }
    if (!(iMetric instanceof IShellMetric)) {
        throw new RuntimeException("Metric[" + name + "] is not IShellMetric, can not call by RPC");
    }
    IShellMetric iShellMetric = (IShellMetric) iMetric;
    // call updateMetricFromRPC with params
    Object paramsObj = shellMsg.getMetricParams();
    try {
        iShellMetric.updateMetricFromRPC(paramsObj);
    } catch (RuntimeException re) {
        throw re;
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : IMetric(backtype.storm.metric.api.IMetric) IShellMetric(backtype.storm.metric.api.rpc.IShellMetric) IOException(java.io.IOException)

Aggregations

IMetric (backtype.storm.metric.api.IMetric)2 IShellMetric (backtype.storm.metric.api.rpc.IShellMetric)2 ReportedFailedException (backtype.storm.topology.ReportedFailedException)1 IOException (java.io.IOException)1