@Override public void accept(EventType evType, Job job) { T tuple = tupleGenerator.apply(evType, job); eventSubmitter.accept(tuple); } }
private void post(String pathname, Exception e, Consumer<String> dst) { String postStr = postFn.apply(pathname, e); if (postStr != null) dst.accept(postStr); }
@Override public R apply(T t, U u) { final BiFunction<T,U,R> function = f(); synchronized (function) { return function.apply(t, u); } } }
@Override public R apply(T t, U u) { final BiFunction<T,U,R> function = f(); synchronized (function) { return function.apply(t, u); } } }
/** * Create a Consumer for the input port that invokes the * receiver and submits a generated tuple, if any, to the output. * @param iportIndex index of the input port * @return the Consumer */ protected Consumer<T> consumer(int iportIndex) { return tuple -> { U result = receiver.apply(tuple, iportIndex); if (result != null) submit(result); }; }
/** * Create a Consumer for the input port that invokes the * receiver and submits a generated tuple, if any, to the output. * @param iportIndex index of the input port * @return the Consumer */ protected Consumer<T> consumer(int iportIndex) { return tuple -> { U result = receiver.apply(tuple, iportIndex); if (result != null) submit(result); }; }
public Aggregate(Window<T,K, ? extends List<T>> window, BiFunction<List<T>,K, U> aggregator){ this.aggregator = aggregator; BiConsumer<List<T>, K> partProcessor = (tuples, key) -> { U aggregateTuple = aggregator.apply(tuples, key); if (aggregateTuple != null) submit(aggregateTuple); }; window.registerPartitionProcessor(partProcessor); this.window=window; }
public Aggregate(Window<T,K, ? extends List<T>> window, BiFunction<List<T>,K, U> aggregator){ this.aggregator = aggregator; BiConsumer<List<T>, K> partProcessor = (tuples, key) -> { U aggregateTuple = aggregator.apply(tuples, key); if (aggregateTuple != null) submit(aggregateTuple); }; window.registerPartitionProcessor(partProcessor); this.window=window; }
void messageArrived(String topic, MqttMessage message) throws Exception { T tuple = message2Tuple.apply(topic, message.getPayload()); eventSubmitter.accept(tuple); }
/** * Perform an analytic function on tuples in parallel. * <P> * Same as {@code parallel(stream, width, splitter, (s,ch) -> s.map(t -> mapper.apply(t, ch))} * </P> * @param <T> Input stream tuple type * @param <U> Result stream tuple type * @param stream input stream * @param splitter the tuple channel allocation function * @param mapper analytic function * @param width number of channels * @return the unordered result stream * @see #roundRobinSplitter(int) roundRobinSplitter * @see #concurrentMap(TStream, List, Function) concurrentMap */ public static <T,U> TStream<U> parallelMap(TStream<T> stream, int width, ToIntFunction<T> splitter, BiFunction<T,Integer,U> mapper) { BiFunction<TStream<T>,Integer,TStream<U>> pipeline = (s,ch) -> s.map(t -> mapper.apply(t, ch)); return parallel(stream, width, splitter, pipeline); }
/** * Perform an analytic function on tuples in parallel. * <P> * Same as {@code parallel(stream, width, splitter, (s,ch) -> s.map(t -> mapper.apply(t, ch))} * </P> * @param <T> Input stream tuple type * @param <U> Result stream tuple type * @param stream input stream * @param splitter the tuple channel allocation function * @param mapper analytic function * @param width number of channels * @return the unordered result stream * @see #roundRobinSplitter(int) roundRobinSplitter * @see #concurrentMap(TStream, List, Function) concurrentMap */ public static <T,U> TStream<U> parallelMap(TStream<T> stream, int width, ToIntFunction<T> splitter, BiFunction<T,Integer,U> mapper) { BiFunction<TStream<T>,Integer,TStream<U>> pipeline = (s,ch) -> s.map(t -> mapper.apply(t, ch)); return parallel(stream, width, splitter, pipeline); }
return responseProcessor.apply(t, response);
aggregates).apply(joList, partition);
results.add(pipeline.apply(channels.get(ch), ch).tag("parallel-ch"+ch));
results.add(pipeline.apply(channels.get(ch), ch).tag("parallel-ch"+ch));
for (int ch = 0; ch < width; ch++) { final int finalCh = ch; results.add(pipeline.apply(channels.get(ch), ch) .tag("parallel-ch"+ch) .peek(tuple -> splitter.channelDone(finalCh)));
for (int ch = 0; ch < width; ch++) { final int finalCh = ch; results.add(pipeline.apply(channels.get(ch), ch) .tag("parallel-ch"+ch) .peek(tuple -> splitter.channelDone(finalCh)));
@Override public synchronized boolean insert(T tuple) { if (getWindow().getInsertionPolicy().apply(this, tuple)) { getWindow().getContentsPolicy().accept(this, tuple); this.tuples.add(tuple); // Trigger getWindow().getTriggerPolicy().accept(this, tuple); return true; } return true; }
@Override public <J, U, K> TStream<J> joinLast(Function<T, K> keyer, TStream<U> lastStream, Function<U, K> lastStreamKeyer, BiFunction<T, U, J> joiner) { BiFunction<List<U>,K, Object> processor = Functions.synchronizedBiFunction((list, key) -> null); Window<U, K, LinkedList<U>> window = Windows.lastNProcessOnInsert(1, lastStreamKeyer); Aggregate<U,Object,K> op = new Aggregate<U,Object,K>(window, processor); lastStream.pipe(op); return this.map((tuple) -> { Partition<U, K, ? extends List<U>> part = window.getPartitions().get(keyer.apply(tuple)); if(part == null) return null; J ret; synchronized (part) { U last = part.getContents().get(0); ret = joiner.apply(tuple, last); } return ret; }); }
@Override public synchronized boolean insert(T tuple) { if (getWindow().getInsertionPolicy().apply(this, tuple)) { getWindow().getContentsPolicy().accept(this, tuple); this.tuples.add(tuple); // Trigger getWindow().getTriggerPolicy().accept(this, tuple); return true; } return true; }