本文整理汇总了Java中backtype.storm.tuple.Values类的典型用法代码示例。如果您正苦于以下问题:Java Values类的具体用法?Java Values怎么用?Java Values使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Values类属于backtype.storm.tuple包,在下文中一共展示了Values类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: nextTuple
import backtype.storm.tuple.Values; //导入依赖的package包/类
public void nextTuple() {
Map<String, Integer> topicCountMap = new HashMap<String, Integer>();
topicCountMap.put(TopologyConfig.kafkaTopic, 1);//one excutor - one thread
Map<String, List<KafkaStream<byte[], byte[]>>> consumerMap = conn.createMessageStreams(topicCountMap);
List<KafkaStream<byte[], byte[]>> streams = consumerMap.get(kafkaTopic);
ConsumerIterator<byte[], byte[]> iter = streams.get(0).iterator();
while(true){
while(iter.hasNext()){
String s = new String(iter.next().message());
collector.emit(new Values(s));
UUID msgId = UUID.randomUUID();
this.pending.put(msgId, new Values(s));
}
try {
Thread.sleep(1000L);
} catch (InterruptedException e) {
logger.error("Spout : sleep wrong \n", e);
}
}
}
示例2: execute
import backtype.storm.tuple.Values; //导入依赖的package包/类
/**
* <p>This function get the radius client from radius event.</p>
* @author Andres Gomez
*/
@Override
public void execute(TridentTuple tuple, TridentCollector collector) {
Map<String, Object> radiusData = (Map<String, Object>) tuple.getValue(0);
String clientMac = radiusData.get("Calling-Station-Id").toString();
clientMac = clientMac.replace("-", ":");
Map<String, Object> radiusMap = new HashMap<>();
radiusMap.put("client_mac", clientMac);
if (_debug) {
System.out.println(GetRadiusClient.class +" - Radius client to query: " + clientMac);
}
collector.emit(new Values(radiusMap));
}
示例3: execute
import backtype.storm.tuple.Values; //导入依赖的package包/类
/**
* <p>This function converts a JSON events to JAVA Map.</p>
*/
@Override
public void execute(TridentTuple tuple, TridentCollector collector) {
String jsonEvent = tuple.getString(0);
if (jsonEvent != null && jsonEvent.length() > 0) {
Map<String, Object> event = null;
try {
event = _mapper.readValue(jsonEvent, Map.class);
_metric.incrEvent();
} catch (IOException | NullPointerException ex) {
Logger.getLogger(MapperFunction.class.getName()).log(Level.SEVERE, "Failed converting a JSON tuple to a Map class [ " + _metricName + " ] \n"
+ " JSON tuple: " + jsonEvent, ex);
}
if (event != null)
collector.emit(new Values(event));
}
}
示例4: execute
import backtype.storm.tuple.Values; //导入依赖的package包/类
@Override
public void execute(TridentTuple tuple, TridentCollector collector) {
Map<String , Object> mseData = (Map<String, Object>) tuple.get(0);
List<Map<String, Object>> notifications = (List<Map<String, Object>>) mseData.get("notifications");
for (Map<String, Object> notification : notifications){
if(notification.get("notificationType").equals("association")){
logger.fine("Mse10 event this event is a association, emitting: [" + notification.size() + ", " + "null]");
collector.emit(new Values(notification, null));
}else if(notification.get("notificationType").equals("locationupdate")){
logger.fine("Mse10 event this event is a locationupdate, emitting: [null" + ", " + notification.size() + "]");
collector.emit(new Values(null, notification));
}else{
Logger.getLogger(SplitMSE10Data.class.getName()).log(Level.WARNING, "MSE version 10 notificationType is unknown: " + notification.get("notificationType"));
}
}
}
示例5: makeState
import backtype.storm.tuple.Values; //导入依赖的package包/类
@Override
public State makeState(Map conf, IMetricsContext context, int partitionIndex, int numPartitions) {
MemcachedState s;
try {
s = new MemcachedState(makeMemcachedClient(_opts, _servers), _opts, _ser);
} catch (UnknownHostException e) {
throw new RuntimeException(e);
}
// s.registerMetrics(conf, context);
CachedMap c = new CachedMap(s, _opts.localCacheSize);
MapState ms;
if(_type == StateType.NON_TRANSACTIONAL) {
ms = NonTransactionalMap.build(c);
} else if(_type==StateType.OPAQUE) {
ms = OpaqueMap.build(c);
} else if(_type==StateType.TRANSACTIONAL){
ms = TransactionalMap.build(c);
} else {
throw new RuntimeException("Unknown state type: " + _type);
}
return new SnapshottableMap(ms, new Values(_opts.globalKey));
}
示例6: execute
import backtype.storm.tuple.Values; //导入依赖的package包/类
@Override
public void execute(TridentTuple tuple, Map<String, Object> result, TridentCollector collector) {
if (result == null) {
Map<String, Object> empty = new HashMap<>();
collector.emit(new Values(empty));
} else {
result.remove("client_rssi");
result.remove("client_rssi_num");
result.remove("client_snr");
result.remove("client_snr_num");
result.remove("dot11_status");
result.remove("wireless_id");
collector.emit(new Values(result));
}
}
示例7: execute
import backtype.storm.tuple.Values; //导入依赖的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));
}
示例8: execute
import backtype.storm.tuple.Values; //导入依赖的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);
}
示例9: execute
import backtype.storm.tuple.Values; //导入依赖的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));
}
}
}
示例10: execute
import backtype.storm.tuple.Values; //导入依赖的package包/类
@Override
public void execute(Tuple input) {
LOG.info("About to process tuple[" + input + "]");
List<Property> properties = new ArrayList<Property>();
TruliaParser tp = new TruliaParser();
// Process tuple by splitting into individual rows
String rssfeed = input.getString(0);
properties = tp.processRSS(rssfeed);
for(Property prop : properties) {
outputCollector.emit(new Values(prop.getTitle(),
prop.getLink(),
prop.getDescription(),
prop.getPubDate(),
prop.getThumbnail()));
}
outputCollector.ack(input);
}
示例11: batchRetrieve
import backtype.storm.tuple.Values; //导入依赖的package包/类
public List<List<Values>> batchRetrieve(List<TridentTuple> tridentTuples) {
List<List<Values>> batchRetrieveResult = Lists.newArrayList();
List<Get> gets = Lists.newArrayList();
for (TridentTuple tuple : tridentTuples) {
byte[] rowKey = options.mapper.rowKey(tuple);
gets.add(hBaseClient.constructGetRequests(rowKey, options.projectionCriteria));
}
try {
Result[] results = hBaseClient.batchGet(gets);
for(Result result : results) {
List<Values> values = options.rowToStormValueMapper.toValues(result);
batchRetrieveResult.add(values);
}
} catch (Exception e) {
LOG.warn("Batch get operation failed. Triggering replay.", e);
throw new FailedException(e);
}
return batchRetrieveResult;
}
示例12: execute
import backtype.storm.tuple.Values; //导入依赖的package包/类
@Override
public void execute(Tuple input) {
LOG.info("About to process tuple[" + input + "]");
String sentence = input.getString(0);
String[] words = sentence.split(" ");
for(String word: words) {
word = word.trim();
if(!word.isEmpty()) {
word = word.toLowerCase();
outputCollector.emit(new Values(word));
}
}
outputCollector.ack(input);
}
示例13: nextTuple
import backtype.storm.tuple.Values; //导入依赖的package包/类
public void nextTuple() {
if (bufferQueue.isEmpty()) {
// pass in mysql server, db name, user, password
seedBufferQueue("localhost", "test", "root", "");
Utils.sleep(100);
} else {
// Replace name with the data being extracted.
// This example expects only name to be returned in the sql/and thus is only item output by the spout.
// To add additional data add them to the values using new Values(value1, value2, etc) then emit the values
String name = bufferQueue.poll();
if (name != null) {
Values values = new Values();
values.add(name);
_collector.emit(values);
}
Utils.sleep(50);
}
}
示例14: consumeMessage
import backtype.storm.tuple.Values; //导入依赖的package包/类
@Override
public ConsumeConcurrentlyStatus consumeMessage(List<MessageExt> msgs, ConsumeConcurrentlyContext context) {
for (MessageExt msg : msgs) {
byte[] body = msg.getBody();
if (body.length == 2 && body[0] == 0 && body[1] == 0) {
LOG.error("Young:Got the end signal");
_collector.emit("stop",new Values("stop"));
continue;
}
if (msg.getTopic().equals(RaceConfig.MqPayTopic)) {
return doPayTopic(body);
}else if (msg.getTopic().equals(RaceConfig.MqTaobaoTradeTopic)) {
putTaobaoTradeToTair(body);
return ConsumeConcurrentlyStatus.CONSUME_SUCCESS;
} else if (msg.getTopic().equals(RaceConfig.MqTmallTradeTopic)) {
putTmallTradeToTair(body);
return ConsumeConcurrentlyStatus.CONSUME_SUCCESS;
}else {
return ConsumeConcurrentlyStatus.RECONSUME_LATER;
}
}
return ConsumeConcurrentlyStatus.CONSUME_SUCCESS;
}
示例15: execute
import backtype.storm.tuple.Values; //导入依赖的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));
}
}
}
}
}