use of io.reactivex.Flowable in project Rocket.Chat.Android by RocketChat.
the class DDPClientImpl method connect.
public void connect(final TaskCompletionSource<DDPClientCallback.Connect> task, final String url, String session) {
try {
flowable = websocket.connect(url).autoConnect();
CompositeDisposable subscriptions = new CompositeDisposable();
subscriptions.add(flowable.filter(callback -> callback instanceof RxWebSocketCallback.Open).subscribe(callback -> {
sendMessage("connect", json -> (TextUtils.isEmpty(session) ? json : json.put("session", session)).put("version", "pre2").put("support", new JSONArray().put("pre2").put("pre1")), task);
}, err -> {
}));
subscriptions.add(flowable.filter(callback -> callback instanceof RxWebSocketCallback.Message).map(callback -> ((RxWebSocketCallback.Message) callback).responseBodyString).map(DDPClientImpl::toJson).timeout(7, TimeUnit.SECONDS).subscribe(response -> {
String msg = extractMsg(response);
if ("connected".equals(msg) && !response.isNull("session")) {
task.trySetResult(new DDPClientCallback.Connect(client, response.optString("session")));
subscriptions.dispose();
} else if ("error".equals(msg) && "Already connected".equals(response.optString("reason"))) {
task.trySetResult(new DDPClientCallback.Connect(client, null));
subscriptions.dispose();
} else if ("failed".equals(msg)) {
task.trySetError(new DDPClientCallback.Connect.Failed(client, response.optString("version")));
subscriptions.dispose();
}
}, err -> task.trySetError(new DDPClientCallback.Connect.Timeout(client))));
addErrorCallback(subscriptions, task);
subscribeBaseListeners();
} catch (Exception e) {
RCLog.e(e);
}
}
use of io.reactivex.Flowable in project rxjava2-jdbc by davidmoten.
the class NonBlockingPool method createMembers.
private Flowable<Member<T>> createMembers() {
List<Member<T>> ms = IntStream.range(1, maxSize + 1).mapToObj(//
n -> memberFactory.create(NonBlockingPool.this)).collect(Collectors.toList());
Flowable<Member<T>> baseMembers = //
Flowable.fromIterable(ms).doOnRequest(n -> log.debug("requested={}", n));
Flowable<Member<T>> returnedMembers = //
subject.toSerialized().toFlowable(BackpressureStrategy.BUFFER);
// use CAS loop to handle a race with close
while (true) {
List<Member<T>> l = list.get();
if (l == null) {
return Flowable.error(new PoolClosedException());
} else if (list.compareAndSet(Collections.emptyList(), ms)) {
return //
returnedMembers.doOnNext(//
m -> log.debug("returned member reentering")).mergeWith(//
baseMembers).doOnNext(//
x -> log.debug("member={}", x)).<Member<T>>flatMap(member -> member.checkout().toFlowable(), false, //
1).doOnNext(x -> log.debug("checked out member={}", x));
}
}
}
use of io.reactivex.Flowable in project todo-mvp-rxjava by albertizzy.
the class TasksPresenter method loadTasks.
/**
* @param forceUpdate Pass in true to refresh the data in the {@link TasksDataSource}
* @param showLoadingUI Pass in true to display a loading icon in the UI
*/
private void loadTasks(final boolean forceUpdate, final boolean showLoadingUI) {
if (showLoadingUI) {
mTasksView.setLoadingIndicator(true);
}
if (forceUpdate) {
mTasksRepository.refreshTasks();
}
// The network request might be handled in a different thread so make sure Espresso knows
// that the app is busy until the response is handled.
// App is busy until further notice
EspressoIdlingResource.increment();
mCompositeDisposable.clear();
Disposable disposable = mTasksRepository.getTasks().flatMap(Flowable::fromIterable).filter(task -> {
switch(mCurrentFiltering) {
case ACTIVE_TASKS:
return task.isActive();
case COMPLETED_TASKS:
return task.isCompleted();
case ALL_TASKS:
default:
return true;
}
}).toList().subscribeOn(mSchedulerProvider.io()).observeOn(mSchedulerProvider.ui()).doFinally(() -> {
if (!EspressoIdlingResource.getIdlingResource().isIdleNow()) {
// Set app as idle.
EspressoIdlingResource.decrement();
}
}).subscribe(// onNext
tasks -> {
processTasks(tasks);
mTasksView.setLoadingIndicator(false);
}, // onError
throwable -> mTasksView.showLoadingTasksError());
mCompositeDisposable.add(disposable);
}
use of io.reactivex.Flowable in project cxf by apache.
the class JAXRSRxJava2FlowableTest method testGetHelloWorldEmpty2.
@Test
public void testGetHelloWorldEmpty2() throws Exception {
String address = "http://localhost:" + PORT + "/rx22/flowable/empty";
final Flowable<Response> obs = ClientBuilder.newClient().register(new JacksonJsonProvider()).register(new FlowableRxInvokerProvider()).target(address).request(MediaType.APPLICATION_JSON).rx(FlowableRxInvoker.class).get();
final TestSubscriber<Response> subscriber = new TestSubscriber<>();
obs.subscribe(subscriber);
subscriber.await(3, TimeUnit.SECONDS);
subscriber.assertValue(r -> "[]".equals(r.readEntity(String.class))).assertComplete();
}
use of io.reactivex.Flowable in project cxf by apache.
the class JAXRSRxJava2FlowableTest method testFlowableImmediateErrorsWithExceptionMapper.
@Test
public void testFlowableImmediateErrorsWithExceptionMapper() throws Exception {
String address = "http://localhost:" + PORT + "/rx22/flowable/immediate/mapper/errors";
final Flowable<Response> obs = ClientBuilder.newClient().register(new JacksonJsonProvider()).register(new FlowableRxInvokerProvider()).target(address).request(MediaType.APPLICATION_JSON).rx(FlowableRxInvoker.class).get();
final TestSubscriber<Response> subscriber = new TestSubscriber<>();
obs.subscribe(subscriber);
subscriber.await(3, TimeUnit.SECONDS);
subscriber.assertValue(r -> r.getStatus() == 409 && r.readEntity(String.class).contains("stackTrace")).assertComplete();
}
Aggregations