Java Code Examples for org.apache.storm.utils.Utils#sleep()
The following examples show how to use
org.apache.storm.utils.Utils#sleep() .
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: BlobStoreAPIWordCountTopology.java From storm-net-adapter with Apache License 2.0 | 6 votes |
public static void main(String[] args) { prepare(); BlobStoreAPIWordCountTopology wc = new BlobStoreAPIWordCountTopology(); try { File file = createFile(fileName); // Creating blob again before launching topology createBlobWithContent(key, store, file); // Blostore launch command with topology blobstore map // Here we are giving it a local name so that we can read from the file // bin/storm jar examples/storm-starter/storm-starter-topologies-0.11.0-SNAPSHOT.jar // org.apache.storm.starter.BlobStoreAPIWordCountTopology bl -c // topology.blobstore.map='{"key":{"localname":"blacklist.txt", "uncompress":"false"}}' wc.buildAndLaunchWordCountTopology(args); // Updating file few times every 5 seconds for (int i = 0; i < 10; i++) { updateBlobWithContent(key, store, updateFile(file)); Utils.sleep(5000); } } catch (KeyAlreadyExistsException kae) { LOG.info("Key already exists {}", kae); } catch (AuthorizationException | KeyNotFoundException | IOException exp) { throw new RuntimeException(exp); } }
Example 2
Source File: ConfigurableTopology.java From storm-crawler with Apache License 2.0 | 6 votes |
/** Submits the topology under a specific name **/ protected int submit(String name, Config conf, TopologyBuilder builder) { // register Metadata for serialization with FieldsSerializer Config.registerSerialization(conf, Metadata.class); if (isLocal) { LocalCluster cluster = new LocalCluster(); cluster.submitTopology(name, conf, builder.createTopology()); if (ttl != -1) { Utils.sleep(ttl * 1000); cluster.shutdown(); } } else { try { StormSubmitter.submitTopology(name, conf, builder.createTopology()); } catch (Exception e) { e.printStackTrace(); return -1; } } return 0; }
Example 3
Source File: MesosSupervisor.java From storm with Apache License 2.0 | 6 votes |
@Override public void run() { try { while (true) { long now = System.currentTimeMillis(); if (!_supervisorViewOfAssignedPorts.get().isEmpty()) { _lastTime = now; } if ((now - _lastTime) > 1000L * _timeoutSecs) { LOG.info("Supervisor has not had anything assigned for {} secs. Committing suicide...", _timeoutSecs); Runtime.getRuntime().halt(0); } Utils.sleep(5000); } } catch (Throwable t) { LOG.error(t.getMessage()); Runtime.getRuntime().halt(2); } }
Example 4
Source File: ClusterSumStormTasksTopology.java From 163-bigdate-note with GNU General Public License v3.0 | 5 votes |
/** * 会产生数据,在生产上是从消息队列中获取数据。这个方法是死循环,会一致不停执行 */ @Override public void nextTuple() { this.collector.emit(new Values(++number)); System.out.println("Spout: " + number); //每隔一秒发送一次,防止太快 Utils.sleep(1000); }
Example 5
Source File: RulesTestSpout.java From streamline with Apache License 2.0 | 5 votes |
@Override public void nextTuple() { Utils.sleep(tupleEmitInterval); final Random rand = new Random(); final Values values = LIST_VALUES.get(rand.nextInt(LIST_VALUES.size())); log.debug("++++++++ Emitting Tuple: [{}]", values); collector.emit(values); Thread.yield(); }
Example 6
Source File: ParserTopologyCLI.java From metron with Apache License 2.0 | 5 votes |
public static void main(String[] args) { try { Options options = new Options(); final CommandLine cmd = parse(options, args); if (cmd.hasOption("h")) { final HelpFormatter usageFormatter = new HelpFormatter(); usageFormatter.printHelp("ParserTopologyCLI", null, options, null, true); System.exit(0); } ParserTopologyCLI cli = new ParserTopologyCLI(); ParserTopologyBuilder.ParserTopology topology = cli.createParserTopology(cmd); String sensorTypes = ParserOptions.SENSOR_TYPES.get(cmd); String topologyName = sensorTypes.replaceAll(TOPOLOGY_OPTION_SEPARATOR, STORM_JOB_SEPARATOR); if (ParserOptions.TEST.has(cmd)) { topology.getTopologyConfig().put(Config.TOPOLOGY_DEBUG, true); LocalCluster cluster = new LocalCluster(); cluster.submitTopology(topologyName, topology.getTopologyConfig(), topology.getBuilder().createTopology()); Utils.sleep(300000); cluster.shutdown(); } else { StormSubmitter.submitTopology(topologyName, topology.getTopologyConfig(), topology.getBuilder().createTopology()); } } catch (Exception e) { e.printStackTrace(); System.exit(-1); } }
Example 7
Source File: GroupByKeyAndWindowExample.java From storm-net-adapter with Apache License 2.0 | 5 votes |
@Override public void nextTuple() { Utils.sleep(5000); for (Values v : values.get(index)) { collector.emit(v); } index = (index + 1) % values.size(); }
Example 8
Source File: RandomNumberSpout.java From tutorials with MIT License | 5 votes |
@Override public void nextTuple() { Utils.sleep(1000); //This will select random int from the range (0, 100) int operation = random.nextInt(101); long timestamp = System.currentTimeMillis(); Values values = new Values(operation, timestamp); collector.emit(values); }
Example 9
Source File: TestWordSpout.java From incubator-heron with Apache License 2.0 | 5 votes |
public void nextTuple() { final String word = words[rand.nextInt(words.length)]; collector.emit(new Values(word)); if (!throttleDuration.isZero()) { Utils.sleep(throttleDuration.toMillis()); // sleep to throttle back CPU usage } }
Example 10
Source File: SentenceSpout.java From java-study with Apache License 2.0 | 5 votes |
/** * nextTuple()方法是任何Spout实现的核心。 * Storm调用这个方法,向输出的collector发出tuple。 * 在这里,我们只是发出当前索引的句子,并增加该索引准备发射下一个句子。 */ public void nextTuple() { //collector.emit(new Values("hello world this is a test")); // TODO Auto-generated method stub this.collector.emit(new Values(sentences[index])); index++; if (index>=sentences.length) { index=0; } Utils.sleep(1); }
Example 11
Source File: TestNameSpout.java From incubator-heron with Apache License 2.0 | 5 votes |
public void nextTuple() { Utils.sleep(100); final String[] words = new String[] {"marge", "homer", "bart", "simpson", "lisa"}; final Random rand = new Random(); final String word = words[rand.nextInt(words.length)]; collector.emit(new Values(word)); }
Example 12
Source File: LocalSumStormTopology.java From 163-bigdate-note with GNU General Public License v3.0 | 5 votes |
/** * 会产生数据,在生产上是从消息队列中获取数据。这个方法是死循环,会一致不停执行 */ @Override public void nextTuple() { this.collector.emit(new Values(++number)); System.out.println("Spout: " + number); //每隔一秒发送一次,防止太快 Utils.sleep(1000); }
Example 13
Source File: ClusterSumFieldGroupingStormTopology.java From 163-bigdate-note with GNU General Public License v3.0 | 5 votes |
/** * 会产生数据,在生产上是从消息队列中获取数据。这个方法是死循环,会一致不停执行 */ @Override public void nextTuple() { this.collector.emit(new Values(number % 2, ++number)); System.out.println("Spout: " + number); //每隔一秒发送一次,防止太快 Utils.sleep(1000); }
Example 14
Source File: NestSpout.java From streamline with Apache License 2.0 | 5 votes |
@Override public void nextTuple() { Utils.sleep(100); long userId = random.nextLong(); long temperature = random.nextLong() % 150L; long evenTime = System.currentTimeMillis(); long longitude = random.nextLong(); long latitude = random.nextLong(); _collector.emit(new Values(new NestMessage(userId, temperature, evenTime, longitude, latitude).serialize())); }
Example 15
Source File: ScrollSpout.java From storm-crawler with Apache License 2.0 | 5 votes |
@Override // simplified version of the super method so that we can store the fields in // the // map of things being processed public void nextTuple() { synchronized (queue) { if (!queue.isEmpty()) { List<Object> fields = queue.remove(); String url = fields.get(0).toString(); _collector.emit(Constants.StatusStreamName, fields, url); beingProcessed.put(url, fields); eventCounter.scope("emitted").incrBy(1); LOG.debug("{} emitted {}", logIdprefix, url); return; } } if (isInQuery.get()) { // sleep for a bit but not too much in order to give ack/fail a // chance Utils.sleep(10); return; } // re-populate the buffer populateBuffer(); }
Example 16
Source File: AbstractQueryingSpout.java From storm-crawler with Apache License 2.0 | 5 votes |
@Override public void nextTuple() { if (!active) return; // force the refresh of the buffer even if the buffer is not empty if (!isInQuery.get() && triggerQueries()) { populateBuffer(); timeLastQuerySent = System.currentTimeMillis(); } if (buffer.hasNext()) { // track how long the buffer had been empty for if (timestampEmptyBuffer != -1) { eventCounter.scope("empty.buffer").incrBy( System.currentTimeMillis() - timestampEmptyBuffer); timestampEmptyBuffer = -1; } List<Object> fields = buffer.next(); String url = fields.get(0).toString(); this._collector.emit(fields, url); beingProcessed.put(url, null); eventCounter.scope("emitted").incrBy(1); return; } else if (timestampEmptyBuffer == -1) { timestampEmptyBuffer = System.currentTimeMillis(); } if (isInQuery.get() || throttleQueries() > 0) { // sleep for a bit but not too much in order to give ack/fail a // chance Utils.sleep(10); return; } // re-populate the buffer populateBuffer(); timeLastQuerySent = System.currentTimeMillis(); }
Example 17
Source File: ASpout.java From chuidiang-ejemplos with GNU Lesser General Public License v3.0 | 4 votes |
@Override public void nextTuple() { Utils.sleep(1000); collector.emit(new Values(System.currentTimeMillis(), counter++)); log.info("Data emitted"); }
Example 18
Source File: BlobStoreAPIWordCountTopology.java From storm-net-adapter with Apache License 2.0 | 4 votes |
@Override public void nextTuple() { Utils.sleep(100); _collector.emit(new Values(getRandomSentence())); }
Example 19
Source File: LogLevelCountTopology.java From nifi-streaming-examples with Apache License 2.0 | 4 votes |
public static void main( String[] args ) throws Exception { String propertiesFile = DEFAULT_PROPERTIES_FILE; if (args != null && args.length == 1 && args[0] != null) { propertiesFile = args[0]; } LogLevelCountProperties props = new LogLevelCountProperties(propertiesFile); int windowMillis = props.getStormWindowMillis(); double rateThreshold = props.getStormRateThreshold(); // Build the spout for pulling data from NiFi and pull out the log level into a tuple field NiFiSpout niFiSpout = new NiFiSpout(getSourceConfig(props), Collections.singletonList(props.getLogLevelAttribute())); // Build the bolt for counting log levels over a tumbling window BaseWindowedBolt logLevelWindowBolt = new LogLevelWindowBolt(props.getLogLevelAttribute()) .withTumblingWindow(new BaseWindowedBolt.Duration(windowMillis, TimeUnit.MILLISECONDS)); // Build the bolt for pushing results back to NiFi NiFiDataPacketBuilder dictionaryBuilder = new DictionaryBuilder(windowMillis, rateThreshold); NiFiBolt niFiBolt = new NiFiBolt(getSinkConfig(props), dictionaryBuilder, 10).withBatchSize(1); // Build the topology of NiFiSpout -> LogLevelWindowBolt -> NiFiBolt TopologyBuilder builder = new TopologyBuilder(); builder.setSpout("nifiInput", niFiSpout); builder.setBolt("logLevels", logLevelWindowBolt).shuffleGrouping("nifiInput"); builder.setBolt("nifiOutput", niFiBolt).shuffleGrouping("logLevels"); // Submit the topology Config conf = new Config(); conf.setDebug(true); // Need to set the message timeout to twice the window size in seconds conf.setMessageTimeoutSecs((props.getStormWindowMillis()/1000) * 2); if (args != null && args.length > 0) { conf.setNumWorkers(3); StormSubmitter.submitTopologyWithProgressBar(args[0], conf, builder.createTopology()); } else { LocalCluster cluster = new LocalCluster(); cluster.submitTopology("log-levels", conf, builder.createTopology()); Utils.sleep(130000); cluster.killTopology("log-levels"); cluster.shutdown(); } }
Example 20
Source File: RandomIntSpout.java From tutorials with MIT License | 4 votes |
@Override public void nextTuple() { Utils.sleep(1000); outputCollector.emit(new Values(random.nextInt(), System.currentTimeMillis())); }