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


Java BasicOutputCollector类代码示例

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


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

示例1: execute

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

    _collector = collector;

    if (isTickTuple(input)) {
        tickTupleCase();
    } else {
        try {
            this.rawJson = input.getStringByField("map");
            this.json = mapper.readValue(input.getStringByField("map"),new TypeReference<Map<String, Object>>() {});
            this.userexecute();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
 
开发者ID:telefonicaid,项目名称:fiware-sinfonier,代码行数:18,代码来源:BaseSinfonierBolt.java

示例2: execute

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

    _collector = collector;

    if (isTickTuple(input)) {
        tickTupleCase();
    } else {
        try {
            this.rawJson = input.getStringByField("map");
            this.json = mapper.readValue(rawJson, new TypeReference<Map<String, Object>>() {});
            this.userexecute();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
 
开发者ID:telefonicaid,项目名称:fiware-sinfonier,代码行数:18,代码来源:BaseSinfonierDrain.java

示例3: 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

示例4: 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

示例5: 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

示例6: 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

示例7: execute

import backtype.storm.topology.BasicOutputCollector; //导入依赖的package包/类
public void execute(Tuple input, BasicOutputCollector collector) {
    Long id      = input.getLong(input.fieldIndex("tweet_id"));
    String tweet = input.getString(input.fieldIndex("tweet_text"));
    Float pos    = input.getFloat(input.fieldIndex("pos_score"));
    Float neg    = input.getFloat(input.fieldIndex("neg_score"));
    String score = input.getString(input.fieldIndex("score"));

    HttpPost post = new HttpPost(this.webserver);
    String content = String.format(
        "{\"id\": \"%d\", "  +
        "\"text\": \"%s\", " +
        "\"pos\": \"%f\", "  +
        "\"neg\": \"%f\", "  +
        "\"score\": \"%s\" }",
        id, tweet, pos, neg, score);

    try {
        post.setEntity(new StringEntity(content));
        HttpResponse response = client.execute(post);
        org.apache.http.util.EntityUtils.consume(response.getEntity());
    } catch (Exception ex) {
        LOGGER.error("exception thrown while attempting post", ex);
        LOGGER.trace(null, ex);
        reconnect();
    }
}
 
开发者ID:mayconbordin,项目名称:erad2016-streamprocessing,代码行数:27,代码来源:NodeNotifierBolt.java

示例8: 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

示例9: 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

示例10: 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

示例11: 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

示例12: 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

示例13: execute

import backtype.storm.topology.BasicOutputCollector; //导入依赖的package包/类
@Override
public void execute(Tuple tuple, BasicOutputCollector collector) {
    TransactionAttempt attempt = (TransactionAttempt) tuple.getValue(0);

    if(tuple.getSourceStreamId().equals(MasterBatchCoordinator.SUCCESS_STREAM_ID)) {
        _state.cleanupBefore(attempt.getTransactionId());
        _coord.success(attempt.getTransactionId());
    } else if (tuple.getSourceStreamId().equals(MasterBatchCoordinator.COMMIT_STREAM_ID)) { 
    	// Do nothing.
    } else {
        long txid = attempt.getTransactionId();
        Object prevMeta = _state.getPreviousState(txid);
        Object meta = _coord.initializeTransaction(txid, prevMeta, _state.getState(txid));
        _state.overrideState(txid, meta);
        collector.emit(MasterBatchCoordinator.BATCH_STREAM_ID, new Values(attempt, meta));
    }
            
}
 
开发者ID:greeenSY,项目名称:Tstream,代码行数:19,代码来源:TridentSpoutCoordinator.java

示例14: testExecute

import backtype.storm.topology.BasicOutputCollector; //导入依赖的package包/类
@Test
public void testExecute(
        @Injectable Tuple input,
        @Injectable BasicOutputCollector collector,
        @Injectable LogRecord logRecord) throws Exception {

    bolt.esJsonField = "field";

    new Expectations(bolt) {{
        input.getValueByField(AbstractLogRecordBolt.RECORD);
        result = logRecord;
        bolt.indexRecord(logRecord);
        logRecord.getValue(bolt.esJsonField);
        result = "value";

        collector.emit(new Values(logRecord));
        collector.emit(ElasticSearchJsonBolt.ES_JSON, new Values("value"));
    }};
    bolt.execute(input, collector);
}
 
开发者ID:boozallen,项目名称:cognition,代码行数:21,代码来源:ElasticSearchJsonBoltTest.java

示例15: execute

import backtype.storm.topology.BasicOutputCollector; //导入依赖的package包/类
@Override
public void execute(Tuple tuple, BasicOutputCollector outputCollector) {
    Fields fields = tuple.getFields();
    try {
        String stockDataStr = new String((byte[]) tuple.getValueByField(fields.get(0)), "UTF-8");
        String[] stockData = stockDataStr.split(",");
        Values values = new Values(df.parse(stockData[0]), Float.parseFloat(stockData[1]),
                Float.parseFloat(stockData[2]), Float.parseFloat(stockData[3]),
                Float.parseFloat(stockData[4]), Integer.parseInt(stockData[5]),
                Float.parseFloat(stockData[6]), stockData[7]);
        outputCollector.emit(values);
    } catch (UnsupportedEncodingException | ParseException ex) {
        Logger.getLogger(Topology.class.getName()).log(Level.SEVERE, null, ex);
        throw new FailedException(ex.toString());
    }
}
 
开发者ID:hkropp,项目名称:storm-hive-streaming-example,代码行数:17,代码来源:StockDataBolt.java


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