org.apache.storm.task.TopologyContext.getRegisteredMetricByName()方法的使用及代码示例

x33g5p2x  于2022-01-30 转载在 其他  
字(4.3k)|赞(0)|评价(0)|浏览(52)

本文整理了Java中org.apache.storm.task.TopologyContext.getRegisteredMetricByName()方法的一些代码示例,展示了TopologyContext.getRegisteredMetricByName()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。TopologyContext.getRegisteredMetricByName()方法的具体详情如下:
包路径:org.apache.storm.task.TopologyContext
类名称:TopologyContext
方法名:getRegisteredMetricByName

TopologyContext.getRegisteredMetricByName介绍

[英]Get component's metric from registered metrics by name. Notice: Normally, one component can only register one metric name once. But now registerMetric has a bug(https://issues.apache.org/jira/browse/STORM-254) cause the same metric name can register twice. So we just return the first metric we meet.
[中]按名称从注册的度量中获取组件的度量。注意:通常,一个组件只能注册一个度量名称一次。但是现在registerMetric有一个bug(https://issues.apache.org/jira/browse/STORM-254)因为同一度量名称可以注册两次。所以我们只返回我们遇到的第一个度量。

代码示例

代码示例来源:origin: apache/storm

if (getRegisteredMetricByName(name) != null) {
  throw new RuntimeException("The same metric name `" + name + "` was registered twice.");

代码示例来源:origin: apache/storm

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);
  }
}

代码示例来源:origin: apache/storm

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);
  }
}

代码示例来源:origin: org.apache.storm/storm-core

if (getRegisteredMetricByName(name) != null) {
  throw new RuntimeException("The same metric name `" + name + "` was registered twice." );

代码示例来源:origin: org.apache.storm/storm-core

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);
  }       
}

代码示例来源:origin: org.apache.storm/storm-core

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);
  }       
}

相关文章

微信公众号

最新文章

更多