org.apache.storm.utils.TupleUtils Java Examples

The following examples show how to use org.apache.storm.utils.TupleUtils. 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: NiFiBolt.java    From localization_nifi with Apache License 2.0 6 votes vote down vote up
@Override
public void execute(Tuple tuple) {
    if (TupleUtils.isTick(tuple)) {
        // if we have a tick tuple then lets see if enough time has passed since our last batch was processed
        if ((System.currentTimeMillis() / 1000 - lastBatchProcessTimeSeconds) >= batchIntervalInSec) {
            LOGGER.debug("Received tick tuple and reached batch interval, executing batch");
            finishBatch();
        } else {
            LOGGER.debug("Received tick tuple, but haven't reached batch interval, nothing to do");
        }
    } else {
        // for a regular tuple we add it to the queue and then see if our queue size exceeds batch size
        this.queue.add(tuple);

        int queueSize = this.queue.size();
        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("Current queue size is " + queueSize + ", and batch size is " + batchSize);
        }

        if (queueSize >= batchSize) {
            LOGGER.debug("Queue Size is greater than or equal to batch size, executing batch");
            finishBatch();
        }
    }
}
 
Example #2
Source File: WrapperBolt.java    From DBus with Apache License 2.0 6 votes vote down vote up
@Override
public void execute(Tuple input) {
    if (TupleUtils.isTick(input)) {
        collector.ack(input);
        return;
    }

    try {
        Command cmd = (Command) input.getValueByField(EmitFields.COMMAND);
        BoltCommandHandler handler = handlerManager.getHandler(cmd);
        handler.handle(input);
        this.collector.ack(input);
    } catch (Exception e) {
        logger.error("Process data error", e);
        this.collector.reportError(e);
        this.collector.fail(input);
    }

}
 
Example #3
Source File: DbusAppenderBolt.java    From DBus with Apache License 2.0 6 votes vote down vote up
@Override
public void execute(Tuple input) {
    if (TupleUtils.isTick(input)) {
        collector.ack(input);
        return;
    }
    try {
        Command cmd = (Command) input.getValueByField(EmitFields.COMMAND);
        BoltCommandHandler handler = handlerManager.getHandler(cmd);
        handler.handle(input);
        this.collector.ack(input);
    } catch (Exception e) {
        this.collector.fail(input);
        this.collector.reportError(e);
        logger.error("Process Error!", e);
    }

}
 
Example #4
Source File: DispatcherBolt.java    From DBus with Apache License 2.0 6 votes vote down vote up
@Override
public void execute(Tuple input) {
    if (TupleUtils.isTick(input)) {
        collector.ack(input);
        return;
    }
    try {
        Command cmd = (Command) input.getValueByField(EmitFields.COMMAND);
        BoltCommandHandler handler = handlerManager.getHandler(cmd);
        handler.handle(input);
        this.collector.ack(input);
    } catch (Exception e) {
        this.collector.fail(input);
        this.collector.reportError(e);
        logger.error("Process Error!", e);
    }

}
 
Example #5
Source File: DbusKafkaWriterBolt.java    From DBus with Apache License 2.0 6 votes vote down vote up
@Override
public void execute(Tuple input) {
    if (TupleUtils.isTick(input)) {
        collector.ack(input);
        return;
    }

    try {
        Command cmd = (Command) input.getValueByField(EmitFields.COMMAND);
        BoltCommandHandler handler = handlerManager.getHandler(cmd);
        handler.handle(input);
    } catch (Exception e) {
        logger.error("Process data error", e);
        this.collector.reportError(e);
        this.collector.fail(input);
    }

}
 
Example #6
Source File: RealtimeJoinBolt.java    From streamline with Apache License 2.0 6 votes vote down vote up
@Override
public void execute(Tuple tuple) {
    long currTime = System.currentTimeMillis();
    for (JoinInfo joinInfo : joinInfos) {
        joinInfo.expireAndAckTimedOutEntries(collector, currTime);
    }

    if (TupleUtils.isTick(tuple))
        return;

    try {
        String stream = streamKind.getStreamId(tuple);
        if (stream.equalsIgnoreCase(fromStream))
            processFromStreamTuple(tuple, currTime);
        else if(stream.equalsIgnoreCase(joinStream))
            processJoinStreamTuple(tuple, currTime);
        else
            throw new InvalidTuple("Source component/streamId for Tuple not part of streams being joined : " + stream, tuple);
    } catch (InvalidTuple e) {
        collector.ack(tuple);
        LOG.warn("{}. Tuple will be dropped.",  e.toString());
    }
}
 
Example #7
Source File: NiFiBolt.java    From nifi with Apache License 2.0 6 votes vote down vote up
@Override
public void execute(Tuple tuple) {
    if (TupleUtils.isTick(tuple)) {
        // if we have a tick tuple then lets see if enough time has passed since our last batch was processed
        if ((System.currentTimeMillis() / 1000 - lastBatchProcessTimeSeconds) >= batchIntervalInSec) {
            LOGGER.debug("Received tick tuple and reached batch interval, executing batch");
            finishBatch();
        } else {
            LOGGER.debug("Received tick tuple, but haven't reached batch interval, nothing to do");
        }
    } else {
        // for a regular tuple we add it to the queue and then see if our queue size exceeds batch size
        this.queue.add(tuple);

        int queueSize = this.queue.size();
        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("Current queue size is " + queueSize + ", and batch size is " + batchSize);
        }

        if (queueSize >= batchSize) {
            LOGGER.debug("Queue Size is greater than or equal to batch size, executing batch");
            finishBatch();
        }
    }
}
 
