Search in sources :

Example 1 with BatchId

use of com.alibaba.jstorm.batch.BatchId in project jstorm by alibaba.

the class SimpleSpout method execute.

@Override
public void execute(Tuple input, BasicOutputCollector collector) {
    BatchId batchId = (BatchId) input.getValue(0);
    for (int i = 0; i < batchSize; i++) {
        long value = rand.nextInt(10);
        collector.emit(new Values(batchId, value));
    }
}
Also used : BatchId(com.alibaba.jstorm.batch.BatchId) Values(backtype.storm.tuple.Values)

Example 2 with BatchId

use of com.alibaba.jstorm.batch.BatchId in project jstorm by alibaba.

the class BatchSpoutMsgId method mkInstance.

public static BatchSpoutMsgId mkInstance() {
    BatchId batchId = BatchId.mkInstance();
    BatchStatus batchStatus = BatchStatus.COMPUTING;
    return new BatchSpoutMsgId(batchId, batchStatus);
}
Also used : BatchId(com.alibaba.jstorm.batch.BatchId) BatchStatus(com.alibaba.jstorm.batch.util.BatchStatus)

Example 3 with BatchId

use of com.alibaba.jstorm.batch.BatchId in project jstorm by alibaba.

the class SimpleBatchTestBolt method execute.

@Override
public void execute(Tuple tuple, BasicOutputCollector basicOutputCollector) {
    BatchId id = (BatchId) tuple.getValue(0);
    Long value = tuple.getLong(1);
    System.out.println("SimpleBatchTestBolt #execute id = " + id + " value = " + value);
}
Also used : BatchId(com.alibaba.jstorm.batch.BatchId)

Example 4 with BatchId

use of com.alibaba.jstorm.batch.BatchId in project jstorm by alibaba.

the class CountBolt method execute.

@Override
public void execute(Tuple input, BasicOutputCollector collector) {
    BatchId id = (BatchId) input.getValue(0);
    AtomicLong counter = counters.get(id);
    if (counter == null) {
        counter = new AtomicLong(0);
        counters.put(id, counter);
    }
    counter.incrementAndGet();
}
Also used : AtomicLong(java.util.concurrent.atomic.AtomicLong) BatchId(com.alibaba.jstorm.batch.BatchId)

Example 5 with BatchId

use of com.alibaba.jstorm.batch.BatchId in project jstorm by alibaba.

the class DBBolt method execute.

@Override
public void execute(Tuple input, BasicOutputCollector collector) {
    BatchId batchId = (BatchId) input.getValue(0);
    if (input.getSourceComponent().equals(CountBolt.COUNT_BOLT_NAME)) {
        AtomicLong counter = counters.get(batchId);
        if (counter == null) {
            counter = new AtomicLong(0);
            counters.put(batchId, counter);
        }
        long value = input.getLong(1);
        counter.addAndGet(value);
    } else if (input.getSourceComponent().equals(CountBolt.SUM_BOLT_NAME)) {
        AtomicLong sum = sums.get(batchId);
        if (sum == null) {
            sum = new AtomicLong(0);
            sums.put(batchId, sum);
        }
        long value = input.getLong(1);
        sum.addAndGet(value);
    } else {
        LOG.warn("Unknow source type");
    }
}
Also used : AtomicLong(java.util.concurrent.atomic.AtomicLong) BatchId(com.alibaba.jstorm.batch.BatchId)

Aggregations

BatchId (com.alibaba.jstorm.batch.BatchId)12 FailedException (backtype.storm.topology.FailedException)3 Values (backtype.storm.tuple.Values)3 AtomicLong (java.util.concurrent.atomic.AtomicLong)3 ReportedFailedException (backtype.storm.topology.ReportedFailedException)2 IPostCommit (com.alibaba.jstorm.batch.IPostCommit)1 IPrepareCommit (com.alibaba.jstorm.batch.IPrepareCommit)1 BatchStatus (com.alibaba.jstorm.batch.util.BatchStatus)1