@Override public void accept(GroupedFlowable<Object, Movie> g) { System.out.println(g.getKey()); } })
@Override public void accept(final GroupedFlowable<K, V> f) { result.put(f.getKey(), new ConcurrentLinkedQueue<V>()); f.subscribe(new Consumer<V>() { @Override public void accept(V v) { result.get(f.getKey()).add(v); } }); } });
@Override public Flowable<String> apply(GroupedFlowable<Integer, Event> eventGroupedFlowable) { System.out.println("GroupedFlowable Key: " + eventGroupedFlowable.getKey()); groupCounter.incrementAndGet(); return eventGroupedFlowable.map(new Function<Event, String>() { @Override public String apply(Event event) { return "Source: " + event.source + " Message: " + event.message; } }); } }).subscribe(new DefaultSubscriber<String>() {
@Override public Flowable<String> apply(GroupedFlowable<Integer, Event> eventGroupedFlowable) { int numToTake = 0; if (eventGroupedFlowable.getKey() == 1) { numToTake = 10; } else if (eventGroupedFlowable.getKey() == 2) { numToTake = 5; } return eventGroupedFlowable .take(numToTake) .map(new Function<Event, String>() { @Override public String apply(Event event) { return "testUnsubscribe => Source: " + event.source + " Message: " + event.message; } }); } })
@Override public Flowable<String> apply(GroupedFlowable<Integer, Event> eventGroupedFlowable) { System.out.println("testUnsubscribe => GroupedFlowable Key: " + eventGroupedFlowable.getKey()); groupCounter.incrementAndGet(); return eventGroupedFlowable .take(20) // limit to only 20 events on this group .map(new Function<Event, String>() { @Override public String apply(Event event) { return "testUnsubscribe => Source: " + event.source + " Message: " + event.message; } }); } }).subscribe(new DefaultSubscriber<String>() {
@Override public Publisher<String> apply(final GroupedFlowable<String, String> g) { System.out.println("-----------> NEXT: " + g.getKey()); return g.take(2).map(new Function<String, String>() { int count; @Override public String apply(String v) { System.out.println(v); return g.getKey() + "-" + count++; } }); } });
@Override public void onNext(GroupedFlowable<Integer, Integer> f) { if (f.getKey() == 0) { f.subscribe(inner1); } else { f.subscribe(inner2); } } });
@Override public Flowable<Integer> apply(GroupedFlowable<Integer, Integer> group) { if (group.getKey() == 0) { return group.delay(100, TimeUnit.MILLISECONDS).map(new Function<Integer, Integer>() { @Override public Integer apply(Integer t) { return t * 10; } }); } else { return group; } } })
@Override public Flowable<String> apply(GroupedFlowable<Integer, Event> eventGroupedFlowable) { Flowable<Event> eventStream = eventGroupedFlowable; if (eventGroupedFlowable.getKey() >= 2) { // filter these eventStream = eventGroupedFlowable.filter(new Predicate<Event>() { @Override public boolean test(Event t1) { return false; } }); } return eventStream .map(new Function<Event, String>() { @Override public String apply(Event event) { return "testUnsubscribe => Source: " + event.source + " Message: " + event.message; } }); } })
@Override public Flowable<String> apply(final GroupedFlowable<Integer, Integer> group) { if (group.getKey() < 3) { return group.map(new Function<Integer, String>() { @Override public String apply(Integer t1) { return "first groups: " + t1; } }) // must take(2) so an onComplete + unsubscribe happens on these first 2 groups .take(2).doOnComplete(new Action() { @Override public void run() { first.countDown(); } }); } else { return group.subscribeOn(Schedulers.newThread()).delay(400, TimeUnit.MILLISECONDS).map(new Function<Integer, String>() { @Override public String apply(Integer t1) { return "last group: " + t1; } }).doOnEach(new Consumer<Notification<String>>() { @Override public void accept(Notification<String> t1) { System.err.println("subscribeOn notification => " + t1); } }); } }
@SuppressWarnings({ "rawtypes", "unchecked" }) public Flowable<EntityStateMachine<?, Id>> flowable() { return Flowable.defer(() -> { Worker worker = signalScheduler.createWorker(); Flowable<Signal<?, Id>> o0 = subject // .toSerialized() // .toFlowable(BackpressureStrategy.BUFFER) // .mergeWith(signals) // .doOnCancel(() -> worker.dispose()) // .compose(preGroupBy); Flowable<GroupedFlowable<ClassId<?, Id>, Signal<?, Id>>> o; if (mapFactory != null) { o = o0.groupBy(signal -> new ClassId(signal.cls(), signal.id()), x -> x, true, 16, mapFactory); } else { o = o0.groupBy(signal -> new ClassId(signal.cls(), signal.id()), Functions.identity()); } return o.flatMap(g -> { Flowable<EntityStateMachine<?, Id>> obs = g // .flatMap(processSignalsToSelfAndSendSignalsToOthers(worker, g.getKey())) // .doOnNext(m -> stateMachines.put(g.getKey(), m)) // .subscribeOn(processingScheduler); // Flowable<EntityStateMachine<?, Id>> res = entityTransform .apply(grouped(g.getKey(), obs)); return res; }); }); }
@SuppressWarnings({ "rawtypes", "unchecked" }) public Flowable<EntityStateMachine<?, Id>> flowable() { return Flowable.defer(() -> { Worker worker = signalScheduler.createWorker(); Flowable<Signal<?, Id>> o0 = subject // .toSerialized() // .toFlowable(BackpressureStrategy.BUFFER) // .mergeWith(signals) // .doOnCancel(() -> worker.dispose()) // .compose(preGroupBy); Flowable<GroupedFlowable<ClassId<?, Id>, Signal<?, Id>>> o; if (mapFactory != null) { o = o0.groupBy(signal -> new ClassId(signal.cls(), signal.id()), x -> x, true, 16, mapFactory); } else { o = o0.groupBy(signal -> new ClassId(signal.cls(), signal.id()), Functions.identity()); } return o.flatMap(g -> { Flowable<EntityStateMachine<?, Id>> obs = g // .flatMap(processSignalsToSelfAndSendSignalsToOthers(worker, g.getKey())) // .doOnNext(m -> stateMachines.put(g.getKey(), m)) // .subscribeOn(processingScheduler); // Flowable<EntityStateMachine<?, Id>> res = entityTransform .apply(grouped(g.getKey(), obs)); return res; }); }); }
.flatMapSingle(groups -> groups .collectInto((Table)new TableN(), (t, b) -> t.addBinding(b)) .map(x -> (Entry<Node, Table>)Maps.immutableEntry(groups.getKey(), x))); } else { result = Flowable.empty();
.flatMapSingle(groups -> groups .collectInto(GraphFactory.createDefaultGraph(), (g, t) -> g.add(t)) .map(x -> (Entry<Node, Model>)Maps.immutableEntry(groups.getKey(), ModelFactory.createModelForGraph(x))));