Example #8
Source File: DbusHeartBeatBolt.java    From DBus with Apache License 2.0 5 votes vote down vote up
public void execute(Tuple input) {
    if (TupleUtils.isTick(input)) {
        collector.ack(input);
        return;
    }
    try {
        Command cmd = (Command) input.getValueByField(Constants.EmitFields.COMMAND);
        BoltCommandHandler handler = handlerManager.getHandler(cmd);
        handler.handle(input);
        this.collector.ack(input);
    } catch (Exception e) {
        this.collector.ack(input);
        logger.error("Heartbeat error, ignore this error", e);
    }
}
 
Example #9
Source File: RollingCountBolt.java    From storm_spring_boot_demo with MIT License 5 votes vote down vote up
@Override
public void execute(Tuple tuple) {
  //如果是TickTuple(则说明该Tuple触发了时间窗口),则将当前时间窗口的计数和实际的时间窗口长度emit。
  if (TupleUtils.isTick(tuple)) {
    LOG.debug("Received tick tuple, triggering emit of current window counts");
    emitCurrentWindowCounts();
  }
  else {
    countObjAndAck(tuple);
  }
}
 
Example #10
Source File: AbstractRankerBolt.java    From storm_spring_boot_demo with MIT License 5 votes vote down vote up
/**
 * This method functions as a template method (design pattern).
 */
@Override
public final void execute(Tuple tuple, BasicOutputCollector collector) {
  if (TupleUtils.isTick(tuple)) {
    getLogger().debug("Received tick tuple, triggering emit of current rankings");
    emitRankings(collector);
  }
  else {
    updateRankingsWithTuple(tuple);
  }
}
 
Example #11
Source File: BaseTickTupleAwareRichBolt.java    From incubator-heron with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 *
 * @param tuple the tuple to process.
 */
@Override
public void execute(final Tuple tuple) {
  if (TupleUtils.isTick(tuple)) {
    onTickTuple(tuple);
  } else {
    process(tuple);
  }
}
 
Example #12
Source File: BaseTickTupleAwareRichBolt.java    From streamline with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 *
 * @param tuple the tuple to process.
 */
@Override
public void execute(final Tuple tuple) {
    if (TupleUtils.isTick(tuple)) {
        onTickTuple(tuple);
    } else {
        process(tuple);
    }
}
 
Example #13
Source File: RollingCountBolt.java    From storm-net-adapter with Apache License 2.0 5 votes vote down vote up
@Override
public void execute(Tuple tuple) {
    if (TupleUtils.isTick(tuple)) {
        LOG.debug("Received tick tuple, triggering emit of current window counts");
        emitCurrentWindowCounts();
    } else {
        countObjAndAck(tuple);
    }
}
 
Example #14
Source File: AbstractRankerBolt.java    From storm-net-adapter with Apache License 2.0 5 votes vote down vote up
/**
 * This method functions as a template method (design pattern).
 */
@Override
public final void execute(Tuple tuple, BasicOutputCollector collector) {
    if (TupleUtils.isTick(tuple)) {
        getLogger().debug("Received tick tuple, triggering emit of current rankings");
        emitRankings(collector);
    } else {
        updateRankingsWithTuple(tuple);
    }
}
 
Example #15
Source File: StatusMetricsBolt.java    From storm-crawler with Apache License 2.0 5 votes vote down vote up
@Override
public void execute(Tuple input) {
    _collector.ack(input);

    // this bolt can be connected to anything
    // we just want to trigger a new search when the input is a tick tuple
    if (!TupleUtils.isTick(input)) {
        return;
    }

    for (StatusActionListener listener : listeners) {
        // still waiting for results from previous request
        if (!listener.isReady()) {
            LOG.debug("Not ready to get counts for status {}",
                    listener.name);
            continue;
        }
        CountRequest request = new CountRequest(indexName);
        if (!listener.name.equalsIgnoreCase("TOTAL")) {
            SearchSourceBuilder sourceBuilder = new SearchSourceBuilder();
            sourceBuilder.query(QueryBuilders.termQuery("status",
                    listener.name));
            request.source(sourceBuilder);
        }
        listener.busy();
        connection.getClient().countAsync(request, RequestOptions.DEFAULT,
                listener);
    }
}
 
Example #16
Source File: PulsarBolt.java    From pulsar with Apache License 2.0 4 votes vote down vote up
@Override
public void execute(Tuple input) {
    if (TupleUtils.isTick(input)) {
        collector.ack(input);
        return;
    }
    try {
        if (producer != null) {
            // a message key can be provided in the mapper
            TypedMessageBuilder<byte[]> msgBuilder = pulsarBoltConf.getTupleToMessageMapper()
                    .toMessage(producer.newMessage(), input);
            if (msgBuilder == null) {
                if (LOG.isDebugEnabled()) {
                    LOG.debug("[{}] Cannot send null message, acking the collector", boltId);
                }
                collector.ack(input);
            } else {
                final long messageSizeToBeSent = ((TypedMessageBuilderImpl<byte[]>) msgBuilder).getContent()
                        .remaining();
                msgBuilder.sendAsync().handle((msgId, ex) -> {
                    synchronized (collector) {
                        if (ex != null) {
                            collector.reportError(ex);
                            collector.fail(input);
                            LOG.error("[{}] Message send failed", boltId, ex);

                        } else {
                            collector.ack(input);
                            ++messagesSent;
                            messageSizeSent += messageSizeToBeSent;
                            if (LOG.isDebugEnabled()) {
                                LOG.debug("[{}] Message sent with id {}", boltId, msgId);
                            }
                        }
                    }

                    return null;
                });
            }
        }
    } catch (Exception e) {
        LOG.error("[{}] Message processing failed", boltId, e);
        collector.reportError(e);
        collector.fail(input);
    }
}