use of rx.subjects.BehaviorSubject in project android-client by GenesisVision.
the class RateManager method getRate.
public BehaviorSubject<Double> getRate(String from, String to) {
BehaviorSubject<Double> rateSubject = getRateSubject(from, to);
RequestRate model = new RequestRate();
model.setFrom(RequestRate.FromEnum.fromValue(from));
model.setTo(RequestRate.ToEnum.fromValue(to));
rateSubscription = rateApi.apiRatePost(model).observeOn(Schedulers.io()).subscribeOn(Schedulers.io()).subscribe(response -> handleGetRateResponse(response, rateSubject), this::handleGetRateError);
return rateSubject;
}
use of rx.subjects.BehaviorSubject in project spoofax by metaborg.
the class ParseResultProcessor method request.
@Override
public Observable<P> request(final I input) {
final FileObject resource = input.source();
return Observable.create(new OnSubscribe<P>() {
@Override
public void call(Subscriber<? super P> observer) {
if (observer.isUnsubscribed()) {
logger.trace("Unsubscribed from parse result request for {}", input);
return;
}
final BehaviorSubject<ParseChange<P>> updates = getUpdates(input);
final ParseChange<P> update = updates.toBlocking().first(new Func1<ParseChange<P>, Boolean>() {
@Override
public Boolean call(ParseChange<P> updateToFilter) {
final UpdateKind kind = updateToFilter.kind;
return kind != UpdateKind.Invalidate;
}
});
if (observer.isUnsubscribed()) {
logger.trace("Unsubscribed from parse result request for {}", resource);
return;
}
switch(update.kind) {
case Update:
logger.trace("Returning cached parse result for {}", resource);
observer.onNext(update.unit);
observer.onCompleted();
break;
case Error:
logger.trace("Returning parse error for {}", resource);
observer.onError(update.exception);
break;
case Remove:
{
final String message = logger.format("Parse result for {} was removed unexpectedly", resource);
logger.error(message);
observer.onError(new ParseException(input, message));
break;
}
default:
{
final String message = logger.format("Unexpected parse update kind {} for {}", update.kind, resource);
logger.error(message);
observer.onError(new ParseException(input, message));
break;
}
}
}
});
}
use of rx.subjects.BehaviorSubject in project spoofax by metaborg.
the class AnalysisResultProcessor method request.
@Override
public Observable<A> request(final I input, final IContext context) {
if (input.detached()) {
throw new MetaborgRuntimeException("Cannot request updates for detached (no source) units");
}
final FileObject resource = input.source();
return Observable.create(new OnSubscribe<A>() {
@Override
public void call(Subscriber<? super A> observer) {
if (observer.isUnsubscribed()) {
logger.trace("Unsubscribed from analysis result request for {}", resource);
return;
}
final BehaviorSubject<AnalysisChange<A>> updates = getUpdates(input, context);
final AnalysisChange<A> update = updates.toBlocking().first(new Func1<AnalysisChange<A>, Boolean>() {
@Override
public Boolean call(AnalysisChange<A> updateToFilter) {
final UpdateKind kind = updateToFilter.kind;
return kind != UpdateKind.Invalidate;
}
});
if (observer.isUnsubscribed()) {
logger.trace("Unsubscribed from analysis result request for {}", resource);
return;
}
switch(update.kind) {
case Update:
logger.trace("Returning cached analysis result for {}", resource);
observer.onNext(update.result);
observer.onCompleted();
break;
case Error:
logger.trace("Returning analysis error for {}", resource);
observer.onError(update.exception);
break;
case Remove:
{
final String message = String.format("Analysis result for %s was removed unexpectedly", resource);
logger.error(message);
observer.onError(new AnalysisException(context, message));
break;
}
default:
{
final String message = String.format("Unexpected analysis update kind %s for %s", update.kind, resource);
logger.error(message);
observer.onError(new MetaborgRuntimeException(message));
break;
}
}
}
});
}
Aggregations