Java Code Examples for storm.trident.operation.TridentCollector#emit()

The following examples show how to use storm.trident.operation.TridentCollector#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: ChainedAggregatorImpl.java    From jstorm with Apache License 2.0 6 votes vote down vote up
public void complete(ChainedResult val, TridentCollector collector) {
    val.setFollowThroughCollector(collector);
    for (int i = 0; i < _aggs.length; i++) {
        _aggs[i].complete(val.objs[i], val.collectors[i]);
    }
    if (_aggs.length > 1) { // otherwise, tuples were emitted directly
        int[] indices = new int[val.collectors.length];
        for (int i = 0; i < indices.length; i++) {
            indices[i] = 0;
        }
        boolean keepGoing = true;
        // emit cross-join of all emitted tuples
        while (keepGoing) {
            List[] combined = new List[_aggs.length];
            for (int i = 0; i < _aggs.length; i++) {
                CaptureCollector capturer = (CaptureCollector) val.collectors[i];
                combined[i] = capturer.captured.get(indices[i]);
            }
            collector.emit(_fact.create(combined));
            keepGoing = increment(val.collectors, indices, indices.length - 1);
        }
    }
}
 
Example 2
Source File: FixedBatchSpout.java    From storm-hdfs with Apache License 2.0 6 votes vote down vote up
@Override
public void emitBatch(long batchId, TridentCollector collector) {
    List<List<Object>> batch = this.batches.get(batchId);
    if(batch == null){
        batch = new ArrayList<List<Object>>();
        if(index>=outputs.length && cycle) {
            index = 0;
        }
        for(int i=0; i < maxBatchSize; index++, i++) {
            if(index == outputs.length){
                index=0;
            }
            batch.add(outputs[index]);
        }
        this.batches.put(batchId, batch);
    }
    for(List<Object> list : batch){
        collector.emit(list);
    }
}
 
Example 3
Source File: TridentThroughput.java    From flink-perf with Apache License 2.0 6 votes vote down vote up
/**
 * assumes that batchId starts at 0, and is increasing
 *
 * @param batchId
 * @param collector
 */
@Override
public void emitBatch(long batchId, TridentCollector collector) {
	long id = (batchId-1) * this.batchSize;
	for(int i = 0; i < this.batchSize; i++) {
		if(id % latFreq == nextlat) {
			time = System.currentTimeMillis();
			if(--nextlat <= 0) {
				nextlat = 1000;
			}
		}
		collector.emit(new Values(id, this.host, this.time, this.payload));
		time = 0;
		id++;
	}
}
 
Example 4
Source File: LocalQueueEmitter.java    From storm-example with Apache License 2.0 6 votes vote down vote up
@Override
public void emitBatch(TransactionAttempt tx, Long coordinatorMeta, TridentCollector collector) {
    int size = 0;
    LOG.debug("Getting batch for [" + tx.getTransactionId() + "]");
    while (size <= MAX_BATCH_SIZE) {
        List<Object> values = new ArrayList<Object>();
        try {
            LOG.debug("Waiting on work from [" + this.queueName + "]:[" + getQueue().size() + "]");
            values.add(getQueue().take());
            LOG.debug("Got work from [" + this.queueName + "]:[" + getQueue().size() + "]");
        } catch (InterruptedException ex) {
            // do something smart
        }
        collector.emit(values);
        size++;
    }
    LOG.info("Emitted [" + size + "] elements in [" + tx.getTransactionId() + "], [" + getQueue().size() + "] remain in queue.");
}
 
Example 5
Source File: VectorBuilder.java    From first-stories-twitter with MIT License 5 votes vote down vote up
@Override
public void execute(TridentTuple tuple, TridentCollector collector) {
	Tweet tweet = (Tweet) tuple.getValue(0);
	String tweetBody = tweet.getBody();

       String words[] = tweetBody.toLowerCase().split(regex);
       if (words.length > 0) {
       	collector.emit(getValues(tweet, words));
       } else {
           tweetBody = "ONLYLINKSANDMENTIONZ";
           String dummyWord[] = {tweetBody};
           collector.emit(getValues(tweet, dummyWord));
       }
}
 
Example 6
Source File: TridentFastWordCount.java    From jstorm with Apache License 2.0 5 votes vote down vote up
@Override
public void execute(TridentTuple tuple, TridentCollector collector) {
    String sentence = tuple.getString(0);
    for (String word : sentence.split(" ")) {
        collector.emit(new Values(word));
    }
}
 
Example 7
Source File: ComputeDistance.java    From first-stories-twitter with MIT License 5 votes vote down vote up
@Override
public void execute(TridentTuple tuple, TridentCollector collector) {
	Tweet possibleNeighbour = (Tweet) tuple.getValueByField("coltweet_obj");
	Tweet newTweet = (Tweet) tuple.getValueByField("tweet_obj");
       NearNeighbour possibleClosest = tools.computeCosineSimilarity(possibleNeighbour, newTweet);
       
       collector.emit(new Values(possibleClosest.getCosine()));
}
 
