本文整理汇总了Java中org.apache.storm.tuple.Tuple.getStringByField方法的典型用法代码示例。如果您正苦于以下问题:Java Tuple.getStringByField方法的具体用法?Java Tuple.getStringByField怎么用?Java Tuple.getStringByField使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.storm.tuple.Tuple
的用法示例。
在下文中一共展示了Tuple.getStringByField方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: execute
import org.apache.storm.tuple.Tuple; //导入方法依赖的package包/类
public void execute(Tuple tuple) {
final String word = tuple.getStringByField(Constraints.wordFileds);
Integer count = tuple.getIntegerByField(Constraints.coinCountFileds);
predictorHotKeyUtil.PredictorHotKey(word,count);
if(predictorHotKeyUtil.isHotKey(word))
collector.emit(new Values(word,1));
predictorHotKeyUtil.SynopsisHashMapRandomDump(new DumpRemoveHandler() {
@Override
public void dumpRemove(String key) {
collector.emit(new Values(word,1));
}
});
collector.ack(tuple);
}
示例2: handle
import org.apache.storm.tuple.Tuple; //导入方法依赖的package包/类
@Override
public void handle(Tuple tuple) {
EmitData data = (EmitData) tuple.getValueByField(Constants.EmitFields.DATA);
List<PairWrapper<String, Object>> wrapperList = data.get(EmitData.MESSAGE);
if (wrapperList != null && !wrapperList.isEmpty()) {
for (PairWrapper<String, Object> wrapper : wrapperList) {
HeartbeatPulse pulse = HeartbeatPulse.build(wrapper.pairs2map());
if (logger.isDebugEnabled()) {
Object offset = data.get(EmitData.OFFSET);
HeartBeatPacket packet = HeartBeatPacket.parse(pulse.getPacket());
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
String groupId = tuple.getStringByField(Constants.EmitFields.GROUP_FIELD);
logger.debug("[heartbeat] {} offset:{} ts:{}, time:{}", groupId, offset == null ? -1 : offset, packet.getTxtime(), format.format(new Date(packet.getTxtime())));
}
reporter.mark(pulse);
}
}
handler.handle(tuple);
this.listener.getOutputCollector().ack(tuple);
}
示例3: execute
import org.apache.storm.tuple.Tuple; //导入方法依赖的package包/类
public void execute(Tuple tuple) {
if(tuple.getSourceComponent().equals(UPSTREAM_COMPONENT_ID)){
String word = tuple.getStringByField(UPSTREAM_FIEDLS);
if(word.length() <= 0) {
collector.ack(tuple);
return;
}
collector.emit(Constraints.coinFileds, new Values(word));
Key ky = new Key(word.getBytes());
if(bf.membershipTest(ky))
collector.emit(Constraints.hotFileds, tuple, new Values(word));
else
collector.emit(Constraints.nohotFileds, tuple, new Values(word));
}else {
String key = tuple.getStringByField(Constraints.wordFileds);
Integer type = tuple.getIntegerByField(Constraints.typeFileds);
Key hk = new Key(key.getBytes());
if(!bf.membershipTest(hk) && type.equals(1))
bf.add(hk);
if(bf.membershipTest(hk) && type.equals(0))
bf.delete(hk);
}
collector.ack(tuple);
}
示例4: getResultofMax
import org.apache.storm.tuple.Tuple; //导入方法依赖的package包/类
/**
* 聚合函数 max 计算结果
*@param isJoin 是否含有join
* @param tupleList 属于某一个组的tuple list
* @param parameter max(tab1.A) 参数值,目前仅支持一个参数
* @return 该组tuple max 函数的执行结果
*/
private int getResultofMax(boolean isJoin, List<Tuple> tupleList, TCItem parameter) {
int maxRes = Integer.MIN_VALUE;
for (Tuple tuple : tupleList) {
String tempKey = parameter.getTableName() + "." + parameter.getColName();
if (!isJoin) {
tempKey = parameter.getColName();
}
String tValStr = tuple.getStringByField(tempKey);
if (!tValStr.isEmpty()) {
int tVal = Integer.valueOf(tValStr);
maxRes = Math.max(maxRes, tVal);
}
}
return maxRes;
}
示例5: execute
import org.apache.storm.tuple.Tuple; //导入方法依赖的package包/类
@Override
public void execute(Tuple tuple) {
boltstatus++;
String word = tuple.getStringByField(Constraints.wordFileds);
if (!word.isEmpty()) {
Long count = counts.get(word);
if (count == null) {
count = 0L;
}
count++;
counts.put(word, count);
outputCollector.emit(tuple,new Values(word,count));
}
outputCollector.ack(tuple);
}
示例6: execute
import org.apache.storm.tuple.Tuple; //导入方法依赖的package包/类
public void execute(Tuple tuple) {
String word = tuple.getStringByField("word");
Long count = this.counts.get(word);
if (count == null) {
count = 0L;
}
count++;
this.counts.put(word, count);
this.collector.emit(new Values(word, count));
}
开发者ID:PacktPublishing,项目名称:Practical-Real-time-Processing-and-Analytics,代码行数:11,代码来源:WordCountBolt.java
示例7: execute
import org.apache.storm.tuple.Tuple; //导入方法依赖的package包/类
public void execute(Tuple tuple) {
String sentence = tuple.getStringByField("sentence");
String[] words = sentence.split(" ");
for (String word : words) {
this.collector.emit(new Values(word));
}
}
开发者ID:PacktPublishing,项目名称:Practical-Real-time-Processing-and-Analytics,代码行数:8,代码来源:SplitSentenceBolt.java
示例8: execute
import org.apache.storm.tuple.Tuple; //导入方法依赖的package包/类
@Override
public void execute(Tuple tuple) {
String url = tuple.getStringByField("url");
Metadata metadata = (Metadata) tuple.getValueByField("metadata");
System.out.println("DummyIndexer %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% set to FETCHED url: " + url);
_collector.emit(
com.digitalpebble.stormcrawler.Constants.StatusStreamName,
tuple, new Values(url, metadata, Status.FETCHED));
_collector.ack(tuple);
}
示例9: getTopic
import org.apache.storm.tuple.Tuple; //导入方法依赖的package包/类
@Override
public String getTopic(Tuple tuple) {
if (tuple.contains(fieldName)) {
return tuple.getStringByField(fieldName);
} else {
LOG.warn("Field {} Not Found. Returning default topic {}", fieldName, defaultTopicName);
return defaultTopicName;
}
}
示例10: doSimulatorCommand
import org.apache.storm.tuple.Tuple; //导入方法依赖的package包/类
public void doSimulatorCommand(Tuple tuple) throws Exception {
List<Values> values = new ArrayList<>();
if (tuple.getFields().contains("command")) {
String command = tuple.getStringByField("command");
switch (command) {
case SimulatorCommands.DO_ADD_SWITCH:
//TODO: this is an ugly hack...
if (tuple.getValueByField("data") instanceof AddSwitchCommand) {
values = addSwitch((AddSwitchCommand) tuple.getValueByField("data"));
} else {
values = addSwitch((SwitchMessage) tuple.getValueByField("data"));
}
break;
case SimulatorCommands.DO_ADD_LINK:
values = addLink((AddLinkCommandMessage) tuple.getValueByField("data"));
break;
case SimulatorCommands.DO_PORT_MOD:
values = modPort((PortModMessage) tuple.getValueByField("data"));
break;
default:
logger.error(String.format("Uknown SimulatorCommand %s", command));
}
} else {
SimulatorMessage message = (SimulatorMessage) tuple.getValueByField("data");
if (message instanceof SwitchModMessage) {
SwitchModMessage switchModMessage = (SwitchModMessage) message;
ISwitchImpl sw = getSwitch(switchModMessage.getDpid());
// sw.mod(switchModMessage.getState());
} else {
logger.error("Unkown SimulatorMessage {}", message.getClass().getSimpleName());
}
}
if (values.size() > 0) {
for (Values value : values) {
logger.debug("emitting: {}", value);
collector.emit(SimulatorTopology.KAFKA_BOLT_STREAM, tuple, value);
}
}
}
示例11: handle
import org.apache.storm.tuple.Tuple; //导入方法依赖的package包/类
@Override
public void handle(Tuple tuple) {
EmitData data = (EmitData) tuple.getValueByField(Constants.EmitFields.DATA);
String groupId = tuple.getStringByField(Constants.EmitFields.GROUP_FIELD);
this.emitHeartbeat(listener.getOutputCollector(), tuple, groupId, data, Command.HEART_BEAT);
if(logger.isDebugEnabled()) {
Object offset = data.get(EmitData.OFFSET);
logger.debug("[heartbeat] {} {} offset:{}", listener.getClass().getSimpleName(), groupId, offset == null ? -1 : offset);
}
}
示例12: execute
import org.apache.storm.tuple.Tuple; //导入方法依赖的package包/类
@Override
public void execute(Tuple input, BasicOutputCollector collector) {
String sentence = input.getStringByField("value");
for(int i=0;i<sentence.length();i++){
char word = sentence.charAt(i);
collector.emit(new Values(word+""));//分词emit,只有1个单词的元组Tuple
}
}
示例13: execute
import org.apache.storm.tuple.Tuple; //导入方法依赖的package包/类
public void execute(Tuple tuple) {
String word = tuple.getStringByField("word");
Long count = tuple.getLongByField("count");
this.counts.put(word, count);
}
开发者ID:PacktPublishing,项目名称:Practical-Real-time-Processing-and-Analytics,代码行数:6,代码来源:DisplayBolt.java
示例14: afterBulk
import org.apache.storm.tuple.Tuple; //导入方法依赖的package包/类
@Override
public void afterBulk(long executionId, BulkRequest request,
BulkResponse response) {
LOG.debug("afterBulk [{}] with {} responses", executionId,
request.numberOfActions());
long msec = response.getTookInMillis();
eventCounter.scope("bulks_received").incrBy(1);
eventCounter.scope("bulk_msec").incrBy(msec);
Iterator<BulkItemResponse> bulkitemiterator = response.iterator();
int itemcount = 0;
int acked = 0;
synchronized (waitAck) {
while (bulkitemiterator.hasNext()) {
BulkItemResponse bir = bulkitemiterator.next();
itemcount++;
String id = bir.getId();
List<Tuple> xx = waitAck.getIfPresent(id);
if (xx != null) {
LOG.debug("Acked {} tuple(s) for ID {}", xx.size(), id);
for (Tuple x : xx) {
acked++;
// ack and put in cache
super.ack(x, x.getStringByField("url"));
}
waitAck.invalidate(id);
} else {
LOG.warn("Could not find unacked tuple for {}", id);
}
}
LOG.info("Bulk response [{}] : items {}, waitAck {}, acked {}",
executionId, itemcount, waitAck.size(), acked);
if (waitAck.size() > 0 && LOG.isDebugEnabled()) {
for (String kinaw : waitAck.asMap().keySet()) {
LOG.debug(
"Still in wait ack after bulk response [{}] => {}",
executionId, kinaw);
}
}
}
}
示例15: create
import org.apache.storm.tuple.Tuple; //导入方法依赖的package包/类
/**
* Create an item. Queue id will be created based on
* <code>queueMode</code> argument, either as a protocol + hostname
* pair, protocol + IP address pair or protocol+domain pair.
*/
public static FetchItem create(URL u, Tuple t, String queueMode) {
String queueID;
String url = u.toExternalForm();
String key = null;
// reuse any key that might have been given
// be it the hostname, domain or IP
if (t.contains("key")) {
key = t.getStringByField("key");
}
if (StringUtils.isNotBlank(key)) {
queueID = key.toLowerCase(Locale.ROOT);
return new FetchItem(url, u, t, queueID);
}
if (FetchItemQueues.QUEUE_MODE_IP.equalsIgnoreCase(queueMode)) {
try {
final InetAddress addr = InetAddress.getByName(u.getHost());
key = addr.getHostAddress();
} catch (final UnknownHostException e) {
LOG.warn(
"Unable to resolve IP for {}, using hostname as key.",
u.getHost());
key = u.getHost();
}
} else if (FetchItemQueues.QUEUE_MODE_DOMAIN
.equalsIgnoreCase(queueMode)) {
key = PaidLevelDomain.getPLD(u.getHost());
if (key == null) {
LOG.warn(
"Unknown domain for url: {}, using hostname as key",
url);
key = u.getHost();
}
} else {
key = u.getHost();
}
if (key == null) {
LOG.warn("Unknown host for url: {}, using URL string as key",
url);
key = u.toExternalForm();
}
queueID = key.toLowerCase(Locale.ROOT);
return new FetchItem(url, u, t, queueID);
}