当前位置: 首页>>代码示例>>Java>>正文


Java BasicOutputCollector.emit方法代码示例

本文整理汇总了Java中backtype.storm.topology.BasicOutputCollector.emit方法的典型用法代码示例。如果您正苦于以下问题:Java BasicOutputCollector.emit方法的具体用法?Java BasicOutputCollector.emit怎么用?Java BasicOutputCollector.emit使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在backtype.storm.topology.BasicOutputCollector的用法示例。


在下文中一共展示了BasicOutputCollector.emit方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: execute

import backtype.storm.topology.BasicOutputCollector; //导入方法依赖的package包/类
@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));
				}
			}
		}
	}
}
 
开发者ID:realxujiang,项目名称:storm-kafka-examples,代码行数:27,代码来源:CheckOrderBolt.java

示例2: execute

import backtype.storm.topology.BasicOutputCollector; //导入方法依赖的package包/类
public void execute(Tuple input, BasicOutputCollector collector) {


        try {
            String url = input.getString(0);
            if(url.length() > 10) {
                collector.emit(new Values(url));
                System.out.println(url);
            }else{
                System.err.println("======>loop back====>"+url);
            }
        }catch (Exception ex){
            logger.error("Generate Url error:"+ex);
            ex.printStackTrace();
        }
    }
 
开发者ID:cutoutsy,项目名称:miner,代码行数:17,代码来源:GenerateUrlBolt.java

示例3: execute

import backtype.storm.topology.BasicOutputCollector; //导入方法依赖的package包/类
public void execute(Tuple input, BasicOutputCollector collector) {
    LOGGER.debug("Calculating positive score");

    Long id     = input.getLong(input.fieldIndex("tweet_id"));
    String text = input.getString(input.fieldIndex("tweet_text"));

    Set<String> posWords = PositiveWords.getWords();
    String[] words = text.split(" ");

    int numWords = words.length;
    int numPosWords = 0;

    for (String word : words) {
        if (posWords.contains(word))
            numPosWords++;
    }

    collector.emit(new Values(id, (float) numPosWords / numWords, text));
}
 
开发者ID:mayconbordin,项目名称:erad2016-streamprocessing,代码行数:20,代码来源:PositiveSentimentBolt.java

示例4: execute

import backtype.storm.topology.BasicOutputCollector; //导入方法依赖的package包/类
public void execute(Tuple input, BasicOutputCollector collector) {
    LOGGER.debug("filttering incoming tweets");
    String json = input.getString(0);

    try {
        JsonNode root = mapper.readValue(json, JsonNode.class);

        long id;
        String text;

        if (root.get("lang") != null && "en".equals(root.get("lang").textValue())) {
            if (root.get("id") != null && root.get("text") != null) {
                id   = root.get("id").longValue();
                text = root.get("text").textValue();
                collector.emit(new Values(id, text));
            } else {
                LOGGER.debug("tweet id and/ or text was null");
            }
        } else {
            LOGGER.debug("Ignoring non-english tweet");
        }
    } catch (IOException ex) {
        LOGGER.error("IO error while filtering tweets", ex);
        LOGGER.trace(null, ex);
    }
}
 
开发者ID:mayconbordin,项目名称:erad2016-streamprocessing,代码行数:27,代码来源:TwitterFilterBolt.java

示例5: execute

import backtype.storm.topology.BasicOutputCollector; //导入方法依赖的package包/类
public void execute(Tuple input, BasicOutputCollector collector) {
    LOGGER.debug("Calculating negitive score");

    Long id     = input.getLong(input.fieldIndex("tweet_id"));
    String text = input.getString(input.fieldIndex("tweet_text"));

    Set<String> negWords = NegativeWords.getWords();
    String[] words = text.split(" ");

    int numWords = words.length;
    int numNegWords = 0;
    for (String word : words) {
        if (negWords.contains(word))
            numNegWords++;
    }

    collector.emit(new Values(id, (float) numNegWords / numWords, text));
}
 
开发者ID:mayconbordin,项目名称:erad2016-streamprocessing,代码行数:19,代码来源:NegativeSentimentBolt.java

示例6: execute

import backtype.storm.topology.BasicOutputCollector; //导入方法依赖的package包/类
@Override
public void execute(Tuple tuple, BasicOutputCollector collector) {
  //Get the sentence content from the tuple
  String sentence = tuple.getString(0);
  //An iterator to get each word
  BreakIterator boundary=BreakIterator.getWordInstance();
  //Give the iterator the sentence
  boundary.setText(sentence);
  //Find the beginning first word
  int start=boundary.first();
  //Iterate over each word and emit it to the output stream
  for (int end=boundary.next(); end != BreakIterator.DONE; start=end, end=boundary.next()) {
    //get the word
    String word=sentence.substring(start,end);
    //If a word is whitespace characters, replace it with empty
    word=word.replaceAll("\\s+","");
    //if it's an actual word, emit it
    if (!word.equals("")) {
      collector.emit(new Values(word));
    }
  }
}
 
开发者ID:mbad0la,项目名称:Get-ENVS,代码行数:23,代码来源:SplitSentence.java

示例7: execute

import backtype.storm.topology.BasicOutputCollector; //导入方法依赖的package包/类
@Override
public void execute(Tuple tuple, BasicOutputCollector collector) {
    //Get the word contents from the tuple
    String word = tuple.getString(0);
    //Have we counted any already?
    Integer count = counts.get(word);
    if (count == null)
        count = 0;
    //Increment the count and store it
    count++;
    counts.put(word, count);
    //Emit the word and the current count
    //collector.emit(new Values(IGNITE_FIELD, count));
    TreeMap<String, Integer> words = new TreeMap<>();
    words.put(word,count);

    collector.emit(new Values(words));
    //Log information
    logger.info("Emitting a count of " + count + " for word " + word);
}
 
