Java Code Examples for org.apache.storm.task.OutputCollector#emit()

The following examples show how to use org.apache.storm.task.OutputCollector#emit() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: StormErrorUtils.java    From metron with Apache License 2.0 5 votes vote down vote up
/**
 * Handles a {@link MetronError} that occurs.
 *
 * @param collector The Storm output collector being reported to
 * @param error The error that occurred
 */
public static void handleError(OutputCollector collector, MetronError error)
{
  collector.emit(Constants.ERROR_STREAM, new Values(error.getJSONObject()));
  Optional<Throwable> throwable = error.getThrowable();
  if (throwable.isPresent()) {
    collector.reportError(throwable.get());
  }

}
 
Example 2
Source File: KafkaEmitter.java    From metron with Apache License 2.0 5 votes vote down vote up
@Override
public void emit(ProfileMeasurement measurement, OutputCollector collector) {

  // only need to emit, if there are triage values
  Map<String, Object> triageValues = measurement.getTriageValues();
  if(MapUtils.isNotEmpty(triageValues)) {

    JSONObject message = createMessage(measurement);
    appendTriageValues(measurement, message);
    collector.emit(getStreamId(), new Values(message));

    LOG.debug("Emitted measurement; stream={}, profile={}, entity={}, period={}, start={}, end={}",
            getStreamId(),
            measurement.getProfileName(),
            measurement.getEntity(),
            measurement.getPeriod().getPeriod(),
            measurement.getPeriod().getStartTimeMillis(),
            measurement.getPeriod().getEndTimeMillis());

  } else {

    LOG.debug("No triage values, nothing to emit; stream={}, profile={}, entity={}, period={}, start={}, end={}",
            getStreamId(),
            measurement.getProfileName(),
            measurement.getEntity(),
            measurement.getPeriod().getPeriod(),
            measurement.getPeriod().getStartTimeMillis(),
            measurement.getPeriod().getEndTimeMillis());
  }
}
 
Example 3
Source File: HBaseEmitter.java    From metron with Apache License 2.0 5 votes vote down vote up
@Override
public void emit(ProfileMeasurement measurement, OutputCollector collector) {

  // measurements are always emitted to hbase
  collector.emit(getStreamId(), new Values(measurement));

  LOG.debug("Emitted measurement; stream={}, profile={}, entity={}, period={}, start={}, end={}",
          getStreamId(),
          measurement.getProfileName(),
          measurement.getEntity(),
          measurement.getPeriod().getPeriod(),
          measurement.getPeriod().getStartTimeMillis(),
          measurement.getPeriod().getEndTimeMillis());
}
 
Example 4
Source File: ProfileBuilderBoltTest.java    From metron with Apache License 2.0 4 votes vote down vote up
@Override
public void emit(ProfileMeasurement measurement, OutputCollector collector) {
  collector.emit(getStreamId(), new Values(measurement));
}
 
Example 5
Source File: MetricFilteringBolt.java    From monasca-thresh with Apache License 2.0 4 votes vote down vote up
@Override
@SuppressWarnings("rawtypes")
public void prepare(Map stormConf, TopologyContext context, OutputCollector collector) {
  logger = LoggerFactory.getLogger(Logging.categoryFor(getClass(), context));
  logger.info("Preparing");
  this.collector = collector;

  if (alarmDefDAO == null) {
    Injector.registerIfNotBound(AlarmDefinitionDAO.class, new PersistenceModule(dbConfig));
    alarmDefDAO = Injector.getInstance(AlarmDefinitionDAO.class);
  }

  if (alarmDAO == null) {
    Injector.registerIfNotBound(AlarmDAO.class, new PersistenceModule(dbConfig));
    alarmDAO = Injector.getInstance(AlarmDAO.class);
  }

  // DCL
  if (alreadyFound.isEmpty()) {
    synchronized (SENTINAL) {
      if (alreadyFound.isEmpty()) {
        for (AlarmDefinition alarmcDef : alarmDefDAO.listAll()) {
          newAlarmDefinition(alarmcDef);
        }

        // Load the existing Alarms
        for (Alarm alarm : alarmDAO.listAll()) {
          final AlarmDefinition alarmDefinition =
              alarmDefinitions.get(alarm.getAlarmDefinitionId());
          if (alarmDefinition == null) {
            logger.error("AlarmDefinition {} does not exist for Alarm {}, ignoring",
                alarm.getAlarmDefinitionId(), alarm.getId());
            continue;
          }
          for (final MetricDefinitionAndTenantId mtid : alarm.getAlarmedMetrics()) {
            alreadyFound.add(mtid, alarm.getAlarmDefinitionId());
            for (final SubAlarm subAlarm : alarm.getSubAlarms()) {
              if (AlarmCreationBolt.metricFitsInAlarmSubExpr(subAlarm.getExpression(),
                  mtid.metricDefinition)) {
                final TenantIdAndMetricName timn = new TenantIdAndMetricName(mtid);
                final Values values =
                    new Values(EventProcessingBolt.CREATED, timn, mtid,
                        alarm.getAlarmDefinitionId(), subAlarm);
                logger.debug("Emitting new SubAlarm {}", values);
                collector.emit(AlarmCreationBolt.ALARM_CREATION_STREAM, values);
              }
            }
          }
        }

        logger.info("Found {} Alarmed Metrics", alreadyFound.size());
        // Just output these here so they are only output once per JVM
        logger.info("MIN_LAG_VALUE set to {} seconds", MIN_LAG_VALUE);
        logger.info("MAX_LAG_MESSAGES set to {}", MAX_LAG_MESSAGES);
        logger.info("LAG_MESSAGE_PERIOD set to {} seconds", LAG_MESSAGE_PERIOD);
      }
    }
  }
  lastMinLagMessageSent = 0;
}
 
Example 6
Source File: BoltCommandHandler.java    From DBus with Apache License 2.0 2 votes vote down vote up
/**
 * 将data数组中的数据,按照groupField分组发送的一个bolt处理,
 * Grouping策略使用DbusGrouping实现
 *
 * @param collector
 * @param tuple      当前bolt接收到的数据
 * @param groupField 分组字段
 * @param data       要发送的数据
 */
default void emit(OutputCollector collector, Tuple tuple, String groupField, EmitData data, Command cmd) {
    List<Object> values = Lists.newArrayList(groupField, data, cmd, EmitFields.EMIT_TO_BOLT);
    collector.emit(tuple, values);
}
 
Example 7
Source File: BoltCommandHandler.java    From DBus with Apache License 2.0 2 votes vote down vote up
/**
 * 将tuple中的数据发送给下游所有的bolt
 *
 * @param collector
 * @param tuple     当前bolt接收到的数据
 */
default void emitToAll(OutputCollector collector, Tuple tuple, EmitData data, Command cmd) {
    List<Object> values = Lists.newArrayList(EmitData.NO_VALUE, data, cmd, EmitFields.EMIT_TO_ALL);
    collector.emit(tuple, values);
}
 
Example 8
Source File: BoltCommandHandler.java    From DBus with Apache License 2.0 2 votes vote down vote up
/**
 * 将data数组中的数据,按照groupField分组发送的一个bolt处理,
 * Grouping策略使用DbusGrouping实现
 *
 * @param collector
 * @param tuple      当前bolt接收到的数据
 * @param groupField 分组字段
 * @param data       要发送的数据
 */
default void emitHeartbeat(OutputCollector collector, Tuple tuple, String groupField, EmitData data, Command cmd) {
    List<Object> values = Lists.newArrayList(groupField, data, cmd, EmitFields.EMIT_HEARTBEAT);
    collector.emit(tuple, values);
}