Search in sources :

Example 1 with StormTimer

use of org.apache.storm.StormTimer in project storm by apache.

the class Executor method setupTicks.

protected void setupTicks(boolean isSpout) {
    final Integer tickTimeSecs = Utils.getInt(stormConf.get(Config.TOPOLOGY_TICK_TUPLE_FREQ_SECS), null);
    boolean enableMessageTimeout = (Boolean) stormConf.get(Config.TOPOLOGY_ENABLE_MESSAGE_TIMEOUTS);
    if (tickTimeSecs != null) {
        if (Utils.isSystemId(componentId) || (!enableMessageTimeout && isSpout)) {
            LOG.info("Timeouts disabled for executor " + componentId + ":" + executorId);
        } else {
            StormTimer timerTask = workerData.getUserTimer();
            timerTask.scheduleRecurring(tickTimeSecs, tickTimeSecs, new Runnable() {

                @Override
                public void run() {
                    TupleImpl tuple = new TupleImpl(workerTopologyContext, new Values(tickTimeSecs), (int) Constants.SYSTEM_TASK_ID, Constants.SYSTEM_TICK_STREAM_ID);
                    List<AddressedTuple> tickTuple = Lists.newArrayList(new AddressedTuple(AddressedTuple.BROADCAST_DEST, tuple));
                    receiveQueue.publish(tickTuple);
                }
            });
        }
    }
}
Also used : StormTimer(org.apache.storm.StormTimer) Values(org.apache.storm.tuple.Values) List(java.util.List) ArrayList(java.util.ArrayList) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) TupleImpl(org.apache.storm.tuple.TupleImpl) AddressedTuple(org.apache.storm.tuple.AddressedTuple)

Example 2 with StormTimer

use of org.apache.storm.StormTimer in project storm by apache.

the class Executor method setupMetrics.

protected void setupMetrics() {
    for (final Integer interval : intervalToTaskToMetricToRegistry.keySet()) {
        StormTimer timerTask = workerData.getUserTimer();
        timerTask.scheduleRecurring(interval, interval, new Runnable() {

            @Override
            public void run() {
                TupleImpl tuple = new TupleImpl(workerTopologyContext, new Values(interval), (int) Constants.SYSTEM_TASK_ID, Constants.METRICS_TICK_STREAM_ID);
                List<AddressedTuple> metricsTickTuple = Lists.newArrayList(new AddressedTuple(AddressedTuple.BROADCAST_DEST, tuple));
                receiveQueue.publish(metricsTickTuple);
            }
        });
    }
}
Also used : StormTimer(org.apache.storm.StormTimer) Values(org.apache.storm.tuple.Values) List(java.util.List) ArrayList(java.util.ArrayList) TupleImpl(org.apache.storm.tuple.TupleImpl) AddressedTuple(org.apache.storm.tuple.AddressedTuple)

Aggregations

ArrayList (java.util.ArrayList)2 List (java.util.List)2 StormTimer (org.apache.storm.StormTimer)2 AddressedTuple (org.apache.storm.tuple.AddressedTuple)2 TupleImpl (org.apache.storm.tuple.TupleImpl)2 Values (org.apache.storm.tuple.Values)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1