开发者ID:srecon,项目名称:ignite-book-code-samples,代码行数:21,代码来源:WordCount.java

示例8: execute

import backtype.storm.topology.BasicOutputCollector; //导入方法依赖的package包/类
@Override
public void execute(Tuple tuple, BasicOutputCollector collector) {
    //Get the sentence content from the tuple
    String sentence = tuple.getString(0);
    //An iterator to get each word
    BreakIterator boundary=BreakIterator.getWordInstance();
    //Give the iterator the sentence
    boundary.setText(sentence);
    //Find the beginning first word
    int start=boundary.first();
    //Iterate over each word and emit it to the output stream
    for (int end = boundary.next(); end != BreakIterator.DONE; start=end, end=boundary.next()) {
        //get the word
        String word=sentence.substring(start,end);
        //If a word is whitespace characters, replace it with empty
        word=word.replaceAll("\\s+","");
        //if it's an actual word, emit it
        if (!word.equals("")) {
            collector.emit(new Values(word));
        }
    }
}
 
开发者ID:srecon,项目名称:ignite-book-code-samples,代码行数:23,代码来源:SplitSentence.java

示例9: execute

import backtype.storm.topology.BasicOutputCollector; //导入方法依赖的package包/类
@Override
public void execute(Tuple tuple, BasicOutputCollector basicOutputCollector) {
    String line = (String)tuple.getValue(0);
    if(!line.isEmpty()){
        String[] elements = line.split(",");
        // we are interested in speed and the car registration number
        int speed = Integer.valueOf((elements[1]).trim());
        String car = elements[0];
        if(speed > SPEED_THRESHOLD){
            TreeMap<String, Integer> carValue = new TreeMap<String, Integer>();
            carValue.put(car, speed);
            basicOutputCollector.emit(new Values(carValue));
            LOGGER.info("Speed violation found:"+ car + " speed:" + speed);
        }
    }
}
 
开发者ID:srecon,项目名称:ignite-book-code-samples,代码行数:17,代码来源:SpeedLimitBolt.java

示例10: execute

import backtype.storm.topology.BasicOutputCollector; //导入方法依赖的package包/类
@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));
	}
}
 
开发者ID:songtk,项目名称:learn_jstorm,代码行数:20,代码来源:TransactionalWordsTest.java

示例11: execute

import backtype.storm.topology.BasicOutputCollector; //导入方法依赖的package包/类
@Override
public void execute(Tuple tuple, BasicOutputCollector outputCollector) {
    try {
        Stock stock = (Stock) tuple.getValueByField(FieldNames.STOCK_FIELD);
        Values values = new Values(
                                  stock.getDate(),
                                  stock.getOpen(),
                                  stock.getHigh(),
                                  stock.getLow(),
                                  stock.getClose(),
                                  stock.getVolume(),
                                  stock.getAdjClose(),
                                  stock.getName());
        outputCollector.emit(values);
    } catch (Exception ex) {
        LOG.error(ex.toString(), ex);
        throw new FailedException(ex.toString());
    }
}
 
开发者ID:hkropp,项目名称:storm-hive-streaming-example,代码行数:20,代码来源:FieldEmitBolt.java

示例12: execute

import backtype.storm.topology.BasicOutputCollector; //导入方法依赖的package包/类
@Override
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 " );
    }
	
}
 
开发者ID:zhangjunfang,项目名称:jstorm-0.9.6.3-,代码行数:27,代码来源:SplitRecord.java

示例13: execute

import backtype.storm.topology.BasicOutputCollector; //导入方法依赖的package包/类
@Override
public void execute(Tuple input, BasicOutputCollector collector) {
	String valueByField = input.getString(0);
	System.out.println("field value "+ valueByField);
	String[] split = valueByField.split(",");
	PacketDetailDTO tdrPacketDetailDTO = new PacketDetailDTO();
	tdrPacketDetailDTO.setPhoneNumber(Long.parseLong(split[0]));
	tdrPacketDetailDTO.setBin(Integer.parseInt(split[1]));
	tdrPacketDetailDTO.setBout(Integer.parseInt(split[2]));
	tdrPacketDetailDTO.setTimestamp(Long.parseLong(split[3]));

	collector.emit("tdrstream", new Values(tdrPacketDetailDTO));
}
 
开发者ID:PacktPublishing,项目名称:Practical-Real-time-Processing-and-Analytics,代码行数:14,代码来源:ParserBolt.java

示例14: execute

import backtype.storm.topology.BasicOutputCollector; //导入方法依赖的package包/类
public void execute(Tuple input, BasicOutputCollector collector) {
    total = total.add(new BigInteger(input.getValues().get(1).toString()));
    collector.emit(tuple(total.toString()));
    //prints the total with low probability.
    if(RANDOM.nextInt(1000) > 995) {
        LOG.info("Running total = " + total);
    }
}
 
开发者ID:mengzhiyi,项目名称:storm-hbase-1.0.x,代码行数:9,代码来源:TotalWordCounter.java

示例15: execute

import backtype.storm.topology.BasicOutputCollector; //导入方法依赖的package包/类
@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+" [email protected]@[email protected]@[email protected] = "+(counter++));
	logger.info("+++++++++++++++++++++++++++++++++Valid+++++++++++++++++++++++++++++++++");
}
 
开发者ID:realxujiang,项目名称:storm-kafka-examples,代码行数:16,代码来源:CounterBolt.java


注:本文中的backtype.storm.topology.BasicOutputCollector.emit方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。