Search in sources :

Example 1 with IShellMetric

use of org.apache.storm.metric.api.rpc.IShellMetric in project storm by apache.

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(org.apache.storm.metric.api.IMetric) IShellMetric(org.apache.storm.metric.api.rpc.IShellMetric)

Example 2 with IShellMetric

use of org.apache.storm.metric.api.rpc.IShellMetric in project storm by apache.

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(org.apache.storm.metric.api.IMetric) IShellMetric(org.apache.storm.metric.api.rpc.IShellMetric) ReportedFailedException(org.apache.storm.topology.ReportedFailedException)

Aggregations

IMetric (org.apache.storm.metric.api.IMetric)2 IShellMetric (org.apache.storm.metric.api.rpc.IShellMetric)2 ReportedFailedException (org.apache.storm.topology.ReportedFailedException)1