use of io.reactivex.Flowable in project RxCache by VictorAlbertos.
the class ProxyTranslator method getLoaderObservable.
private Observable getLoaderObservable(Method method, Object[] objectsMethod) {
Observable<?> observable = getObjectFromMethodParam(method, Observable.class, objectsMethod);
if (observable != null)
return observable;
Single single = getObjectFromMethodParam(method, Single.class, objectsMethod);
if (single != null)
return single.toObservable();
Maybe maybe = getObjectFromMethodParam(method, Maybe.class, objectsMethod);
if (maybe != null)
return maybe.toObservable();
Flowable flowable = getObjectFromMethodParam(method, Flowable.class, objectsMethod);
if (flowable != null)
return flowable.toObservable();
String errorMessage = method.getName() + io.rx_cache2.internal.Locale.NOT_REACTIVE_TYPE_FOR_LOADER_WAS_FOUND;
throw new IllegalArgumentException(errorMessage);
}
use of io.reactivex.Flowable in project RxJava-Android-Samples by kaushikgopal.
the class RxBusDemo_Bottom2Fragment method onStart.
@Override
public void onStart() {
super.onStart();
_disposables = new CompositeDisposable();
Flowable<Object> tapEventEmitter = _rxBus.asFlowable().share();
_disposables.add(tapEventEmitter.subscribe(event -> {
if (event instanceof RxBusDemoFragment.TapEvent) {
_showTapText();
}
}));
Flowable<Object> debouncedEmitter = tapEventEmitter.debounce(1, TimeUnit.SECONDS);
Flowable<List<Object>> debouncedBufferEmitter = tapEventEmitter.buffer(debouncedEmitter);
_disposables.add(debouncedBufferEmitter.observeOn(AndroidSchedulers.mainThread()).subscribe(taps -> {
_showTapCount(taps.size());
}));
}
use of io.reactivex.Flowable in project pentaho-kettle by pentaho.
the class FixedTimeStreamWindowTest method testSharedStreamingBatchPoolExecution.
@Test
public void testSharedStreamingBatchPoolExecution() throws Exception {
/*
* Tests that there is only 1 thread running inside the pool at all times.
* */
final List<String> errors = new ArrayList<String>();
// Only 1 thread should be present in the pool at a given time.
System.setProperty(Const.SHARED_STREAMING_BATCH_POOL_SIZE, "1");
RowMetaInterface rowMeta = new RowMeta();
rowMeta.addValueMeta(new ValueMetaString("field"));
Result mockResult = new Result();
mockResult.setRows(Arrays.asList(new RowMetaAndData(rowMeta, "queen"), new RowMetaAndData(rowMeta, "king")));
FixedTimeStreamWindow<List> window1 = new FixedTimeStreamWindow<>(subtransExecutor, rowMeta, 0, 10, 10);
FixedTimeStreamWindow<List> window2 = new FixedTimeStreamWindow<>(subtransExecutor, rowMeta, 0, 10, 10);
Flowable flowable = Flowable.fromIterable(singletonList(asList("v1", "v2")));
Field field = window1.getClass().getDeclaredField("sharedStreamingBatchPool");
field.setAccessible(true);
ThreadPoolExecutor sharedStreamingBatchPool = (ThreadPoolExecutor) field.get(window1);
when(subtransExecutor.getPrefetchCount()).thenReturn(1000);
when(subtransExecutor.execute(any())).thenAnswer((InvocationOnMock invocation) -> {
// The active count should always be 1.
if (sharedStreamingBatchPool.getActiveCount() != 1) {
errors.add("Error: Active count should have been 1 at all times. Current value: " + sharedStreamingBatchPool.getActiveCount());
}
return Optional.of(mockResult);
});
Thread bufferThread1 = new Thread(new BufferThread(window1, flowable, mockResult));
bufferThread1.start();
Thread bufferThread2 = new Thread(new BufferThread(window2, flowable, mockResult));
bufferThread2.start();
Thread.sleep(10000);
assertEquals(0, errors.size());
}
use of io.reactivex.Flowable in project incubator-gobblin by apache.
the class StreamModelTaskRunner method run.
protected void run() throws Exception {
long maxWaitInMinute = taskState.getPropAsLong(ConfigurationKeys.FORK_MAX_WAIT_MININUTES, ConfigurationKeys.DEFAULT_FORK_MAX_WAIT_MININUTES);
long initialDelay = taskState.getPropAsLong(ConfigurationKeys.FORK_FINISHED_CHECK_INTERVAL, ConfigurationKeys.DEFAULT_FORK_FINISHED_CHECK_INTERVAL);
// Get the fork operator. By default IdentityForkOperator is used with a single branch.
ForkOperator forkOperator = closer.register(this.taskContext.getForkOperator());
RecordStreamWithMetadata<?, ?> stream = this.extractor.recordStream(this.shutdownRequested);
// This prevents emitting records until a connect() call is made on the connectable stream
ConnectableFlowable connectableStream = stream.getRecordStream().publish();
// The cancel is not propagated to the extractor's record generator when it has been turned into a hot Flowable
// by publish, and in the case that extractor stuck in reading record when cancel get called,
// we directly call shutdown to force it instead of setting the shutdownRequested flag on cancel to stop the extractor
Flowable streamWithShutdownOnCancel = connectableStream.doOnCancel(this.extractor::shutdown);
stream = stream.withRecordStream(streamWithShutdownOnCancel);
stream = stream.mapRecords(r -> {
this.task.onRecordExtract();
return r;
});
if (this.task.isStreamingTask()) {
// Start watermark manager and tracker
if (this.watermarkTracker.isPresent()) {
this.watermarkTracker.get().start();
}
this.watermarkManager.get().start();
((StreamingExtractor) this.taskContext.getRawSourceExtractor()).start(this.watermarkStorage.get());
stream = stream.mapRecords(r -> {
AcknowledgableWatermark ackableWatermark = new AcknowledgableWatermark(r.getWatermark());
if (watermarkTracker.isPresent()) {
watermarkTracker.get().track(ackableWatermark);
}
r.addCallBack(ackableWatermark);
return r;
});
}
// Use the recordStreamProcessor list if it is configured. This list can contain both all RecordStreamProcessor types
if (!this.recordStreamProcessors.isEmpty()) {
for (RecordStreamProcessor streamProcessor : this.recordStreamProcessors) {
stream = streamProcessor.processStream(stream, this.taskState);
}
} else {
if (this.converter instanceof MultiConverter) {
// if multiconverter, unpack it
for (Converter cverter : ((MultiConverter) this.converter).getConverters()) {
stream = cverter.processStream(stream, this.taskState);
}
} else {
stream = this.converter.processStream(stream, this.taskState);
}
}
stream = this.rowChecker.processStream(stream, this.taskState);
Forker.ForkedStream<?, ?> forkedStreams = new Forker().forkStream(stream, forkOperator, this.taskState);
boolean isForkAsync = !this.task.areSingleBranchTasksSynchronous(this.taskContext) || forkedStreams.getForkedStreams().size() > 1;
int bufferSize = this.taskState.getPropAsInt(ConfigurationKeys.FORK_RECORD_QUEUE_CAPACITY_KEY, ConfigurationKeys.DEFAULT_FORK_RECORD_QUEUE_CAPACITY);
for (int fidx = 0; fidx < forkedStreams.getForkedStreams().size(); fidx++) {
RecordStreamWithMetadata<?, ?> forkedStream = forkedStreams.getForkedStreams().get(fidx);
if (forkedStream != null) {
if (isForkAsync) {
forkedStream = forkedStream.mapStream(f -> f.observeOn(Schedulers.from(this.taskExecutor.getForkExecutor()), false, bufferSize));
}
Fork fork = new Fork(this.taskContext, forkedStream.getGlobalMetadata().getSchema(), forkedStreams.getForkedStreams().size(), fidx, this.taskMode);
fork.consumeRecordStream(forkedStream);
this.forks.put(Optional.of(fork), Optional.of(Futures.immediateFuture(null)));
this.task.configureStreamingFork(fork);
}
}
Thread thread = new Thread(() -> connectableStream.connect());
thread.setName(this.getClass().getSimpleName());
// Log uncaught exceptions (e.g.OOMEs) to prevent threads from dying silently
thread.setUncaughtExceptionHandler(new LoggingUncaughtExceptionHandler(Optional.absent()));
thread.start();
if (!ExponentialBackoff.awaitCondition().callable(() -> this.forks.keySet().stream().map(Optional::get).allMatch(Fork::isDone)).initialDelay(initialDelay).maxDelay(initialDelay).maxWait(TimeUnit.MINUTES.toMillis(maxWaitInMinute)).await()) {
throw new TimeoutException("Forks did not finish withing specified timeout.");
}
}
use of io.reactivex.Flowable in project vertx-examples by vert-x3.
the class Client method start.
@Override
public void start() throws Exception {
HttpClient client = vertx.createHttpClient();
// Create two requests
HttpClientRequest req1 = client.request(HttpMethod.GET, 8080, "localhost", "/");
HttpClientRequest req2 = client.request(HttpMethod.GET, 8080, "localhost", "/");
// Turn the requests responses into Flowable<JsonObject>
Flowable<JsonObject> obs1 = req1.toFlowable().flatMap(HttpClientResponse::toFlowable).map(buf -> new JsonObject(buf.toString("UTF-8")));
Flowable<JsonObject> obs2 = req2.toFlowable().flatMap(HttpClientResponse::toFlowable).map(buf -> new JsonObject(buf.toString("UTF-8")));
// Combine the responses with the zip into a single response
obs1.zipWith(obs2, (b1, b2) -> new JsonObject().put("req1", b1).put("req2", b2)).subscribe(json -> {
System.out.println("Got combined result " + json);
}, Throwable::printStackTrace);
req1.end();
req2.end();
}
Aggregations