當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。