Java Code Examples for backtype.storm.topology.BasicOutputCollector#emit()

The following examples show how to use backtype.storm.topology.BasicOutputCollector#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: SplitRecord.java    From jstorm with Apache License 2.0 6 votes vote down vote up
public void execute(Tuple tuple, BasicOutputCollector collector) {
    tpsCounter.count();
    
    Long tupleId = tuple.getLong(0);
    Object obj = tuple.getValue(1);
    
    if (obj instanceof TradeCustomer) {
        
        TradeCustomer tradeCustomer = (TradeCustomer) obj;
        
        Pair trade = tradeCustomer.getTrade();
        Pair customer = tradeCustomer.getCustomer();
        
        collector.emit(SequenceTopologyDef.TRADE_STREAM_ID, new Values(tupleId, trade));
        
        collector.emit(SequenceTopologyDef.CUSTOMER_STREAM_ID, new Values(tupleId, customer));
    } else if (obj != null) {
        LOG.info("Unknow type " + obj.getClass().getName());
    } else {
        LOG.info("Nullpointer ");
    }
}
 
Example 2
Source File: TransactionalWordsTest.java    From jstorm with Apache License 2.0 6 votes vote down vote up
@Override
public void execute(Tuple tuple, BasicOutputCollector collector) {
    TransactionAttempt attempt = (TransactionAttempt) tuple.getValue(0);
    int curr = tuple.getInteger(2);
    Integer prev = tuple.getInteger(3);

    int currBucket = curr / BUCKET_SIZE;
    Integer prevBucket = null;
    if (prev != null) {
        prevBucket = prev / BUCKET_SIZE;
    }

    if (prevBucket == null) {
        collector.emit(new Values(attempt, currBucket, 1));
    } else if (currBucket != prevBucket) {
        collector.emit(new Values(attempt, currBucket, 1));
        collector.emit(new Values(attempt, prevBucket, -1));
    }
}
 
Example 3
Source File: CheckOrderBolt.java    From storm-kafka-examples with Apache License 2.0 6 votes vote down vote up
@Override
public void execute(Tuple tuple, BasicOutputCollector collector) {
	SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");//设置日期格式
	String nowData = df.format(new Date()); // new Date()为获取当前系统时间,检测是否为最新数据

	String data = tuple.getString(0);
	//订单号		用户id	     原金额	                      优惠价	          标示字段		下单时间
	//id		memberid  	totalprice					preprice		sendpay		createdate
	if(data!=null && data.length()>0) {
		String[] values = data.split("\t");
		if(values.length==6) {
			String id = values[0];
			String memberid = values[1];
			String totalprice = values[2];
			String preprice = values[3];
			String sendpay = values[4];
			String createdate = values[5];
			
			if(StringUtils.isNotEmpty(id)&&StringUtils.isNotEmpty(memberid)&&StringUtils.isNotEmpty(totalprice)) {
				if(DateUtils.isValidDate(createdate, nowData)) {
					collector.emit(new Values(id,memberid,totalprice,preprice,sendpay,createdate));
				}
			}
		}
	}
}
 
Example 4
Source File: AuditLoginsCounterBolt.java    From Kafka-Storm-ElasticSearch with Apache License 2.0 6 votes vote down vote up
public void execute(Tuple input, BasicOutputCollector collector){
  	
  	Map<String,String> auditAttributes = (Map<String, String>) input.getValues().get(0);
  	
  	String host_user = new String(auditAttributes.get("host")).concat("|")
  			.concat(auditAttributes.get("user"));
  	String type = auditAttributes.get("type");
  	int counterValue = getCounterValue(host_user);
  	String document = "{\"counter\": ";
  	    	
  	if (type.equals("USER_LOGIN")){
  		counterValue++;
  		document = document + counterValue + "}";
        	collector.emit(tuple(host_user,index, this.type, document));
  	} else
if (type.equals("USER_LOGOUT") && counterValue > 0){
	counterValue--;
	document = document + counterValue + "}";
	collector.emit(tuple(host_user, index, this.type, document));
}
  }
 
Example 5
Source File: ParseReferrerBolt.java    From aws-big-data-blog with Apache License 2.0 6 votes vote down vote up
@Override
public void execute(Tuple input,  BasicOutputCollector collector) {
    Record record = (Record)input.getValueByField(DefaultKinesisRecordScheme.FIELD_RECORD);
    ByteBuffer buffer = record.getData();
    String data = null; 
    try {
        data = decoder.decode(buffer).toString();
        JSONObject jsonObject = new JSONObject(data);

        String referrer = jsonObject.getString("referrer");

        int firstIndex = referrer.indexOf('.');
        int nextIndex = referrer.indexOf('.',firstIndex+1);
        collector.emit(new Values(referrer.substring(firstIndex+1,nextIndex)));

    } catch (CharacterCodingException|JSONException|IllegalStateException e) {
        LOG.error("Exception when decoding record ", e);
    }
}
 
Example 6
Source File: ReachTopology.java    From jstorm with Apache License 2.0 5 votes vote down vote up
@Override
public void execute(Tuple tuple, BasicOutputCollector collector) {
    Object id = tuple.getValue(0);
    String tweeter = tuple.getString(1);
    List<String> followers = FOLLOWERS_DB.get(tweeter);
    if (followers != null) {
        for (String follower : followers) {
            collector.emit(new Values(id, follower));
        }
    }
}
 
Example 7
Source File: Grep.java    From storm-benchmark with Apache License 2.0 5 votes vote down vote up
@Override
public void execute(Tuple input, BasicOutputCollector collector) {
  String sentence = input.getString(0);
  LOG.debug(String.format("find pattern %s in sentence %s", ptnString, sentence));
  matcher = pattern.matcher(input.getString(0));
  if (matcher.find()) {
    collector.emit(new Values(1));
  }
}
 
