本文整理汇总了Java中org.apache.storm.topology.base.BaseWindowedBolt类的典型用法代码示例。如果您正苦于以下问题:Java BaseWindowedBolt类的具体用法?Java BaseWindowedBolt怎么用?Java BaseWindowedBolt使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
BaseWindowedBolt类属于org.apache.storm.topology.base包,在下文中一共展示了BaseWindowedBolt类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getSpeedTopolgy
import org.apache.storm.topology.base.BaseWindowedBolt; //导入依赖的package包/类
/**
* @return the topology to run
*/
protected StormTopology getSpeedTopolgy() {
final TopologyBuilder tp = new TopologyBuilder();
// consume from the truck_speed_events topic
tp.setSpout("kafka_spout", new KafkaSpout<>(getKafkaSpoutConfig()), 1);
// parse pipe-delimited speed events into a POJO
tp.setBolt("parse_speed_event", new ParseSpeedEventBolt())
.shuffleGrouping("kafka_spout");
// calculate the average speed for driver-route over a 10 second window
tp.setBolt("average_speed", new AverageSpeedBolt().withTumblingWindow(new BaseWindowedBolt.Duration(WINDOW_SIZE_MS, TimeUnit.MILLISECONDS)))
.shuffleGrouping("parse_speed_event");
//new Fields(ParseSpeedEventBolt.FIELD_DRIVER_ID, ParseSpeedEventBolt.FIELD_ROUTE_ID));
// send results back to Kafka results topic
tp.setBolt("kakfa_bolt", getKafkaBolt())
.shuffleGrouping("average_speed");
return tp.createTopology();
}
示例2: main
import org.apache.storm.topology.base.BaseWindowedBolt; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
TopologyBuilder builder = new TopologyBuilder();
builder.setSpout("integer", new RandomIntegerSpout(), 1);
builder.setBolt("slidingsum", new SlidingWindowSumBolt()
.withWindow(BaseWindowedBolt.Count.of(30), BaseWindowedBolt.Count.of(10)), 1)
.shuffleGrouping("integer");
builder.setBolt("tumblingavg", new TumblingWindowAvgBolt()
.withTumblingWindow(BaseWindowedBolt.Count.of(3)), 1)
.shuffleGrouping("slidingsum");
builder.setBolt("printer", new PrinterBolt(), 1)
.shuffleGrouping("tumblingavg");
Config conf = new Config();
conf.setDebug(true);
String topoName = "test";
if (args != null && args.length > 0) {
topoName = args[0];
}
StormSubmitter.submitTopology(topoName, conf, builder.createTopology());
}
示例3: main
import org.apache.storm.topology.base.BaseWindowedBolt; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
Config conf = new Config();
WindowsStoreFactory mapState = new InMemoryWindowsStoreFactory();
if (args.length == 0) {
List<? extends WindowConfig> list = Arrays.asList(
SlidingCountWindow.of(1000, 100)
,TumblingCountWindow.of(1000)
,SlidingDurationWindow.of(new BaseWindowedBolt.Duration(6, TimeUnit.SECONDS), new BaseWindowedBolt.Duration(3, TimeUnit.SECONDS))
,TumblingDurationWindow.of(new BaseWindowedBolt.Duration(3, TimeUnit.SECONDS))
);
for (WindowConfig windowConfig : list) {
LocalCluster cluster = new LocalCluster();
cluster.submitTopology("wordCounter", conf, buildTopology(mapState, windowConfig));
Utils.sleep(60 * 1000);
cluster.shutdown();
}
System.exit(0);
} else {
conf.setNumWorkers(3);
StormSubmitter.submitTopologyWithProgressBar(args[0], conf, buildTopology(mapState, SlidingCountWindow.of(1000, 100)));
}
}
示例4: main
import org.apache.storm.topology.base.BaseWindowedBolt; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
TopologyBuilder builder = new TopologyBuilder();
BaseWindowedBolt bolt = new SlidingWindowSumBolt()
.withWindow(new Duration(5, TimeUnit.SECONDS), new Duration(3, TimeUnit.SECONDS))
.withTimestampField("ts")
.withLag(new Duration(5, TimeUnit.SECONDS));
builder.setSpout("integer", new RandomIntegerSpout(), 1);
builder.setBolt("slidingsum", bolt, 1).shuffleGrouping("integer");
builder.setBolt("printer", new PrinterBolt(), 1).shuffleGrouping("slidingsum");
Config conf = new Config();
conf.setDebug(true);
if (args != null && args.length > 0) {
conf.setNumWorkers(1);
StormSubmitter.submitTopologyWithProgressBar(args[0], conf, builder.createTopology());
} else {
LocalCluster cluster = new LocalCluster();
cluster.submitTopology("test", conf, builder.createTopology());
Utils.sleep(40000);
cluster.killTopology("test");
cluster.shutdown();
}
}
示例5: main
import org.apache.storm.topology.base.BaseWindowedBolt; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
Config conf = new Config();
WindowsStoreFactory mapState = new InMemoryWindowsStoreFactory();
if (args.length == 0) {
List<? extends WindowConfig> list = Arrays.asList(
// SlidingCountWindow.of(100, 10)
// TumblingCountWindow.of(100)
//SlidingDurationWindow.of(new BaseWindowedBolt.Duration(6, TimeUnit.SECONDS), new BaseWindowedBolt.Duration(3, TimeUnit.SECONDS))
TumblingDurationWindow.of(new BaseWindowedBolt.Duration(3, TimeUnit.SECONDS))
);
for (WindowConfig windowConfig : list) {
LocalCluster cluster = new LocalCluster();
cluster.submitTopology("wordCounter", conf, buildTopology(mapState, windowConfig));
Utils.sleep(60 * 1000);
cluster.shutdown();
System.out.println("===================================================================================");
System.out.println("Completed Window config "+ windowConfig.getWindowStrategy().toString());
System.out.println("===================================================================================");
}
System.exit(0);
} else {
conf.setNumWorkers(3);
StormSubmitter.submitTopologyWithProgressBar(args[0], conf, buildTopology(mapState, SlidingCountWindow.of(1000, 100)));
}
}
开发者ID:PacktPublishing,项目名称:Practical-Real-time-Processing-and-Analytics,代码行数:28,代码来源:TridentWindowingInmemoryStoreTopology.java
示例6: main
import org.apache.storm.topology.base.BaseWindowedBolt; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
TopologyBuilder builder = new TopologyBuilder();
// BaseWindowedBolt bolt = new SlidingWindowSumBolt()
// .withWindow(new Duration(5, TimeUnit.SECONDS), new Duration(1, TimeUnit.SECONDS))
// .withTimestampField("ts")
// .withLag(new Duration(5, TimeUnit.SECONDS));
BaseWindowedBolt bolt = new SlidingWindowSumBolt()
.withTumblingWindow(new Duration(5,TimeUnit.SECONDS))
.withTimestampField("ts")
;
builder.setSpout("integer", new RandomIntegerSpout(), 1);
builder.setBolt("slidingsum", bolt, 1).shuffleGrouping("integer");
builder.setBolt("printer", new PrinterBolt(), 1).shuffleGrouping("slidingsum");
Config conf = new Config();
conf.setDebug(true);
// if (args != null && args.length > 0) {
// conf.setNumWorkers(1);
// StormSubmitter.submitTopologyWithProgressBar(args[0], conf, builder.createTopology());
// } else {
LocalCluster cluster = new LocalCluster();
cluster.submitTopology("test", conf, builder.createTopology());
Utils.sleep(300*1000);
cluster.killTopology("test");
cluster.shutdown();
// }
}
示例7: main
import org.apache.storm.topology.base.BaseWindowedBolt; //导入依赖的package包/类
public static void main(String[] args)
throws InterruptedException, AlreadyAliveException, InvalidTopologyException, AuthorizationException {
RandomSpout r = new RandomSpout();
// Sliding window used to test withLag
// BaseWindowedBolt b = new WindowDemoBolt().withTimestampField("time")
// .withWindow(new Duration(5, TimeUnit.SECONDS), new Duration(3,
// TimeUnit.SECONDS))
// // When get tuple with timestamp
// // t1(10:00:10),t2(10:00:14),t3(10:00:12),t4(10:00:16) in turn,
// // If we won't set withLag, storm would throw t3 away. But if
// // setted and (lag + t3) > t2, t3 will not be dropped.
// .withLag(new Duration(2, TimeUnit.SECONDS));
// Sliding window used to test watermark
BaseWindowedBolt b = new WindowDemoBolt().withTimestampField("time")
.withWindow(new Duration(20, TimeUnit.SECONDS), new Duration(10, TimeUnit.SECONDS))
.withLag(new Duration(5, TimeUnit.SECONDS));
TopologyBuilder builder = new TopologyBuilder();
builder.setSpout("spout", r);
builder.setBolt("window-bolt", b).shuffleGrouping("spout");
Config conf = new Config();
if (args.length == 0) {
LocalCluster cluster = new LocalCluster();
cluster.submitTopology("test", conf, builder.createTopology());
Thread.sleep(3600000L);
cluster.shutdown();
} else {
StormSubmitter.submitTopology("test-window", conf, builder.createTopology());
}
}
示例8: main
import org.apache.storm.topology.base.BaseWindowedBolt; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
SquaresSpout squares = new SquaresSpout();
CubesSpout cubes = new CubesSpout();
TopologyBuilder builder = new TopologyBuilder();
builder.setSpout("squares", squares, 1);
builder.setSpout("cubes", cubes, 1);
BaseWindowedBolt joiner = new WindowedQueryBolt("cubes", "number")
.leftJoin("squares", "number", "cubes")
.select("number,square,cube")
.withTumblingWindow(BaseWindowedBolt.Count.of(1000))
;
builder.setBolt("joiner", joiner, 2)
.fieldsGrouping("squares", new Fields("number") )
.fieldsGrouping("cubes", new Fields("number") )
;
builder.setBolt("fileWrite", new FileWriteBolt(), 1).shuffleGrouping("joiner");
// - submit topo
// LocalCluster cluster = runOnLocalCluster(TOPO_NAME, builder.createTopology() );
// Thread.sleep(10 * 60*1000);
// System.err.println("Shutting down");
// cluster.killTopology(TOPO_NAME);
// cluster.shutdown();
}
示例9: main
import org.apache.storm.topology.base.BaseWindowedBolt; //导入依赖的package包/类
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();
}
}
示例10: TestRunWindowProcessorBolt
import org.apache.storm.topology.base.BaseWindowedBolt; //导入依赖的package包/类
public TestRunWindowProcessorBolt(BaseWindowedBolt processorBolt, String eventLogFilePath) {
this.processorBolt = processorBolt;
this.eventLogFilePath = eventLogFilePath;
}