/** * @param shutdownRequest an {@link AtomicBoolean} that becomes true when a shutdown has been requested. * @return a {@link Flowable} with the records from this source. Note the flowable should honor downstream backpressure. */ default RecordStreamWithMetadata<D, S> recordStream(AtomicBoolean shutdownRequest) throws IOException { S schema = getSchema(); Flowable<StreamEntity<D>> recordStream = Flowable.generate(() -> shutdownRequest, (BiConsumer<AtomicBoolean, Emitter<StreamEntity<D>>>) (state, emitter) -> { if (state.get()) { emitter.onComplete(); } try { StreamEntity<D> record = readStreamEntity(); if (record != null) { emitter.onNext(record); } else { emitter.onComplete(); } } catch (DataRecordException | IOException exc) { emitter.onError(exc); } }); recordStream = recordStream.doFinally(this::close); return new RecordStreamWithMetadata<>(recordStream, GlobalMetadata.<S>builder().schema(schema).build()); }
/** * @param shutdownRequest an {@link AtomicBoolean} that becomes true when a shutdown has been requested. * @return a {@link Flowable} with the records from this source. Note the flowable should honor downstream backpressure. */ default RecordStreamWithMetadata<D, S> recordStream(AtomicBoolean shutdownRequest) throws IOException { S schema = getSchema(); Flowable<StreamEntity<D>> recordStream = Flowable.generate(() -> shutdownRequest, (BiConsumer<AtomicBoolean, Emitter<StreamEntity<D>>>) (state, emitter) -> { if (state.get()) { emitter.onComplete(); } try { StreamEntity<D> record = readStreamEntity(); if (record != null) { emitter.onNext(record); } else { emitter.onComplete(); } } catch (DataRecordException | IOException exc) { emitter.onError(exc); } }); recordStream = recordStream.doFinally(this::close); return new RecordStreamWithMetadata<>(recordStream, GlobalMetadata.<S>builder().schema(schema).build()); }