windowLengthCount = new Count(((Number) topoConf.get(Config.TOPOLOGY_BOLTS_WINDOW_LENGTH_COUNT)).intValue()); } else if (topoConf.containsKey(Config.TOPOLOGY_BOLTS_WINDOW_LENGTH_DURATION_MS)) { windowLengthDuration = new Duration( ((Number) topoConf.get(Config.TOPOLOGY_BOLTS_WINDOW_LENGTH_DURATION_MS)).intValue(), TimeUnit.MILLISECONDS); } else if (topoConf.containsKey(Config.TOPOLOGY_BOLTS_SLIDING_INTERVAL_DURATION_MS)) { slidingIntervalDuration = new Duration(((Number) topoConf.get(Config.TOPOLOGY_BOLTS_SLIDING_INTERVAL_DURATION_MS)).intValue(), TimeUnit.MILLISECONDS); } else {
@Override public boolean equals(Object o) { if (this == o) { return true; } if (o == null || getClass() != o.getClass()) { return false; } BaseWindow<?, ?> that = (BaseWindow<?, ?>) o; if (timestampField != null ? !timestampField.equals(that.timestampField) : that.timestampField != null) { return false; } if (lateTupleStream != null ? !lateTupleStream.equals(that.lateTupleStream) : that.lateTupleStream != null) { return false; } return lag != null ? lag.equals(that.lag) : that.lag == null; }
@Override public int hashCode() { int result = timestampField != null ? timestampField.hashCode() : 0; result = 31 * result + (lateTupleStream != null ? lateTupleStream.hashCode() : 0); result = 31 * result + (lag != null ? lag.hashCode() : 0); return result; } }
windowLengthCount = new Count(((Number) stormConf.get(Config.TOPOLOGY_BOLTS_WINDOW_LENGTH_COUNT)).intValue()); } else if (stormConf.containsKey(Config.TOPOLOGY_BOLTS_WINDOW_LENGTH_DURATION_MS)) { windowLengthDuration = new Duration( ((Number) stormConf.get(Config.TOPOLOGY_BOLTS_WINDOW_LENGTH_DURATION_MS)).intValue(), TimeUnit.MILLISECONDS); slidingIntervalCount = new Count(((Number) stormConf.get(Config.TOPOLOGY_BOLTS_SLIDING_INTERVAL_COUNT)).intValue()); } else if (stormConf.containsKey(Config.TOPOLOGY_BOLTS_SLIDING_INTERVAL_DURATION_MS)) { slidingIntervalDuration = new Duration(((Number) stormConf.get(Config.TOPOLOGY_BOLTS_SLIDING_INTERVAL_DURATION_MS)).intValue(), TimeUnit.MILLISECONDS); } else {
public void withWindowConfig(Window windowConfig) throws IOException { if (windowConfig.getWindowLength() instanceof Window.Duration) { BaseWindowedBolt.Duration windowLength = new BaseWindowedBolt.Duration(((Window.Duration) windowConfig.getWindowLength()).getDurationMs(), TimeUnit.MILLISECONDS); if (windowConfig.getSlidingInterval() instanceof Window.Duration) { BaseWindowedBolt.Duration slidingInterval = new BaseWindowedBolt.Duration(((Window.Duration) windowConfig.getSlidingInterval()).getDurationMs(), TimeUnit.MILLISECONDS); withWindow(windowLength, slidingInterval); } else if (windowConfig.getSlidingInterval() instanceof Window.Count) { BaseWindowedBolt.Count windowLength = new BaseWindowedBolt.Count(((Window.Count) windowConfig.getWindowLength()).getCount()); if (windowConfig.getSlidingInterval() instanceof Window.Duration) { BaseWindowedBolt.Duration slidingInterval = new BaseWindowedBolt.Duration(((Window.Duration) windowConfig.getWindowLength()).getDurationMs(), TimeUnit.MILLISECONDS); withWindow(windowLength, slidingInterval); } else if (windowConfig.getSlidingInterval() instanceof Window.Count) { withLag(new BaseWindowedBolt.Duration(windowConfig.getLagMs(), TimeUnit.MILLISECONDS));
Duration windowLength = new Duration(((Window.Duration) windowConfig.getWindowLength()).getDurationMs(), TimeUnit.MILLISECONDS); if (windowConfig.getSlidingInterval() instanceof Window.Duration) { Duration slidingInterval = new Duration(((Window.Duration) windowConfig.getSlidingInterval()).getDurationMs(), TimeUnit.MILLISECONDS); withWindow(windowLength, slidingInterval); } else if (windowConfig.getSlidingInterval() instanceof Window.Count) { Count windowLength = new Count(((Window.Count) windowConfig.getWindowLength()).getCount()); if (windowConfig.getSlidingInterval() instanceof Window.Duration) { Duration slidingInterval = new Duration(((Window.Duration) windowConfig.getWindowLength()).getDurationMs(), TimeUnit.MILLISECONDS); withWindow(windowLength, slidingInterval); } else if (windowConfig.getSlidingInterval() instanceof Window.Count) { withLag(new Duration(windowConfig.getLagMs(), TimeUnit.MILLISECONDS));
/** * Returns a {@link Duration} corresponding to the the given value in seconds. * * @param seconds the number of seconds * @return the Duration */ public static Duration seconds(int seconds) { return new Duration(seconds, TimeUnit.SECONDS); }
/** * Returns a {@link Duration} corresponding to the the given value in minutes. * * @param minutes the number of minutes * @return the Duration */ public static Duration minutes(int minutes) { return new Duration(minutes, TimeUnit.MINUTES); }
/** * Returns a {@link Duration} corresponding to the the given value in days. * * @param days the number of days * @return the Duration */ public static Duration days(int days) { return new Duration(days, TimeUnit.DAYS); }
/** * Returns a {@link Duration} corresponding to the the given value in milli seconds. * * @param milliseconds the duration in milliseconds * @return the Duration */ public static Duration of(int milliseconds) { return new Duration(milliseconds, TimeUnit.MILLISECONDS); }
/** * Returns a {@link Duration} corresponding to the the given value in minutes. * * @param minutes the number of minutes * @return the Duration */ public static Duration minutes(int minutes) { return new Duration(minutes, TimeUnit.MINUTES); }
/** * Returns a {@link Duration} corresponding to the the given value in milli seconds. * * @param milliseconds the duration in milliseconds * @return the Duration */ public static Duration of(int milliseconds) { return new Duration(milliseconds, TimeUnit.MILLISECONDS); }
/** * Returns a {@link Duration} corresponding to the the given value in hours. * * @param hours the number of hours * @return the Duration */ public static Duration hours(int hours) { return new Duration(hours, TimeUnit.HOURS); }
/** * Returns a {@link Duration} corresponding to the the given value in seconds. * * @param seconds the number of seconds * @return the Duration */ public static Duration seconds(int seconds) { return new Duration(seconds, TimeUnit.SECONDS); }
/** * Returns a {@link Duration} corresponding to the the given value in days. * * @param days the number of days * @return the Duration */ public static Duration days(int days) { return new Duration(days, TimeUnit.DAYS); }
/** * Returns a {@link Duration} corresponding to the the given value in hours. * * @param hours the number of hours * @return the Duration */ public static Duration hours(int hours) { return new Duration(hours, TimeUnit.HOURS); }
@Override public TridentTopology createTopology() { ITridentDataSource source = KafkaSpoutFactory.getTridentSpout(config, true); TridentTopology topology = new TridentTopology(); topology.newStream("kafka", source) .each(new Fields("str"), new Parser(), new Fields("ip", "time")) .project(new Fields("ip", "time")) .parallelismHint(config.spoutThreads) .groupBy(new Fields("ip")).toStream() .slidingWindow(new BaseWindowedBolt.Duration((int) config.windowDuration, TimeUnit.MILLISECONDS), new BaseWindowedBolt.Duration((int) config.windowSlideStep, TimeUnit.MILLISECONDS), new InMemoryWindowsStoreFactory(), new Fields("ip", "time"), new Count(config), new Fields("ip", "count")) .parallelismHint(config.boltThreads); return topology; }
@Override public void setBolts(TopologyBuilder builder) { Duration windowDuration = new Duration((int) config.windowDuration, TimeUnit.MILLISECONDS); Duration windowSlide = new Duration((int) config.windowSlideStep, TimeUnit.MILLISECONDS); BoltDeclarer boltDeclarer = builder.setBolt("parser", new ParserBolt(), config.boltThreads); if (config.localShuffle) { boltDeclarer.localOrShuffleGrouping("spout"); } else { boltDeclarer.shuffleGrouping("spout"); } builder.setBolt("window", new SlidingWindowBolt(config) .withWindow(windowDuration, windowSlide), config.boltThreads).fieldsGrouping("parser", new Fields("ip")); }
@Test public void testTimeBasedWindow() throws Exception { EvictionPolicy<Integer, ?> evictionPolicy = new TimeEvictionPolicy<Integer>(new Duration(1, TimeUnit.SECONDS).value); windowManager.setEvictionPolicy(evictionPolicy); new TimeTriggerPolicy<Integer>(new Duration(1, TimeUnit.DAYS).value, windowManager, evictionPolicy); triggerPolicy.start(); windowManager.setTriggerPolicy(triggerPolicy);
.window(TumblingWindows.of(Duration.seconds(2)))