Example 8
Source File: HourAssignment.java    From storm-example with Apache License 2.0 5 votes vote down vote up
@Override
public void execute(TridentTuple tuple, TridentCollector collector) {
    DiagnosisEvent diagnosis = (DiagnosisEvent) tuple.getValue(0);
    String city = (String) tuple.getValue(1);
    long timestamp = diagnosis.time;
    long hourSinceEpoch = timestamp / 1000 / 60 / 60;
    LOG.debug("Key =  [" + city + ":" + hourSinceEpoch + "]");
    String key = city + ":" + diagnosis.diagnosisCode + ":" + hourSinceEpoch;

    List<Object> values = new ArrayList<Object>();
    values.add(hourSinceEpoch);
    values.add(key);
    collector.emit(values);
}
 
Example 9
Source File: WithDefaultValue.java    From trident-tutorial with Apache License 2.0 5 votes vote down vote up
@Override
public void execute(TridentTuple tuple, TridentCollector collector) {
    if(tuple.get(0) == null){
        collector.emit(new Values(t));
    }else{
        collector.emit(new Values(tuple.get(0)));
    }
}
 
Example 10
Source File: Part02_AdvancedPrimitives1.java    From trident-tutorial with Apache License 2.0 5 votes vote down vote up
@Override
public void execute(TridentTuple tuple, TridentCollector collector) {
    Map<String,Integer> val = (Map<String,Integer>)tuple.get(0);
    Map<String,Integer> ret = new HashMap<String, Integer>();
    for (Map.Entry<String, Integer> e : val.entrySet()) {
        ret.put(e.getKey(), e.getValue() * 10);
    }
    collector.emit(new Values(ret));
}
 
Example 11
Source File: OutbreakDetector.java    From storm-example with Apache License 2.0 5 votes vote down vote up
@Override
public void execute(TridentTuple tuple, TridentCollector collector) {
    String key = (String) tuple.getValue(0);
    Long count = (Long) tuple.getValue(1);
    if (count > THRESHOLD) {
        List<Object> values = new ArrayList<Object>();
        values.add("Outbreak detected for [" + key + "]!");
        collector.emit(values);
    }
}
 
Example 12
Source File: DiagnosisEventEmitter.java    From storm-example with Apache License 2.0 5 votes vote down vote up
@Override
public void emitBatch(TransactionAttempt tx, Long coordinatorMeta, TridentCollector collector) {
    for (int i = 0; i < 10000; i++) {
        List<Object> events = new ArrayList<Object>();
        double lat = new Double(-30 + (int) (Math.random() * 75));
        double lng = new Double(-120 + (int) (Math.random() * 70));
        long time = System.currentTimeMillis();

        String diag = new Integer(320 + (int) (Math.random() * 7)).toString();
        DiagnosisEvent event = new DiagnosisEvent(lat, lng, time, diag);
        events.add(event);
        collector.emit(events);
    }
}
 
Example 13
Source File: SnapshotGet.java    From jstorm with Apache License 2.0 4 votes vote down vote up
@Override
public void execute(TridentTuple tuple, Object result, TridentCollector collector) {
    collector.emit(new Values(result));
}
 
Example 14
Source File: StringCounter.java    From trident-tutorial with Apache License 2.0 4 votes vote down vote up
@Override
public void complete(Map<String, Integer> val, TridentCollector collector) {
    System.err.println(String.format("Partition %s out ot %s partitions aggregated:%s", partitionId, numPartitions, val));
    collector.emit(new Values(val));
}
 
Example 15
Source File: ReducerAggregatorImpl.java    From jstorm with Apache License 2.0 4 votes vote down vote up
public void complete(Result val, TridentCollector collector) {
    collector.emit(new Values(val.obj));
}
 
Example 16
Source File: DocumentBuilder.java    From storm-trident-elasticsearch with Apache License 2.0 4 votes vote down vote up
@Override
public void execute(TridentTuple tuple, TridentCollector collector) {
    String sentence = tuple.getString(0);
    collector.emit(new Values( new Document<>("my_index", "my_type", sentence, String.valueOf(sentence.hashCode()))));
}
 
Example 17
Source File: HBaseQuery.java    From storm-hbase with Apache License 2.0 4 votes vote down vote up
@Override
public void execute(TridentTuple tuples, List<Values> values, TridentCollector tridentCollector) {
    for (Values value : values) {
        tridentCollector.emit(value);
    }
}
 
Example 18
Source File: QuerySearchIndexQuery.java    From storm-trident-elasticsearch with Apache License 2.0 4 votes vote down vote up
@Override
public void execute(TridentTuple objects, Collection<T> tl, TridentCollector tridentCollector) {
    for(T t :  tl) tridentCollector.emit( new Values(t));
}
 
Example 19
Source File: IdentityMultiReducer.java    From jstorm with Apache License 2.0 4 votes vote down vote up
@Override
public void execute(Object state, int streamIndex, TridentTuple input, TridentCollector collector) {
    collector.emit(input);
}
 
Example 20
Source File: ComparisonAggregator.java    From jstorm with Apache License 2.0 4 votes vote down vote up
@Override
public void complete(State state, TridentCollector collector) {
    log.debug("Completed comparison aggregation for batch [{}] with resultant tuple: [{}] in operation [{}]", batchId, state.previousTuple, this);

    collector.emit(state.previousTuple != null ? state.previousTuple.getValues() : null);
}