本文整理汇总了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));
}
}
}
}
}
示例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();
}
}
示例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));
}
示例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);
}
}
示例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));
}
示例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));
}
}
}
示例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);
}
示例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));
}
}
}
示例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);
}
}
}
示例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));
}
}
示例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());
}
}
示例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 " );
}
}
示例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);
}
}
示例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+++++++++++++++++++++++++++++++++");
}