Java Code Examples for backtype.storm.tuple.Tuple#getString()
The following examples show how to use
backtype.storm.tuple.Tuple#getString() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SplitSentence.java From ignite-book-code-samples with GNU General Public License v3.0 | 6 votes |
@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)); } } }
Example 2
Source File: UserDefinedWorkerTopology.java From jstorm with Apache License 2.0 | 6 votes |
@Override public void execute(Tuple tuple) { String sourceIp = tuple.getString(1); Integer sourcePort = tuple.getInteger(2); if (differentNode) { if (ip.equals(sourceIp)) { fail(tuple, _collector); return; } else if (port.equals(sourcePort)) { fail(tuple, _collector); return; } _collector.emit(tuple, new Values(tuple.getValue(0), ip, port)); _collector.ack(tuple); return; } else { if (ip.equals(sourceIp) == false) { fail(tuple, _collector); return; } _collector.emit(tuple, new Values(tuple.getValue(0), ip, port)); _collector.ack(tuple); } }
Example 3
Source File: HBaseAuditLogParserBolt.java From eagle with Apache License 2.0 | 6 votes |
@Override public void execute(Tuple input) { String logLine = input.getString(0); try { HBaseAuditLogObject entity = parser.parse(logLine); Map<String, Object> map = new TreeMap<>(); map.put("action", entity.action); map.put("host", entity.host); map.put("status", entity.status); map.put("request", entity.request); map.put("scope", entity.scope); map.put("user", entity.user); map.put("timestamp", entity.timestamp); collector.emit(Collections.singletonList(map)); } catch (Exception ex) { LOG.error("Failing parse and ignore audit log {} ", logLine, ex); } finally { collector.ack(input); } }
Example 4
Source File: TransactionStateTest.java From jstorm with Apache License 2.0 | 6 votes |
@Override public void execute(Tuple input, IKvState<String, Integer> state) { String word = input.getString(0); Integer count = state.get(word); if (count == null) count = 0; state.put(word, ++count); // For performance purpose, you can cache the value first, and then put them into state instance when checkpoint // get value from cache. If not found, try to get value from state instance /*Integer count = cacheCounts.get(word); if (count == null) { count = state.get(word); if (count == null) count = 0; } cacheCounts.put(word, ++count);*/ }
Example 5
Source File: SecurityLogParserBolt.java From eagle with Apache License 2.0 | 6 votes |
@Override public void execute(Tuple tuple) { String logLine = tuple.getString(0); HDFSSecurityLogParser parser = new HDFSSecurityLogParser(); HDFSSecurityLogObject entity = null; try{ entity = parser.parse(logLine); Map<String, Object> map = new TreeMap<>(); map.put("timestamp", entity.timestamp); map.put("allowed", entity.allowed); map.put("user", entity.user); if(LOG.isDebugEnabled()){ LOG.debug("emitted " + map); } // push to Kafka sink ObjectMapper mapper = new ObjectMapper(); String msg = mapper.writeValueAsString(map); collector.emit(Arrays.asList(entity.user, msg)); }catch(Exception ex){ LOG.error("Failing parse security log message, and ignore this message", ex); }finally { collector.ack(tuple); } }
Example 6
Source File: WordCountTopology.java From flink-perf with Apache License 2.0 | 5 votes |
@Override public void execute(Tuple tuple, BasicOutputCollector collector) { String word = tuple.getString(0); Integer count = counts.get(word); if (count == null) count = 0; count++; counts.put(word, count); collector.emit(new Values(word, count)); }
Example 7
Source File: PrepareRequest.java From jstorm with Apache License 2.0 | 5 votes |
@Override public void execute(Tuple tuple, BasicOutputCollector collector) { String args = tuple.getString(0); String returnInfo = tuple.getString(1); long requestId = rand.nextLong(); collector.emit(ARGS_STREAM, new Values(requestId, args)); collector.emit(RETURN_STREAM, new Values(requestId, returnInfo)); collector.emit(ID_STREAM, new Values(requestId)); }
Example 8
Source File: FastWordCountTimeWindowTopology.java From jstorm with Apache License 2.0 | 5 votes |
@Override public void execute(Tuple tuple) { String sentence = tuple.getString(0); for (String word : sentence.split("\\s+")) { collector.emit(new Values(word)); } }
Example 9
Source File: Grep.java From storm-benchmark with Apache License 2.0 | 5 votes |
@Override public void execute(Tuple input, BasicOutputCollector collector) { String sentence = input.getString(0); LOG.debug(String.format("find pattern %s in sentence %s", ptnString, sentence)); matcher = pattern.matcher(input.getString(0)); if (matcher.find()) { collector.emit(new Values(1)); } }
Example 10
Source File: WordCounterBolt.java From storm-camel-example with Apache License 2.0 | 5 votes |
@Override public final void execute(final Tuple tuple, final BasicOutputCollector collector) { final String word = tuple.getString(0); int count = counts.getOrDefault(word, 0); count++; counts.put(word, count); collector.emit(new Values(word, count)); }
Example 11
Source File: TransactionalWordsTest.java From jstorm with Apache License 2.0 | 5 votes |
@Override public void execute(Tuple tuple) { String key = tuple.getString(1); Integer curr = _counts.get(key); if (curr == null) curr = 0; _counts.put(key, curr + 1); }
Example 12
Source File: WordCountTopology.java From jstorm with Apache License 2.0 | 5 votes |
@Override public void execute(Tuple tuple, BasicOutputCollector collector) { String word = tuple.getString(0); Integer count = counts.get(word); if (count == null) count = 0; count++; counts.put(word, count); collector.emit(new Values(word, count)); }
Example 13
Source File: FastWordCountTopNWindowTopology.java From jstorm with Apache License 2.0 | 5 votes |
@Override public void execute(Tuple tuple, Object state, TimeWindow window) { HashMap<String, Integer> counts = (HashMap<String, Integer>) state; String word = tuple.getString(0); Integer count = counts.get(word); if (count == null) count = 0; counts.put(word, ++count); }
Example 14
Source File: FastWordCountWindowTopology.java From jstorm with Apache License 2.0 | 5 votes |
@Override public void execute(Tuple tuple, Object state, TimeWindow window) { Map<String, Integer> counts = (Map<String, Integer>) state; String word = tuple.getString(0); Integer count = counts.get(word); if (count == null) count = 0; counts.put(word, ++count); }
Example 15
Source File: BatchNumberList.java From jstorm with Apache License 2.0 | 5 votes |
@Override public void execute(Tuple tuple) { if (tuple.getSourceComponent().equals(_wordComponent)) { this.word = tuple.getString(1); } else { intSet.add(tuple.getInteger(1)); } }
Example 16
Source File: FastWordCountEventTimeWindowTopology.java From jstorm with Apache License 2.0 | 5 votes |
@Override public void execute(Tuple tuple, Object state, TimeWindow window) { Map<String, Integer> counts = (Map<String, Integer>) state; String word = tuple.getString(0); Integer count = counts.get(word); if (count == null) count = 0; counts.put(word, ++count); }
Example 17
Source File: FastWordCountIngestionTimeWindowTopology.java From jstorm with Apache License 2.0 | 5 votes |
@Override public void execute(Tuple tuple, Object state, TimeWindow window) { Map<String, Integer> counts = (Map<String, Integer>) state; String word = tuple.getString(0); Integer count = counts.get(word); if (count == null) count = 0; counts.put(word, ++count); }
Example 18
Source File: FastWordCountWindowTopology.java From jstorm with Apache License 2.0 | 5 votes |
@Override public void execute(Tuple tuple) { String sentence = tuple.getString(0); for (String word : sentence.split("\\s+")) { collector.emit(new Values(word)); } }
Example 19
Source File: ManualDRPC.java From jstorm with Apache License 2.0 | 4 votes |
@Override public void execute(Tuple tuple, BasicOutputCollector collector) { String arg = tuple.getString(0); Object retInfo = tuple.getValue(1); collector.emit(new Values(arg + "!!!", retInfo)); }
Example 20
Source File: BasicDRPCTopology.java From jstorm with Apache License 2.0 | 4 votes |
@Override public void execute(Tuple tuple, BasicOutputCollector collector) { String input = tuple.getString(1); collector.emit(new Values(tuple.getValue(0), input + "!")); }