Example 8
Source File: SimpleBatchTestSpout.java    From jstorm with Apache License 2.0 5 votes vote down vote up
@Override
public void execute(Tuple tuple, BasicOutputCollector basicOutputCollector) {

    BatchId batchId = (BatchId) tuple.getValue(0);
    if(batchId.getId() > 100)
    {
        JStormUtils.sleepMs(1000);
        return;
    }

    for (int i = 0; i < BATCH_SIZE; i++) {
        long value = random.nextInt(100);
        basicOutputCollector.emit(new Values(batchId, value));
    }
}
 
Example 9
Source File: FastWordCountTopology.java    From eagle with Apache License 2.0 5 votes vote down vote up
@Override
public void execute(Tuple tuple, BasicOutputCollector collector) {
    String sentence = tuple.getString(0);
    for (String word : sentence.split("\\s+")) {
        collector.emit(new Values(word, 1));
    }
}
 
Example 10
Source File: WordCounter.java    From jstorm with Apache License 2.0 5 votes vote down vote up
public void execute(Tuple input, BasicOutputCollector collector) {
    String word = (String) input.getValues().get(0);
    int count = 0;
    if (_counts.containsKey(word)) {
        count = _counts.get(word);
    }
    count++;
    _counts.put(word, count);
    collector.emit(tuple(word, count));
}
 
Example 11
Source File: BatchMetaRebalance.java    From jstorm with Apache License 2.0 5 votes vote down vote up
@Override
public void postCommit(BatchId id, BasicOutputCollector collector) {
	if (isNeedRebalance.get() == true) {
		isNeedRebalance.set(false);
		collector.emit(REBALANCE_STREAM_ID, new Values(id));
		LOG.info("Emit rebalance command");
	}
}
 
Example 12
Source File: TokenizerBolt.java    From senti-storm with Apache License 2.0 5 votes vote down vote up
@Override
public void execute(Tuple tuple, BasicOutputCollector collector) {
  String text = tuple.getStringByField("text");

  List<String> tokens = Tokenizer.tokenize(text);

  if (m_logging) {
    LOG.info("Tweet: \"" + text + "\" Tokenized: " + tokens);
  }

  // Emit new tuples
  collector.emit(new Values(text, tokens));
}
 
Example 13
Source File: CounterBolt.java    From storm-kafka-examples with Apache License 2.0 5 votes vote down vote up
@Override
public void execute(Tuple tuple, BasicOutputCollector collector) {
	List<Object> data = tuple.getValues();

	String id = (String) data.get(0);
	String memberid = (String) data.get(1);
	String totalprice = (String) data.get(2);
	String preprice = (String) data.get(3);
	String sendpay = (String) data.get(4);
	String createdate = (String) data.get(5);
	collector.emit(new Values(id,memberid,totalprice,preprice,sendpay,createdate));
	logger.info("+++++++++++++++++++++++++++++++++Valid+++++++++++++++++++++++++++++++++");
	logger.info("msg = "+data+" ----@-@-@-@-@--------counter = "+(counter++));
	logger.info("+++++++++++++++++++++++++++++++++Valid+++++++++++++++++++++++++++++++++");
}
 
Example 14
Source File: BatchMetaSpout.java    From jstorm with Apache License 2.0 4 votes vote down vote up
public void emitBatch(BatchId batchId, BasicOutputCollector collector) {
	List<MessageExt> msgs = metaClient.fetchOneBatch();
	for (MessageExt msgExt : msgs) {
		collector.emit(new Values(batchId, msgExt));
	}
}
 
Example 15
Source File: FilterBolt.java    From storm-benchmark with Apache License 2.0 4 votes vote down vote up
@Override
public void execute(Tuple input, BasicOutputCollector collector) {
  if (!filter(input, toFilter)) {
    collector.emit(new Values(input.getValue(1)));
  }
}
 
Example 16
Source File: BasicDRPCTopology.java    From jstorm with Apache License 2.0 4 votes vote down vote up
@Override
public void execute(Tuple tuple, BasicOutputCollector collector) {
    String input = tuple.getString(1);
    collector.emit(new Values(tuple.getValue(0), input + "!"));
}
 
Example 17
Source File: WordCounter.java    From flux with Apache License 2.0 4 votes vote down vote up
public void execute(Tuple input, BasicOutputCollector collector) {
    collector.emit(tuple(input.getValues().get(0), 1));
}
 
Example 18
Source File: WordCount.java    From storm-benchmark with Apache License 2.0 4 votes vote down vote up
@Override
public void execute(Tuple input, BasicOutputCollector collector) {
  for (String word : WordSplit.splitSentence(input.getString(0))) {
    collector.emit(new Values(word));
  }
}
 
Example 19
Source File: PairCount.java    From jstorm with Apache License 2.0 3 votes vote down vote up
public void execute(Tuple tuple, BasicOutputCollector collector) {
    tpsCounter.count();
    
    Long tupleId = tuple.getLong(0);
    Pair pair = (Pair) tuple.getValue(1);
    
    sum.addAndGet(pair.getValue());
    
    collector.emit(new Values(tupleId, pair));
}
 
Example 20
Source File: TransformBolt.java    From jstorm with Apache License 2.0 3 votes vote down vote up
@Override
public void execute(Tuple input, BasicOutputCollector collector) {
	BatchId id = (BatchId) input.getValue(0);

	long value = rand.nextInt(100);

	collector.emit(new Values(id, value));

}