本文整理汇总了Java中io.reactivex.BackpressureStrategy类的典型用法代码示例。如果您正苦于以下问题:Java BackpressureStrategy类的具体用法?Java BackpressureStrategy怎么用?Java BackpressureStrategy使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
BackpressureStrategy类属于io.reactivex包,在下文中一共展示了BackpressureStrategy类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: post
import io.reactivex.BackpressureStrategy; //导入依赖的package包/类
/**
* Post请求的Rxjava方式.
* @param url
* @param requestParams
* @return
*/
public <T> Flowable<T> post(String url, EasyRequestParams requestParams, RxEasyConverter<T> rxEasyConverter) {
FormBody.Builder builder = new FormBody.Builder();
ConcurrentHashMap<String, String> paramsMap = requestParams.getRequestParams();
for (ConcurrentHashMap.Entry<String, String> entry : paramsMap.entrySet()) {
builder.add(entry.getKey(), entry.getValue());
}
RequestBody requestBody = builder.build();
final Request request = new Request.Builder()
.url(url)
.post(requestBody)
.build();
Call call = EasyHttpClientManager.getInstance().getOkHttpClient(EasyCacheType.CACHE_TYPE_DEFAULT).newCall(request);
return Flowable.create(new CallFlowableOnSubscribe(call,rxEasyConverter), BackpressureStrategy.BUFFER)
.subscribeOn(Schedulers.io());
}
示例2: startLocationUpdates
import io.reactivex.BackpressureStrategy; //导入依赖的package包/类
@SuppressWarnings("MissingPermission")
@RequiresPermission(anyOf = {
Manifest.permission.ACCESS_COARSE_LOCATION,
Manifest.permission.ACCESS_FINE_LOCATION
})
public void startLocationUpdates(boolean checkLocationSettings) {
stopLocationUpdates();
locationUpdatesDisposable = locationSettingsCheck(checkLocationSettings)
.flatMapObservable(ignore -> locationUpdates()
.startWith(lastLocation()))
.map(this::transformLocation)
.toFlowable(BackpressureStrategy.LATEST)
.observeOn(AndroidSchedulers.mainThread())
.subscribe(this::setLocation,
error -> Timber.e("Failed to get location updates", error));
}
示例3: onImageCapture
import io.reactivex.BackpressureStrategy; //导入依赖的package包/类
@Override
public void onImageCapture(@Nullable byte[] imageBytes) {
//Process the image using Tf.
Flowable<BarcodeInfo> flowable = Flowable.create(e -> {
Bitmap bitmap = null;
if (imageBytes != null) bitmap = CameraUtils.bytesToBitmap(imageBytes);
if (bitmap != null) e.onNext(mBarcodeScanner.scan(bitmap));
e.onComplete();
}, BackpressureStrategy.DROP);
final Subscription[] subscriptions = new Subscription[1];
flowable.subscribeOn(Schedulers.computation())
.observeOn(AndroidSchedulers.mainThread())
.doOnSubscribe(subscription -> subscriptions[0] = subscription)
.doOnError(t -> {
Timber.e(t.getMessage());
subscriptions[0].cancel();
})
.doOnComplete(() -> subscriptions[0].cancel())
.subscribe(barcodeInfo -> {
//TODO Display the info
});
}
示例4: asyncMethod
import io.reactivex.BackpressureStrategy; //导入依赖的package包/类
private void asyncMethod(final ProceedingJoinPoint joinPoint) throws Throwable {
Flowable.create(new FlowableOnSubscribe<Object>() {
@Override
public void subscribe(FlowableEmitter<Object> e) throws Exception {
Looper.prepare();
try {
joinPoint.proceed();
} catch (Throwable throwable) {
throwable.printStackTrace();
}
Looper.loop();
}
}
, BackpressureStrategy.BUFFER)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe();
}
示例5: main
import io.reactivex.BackpressureStrategy; //导入依赖的package包/类
public static void main(String[] args) {
// TODO Auto-generated method stub
Flowable<String> month_maybe = Flowable.create(emitter -> {
try {
String[] monthArray = { "Jan", "Feb", "Mar", "Apl", "May", "Jun", "July", "Aug", "Sept", "Oct", "Nov",
"Dec" };
List<String> months = Arrays.asList(monthArray);
for (String month : months) {
emitter.onNext(month);
}
emitter.onComplete();
} catch (Exception e) {
emitter.onError(e);
}
},BackpressureStrategy.MISSING);
month_maybe.subscribe(s -> System.out.println(s));
}
示例6: shouldPassMessageToLocalStreamWhenSendMessage
import io.reactivex.BackpressureStrategy; //导入依赖的package包/类
@Test
public void shouldPassMessageToLocalStreamWhenSendMessage() throws Exception {
String message = "hello @alex http://youtube.com/q=look (love) there @yui you go http://twitter.com";
final List<Link> expectedLinks = asList(
new Link("http://youtube.com/q=look", ""),
new Link("http://twitter.com", ""));
when(userResolver.getLoggedInUser()).thenReturn(TestUtils.createMockUser());
final TestSubscriber<Message> userTestSubscriber = new TestSubscriber<>();
final Observable<Message> messageViewModelMessages = messageViewModel.localMessageStream();
messageViewModelMessages.toFlowable(BackpressureStrategy.LATEST).subscribe(userTestSubscriber);
final Message m = new Message(id, message, Arrays.asList("alex", "yui"),
Arrays.asList("love"), expectedLinks, TestUtils.createMockUser());
messageViewModel.sendMessage(message, Arrays.asList("love"), sendScheduler);
userTestSubscriber.assertValue(m);
}
示例7: main
import io.reactivex.BackpressureStrategy; //导入依赖的package包/类
public static void main(String[] args) throws IOException {
ReactiveJournal reactiveJournal = new ReactiveJournal("/tmp/fastproducer");
reactiveJournal.clearCache();
Flowable<Long> fastProducer = FastProducerSlowConsumer.createFastProducer(BackpressureStrategy.MISSING, 500);
reactiveJournal.createReactiveRecorder().recordAsync(fastProducer,"input");
PlayOptions options = new PlayOptions().filter("input").replayRate(PlayOptions.ReplayRate.FAST);
Flowable journalInput = new RxJavaPlayer(reactiveJournal).play(options);
Consumer onNextSlowConsumer = FastProducerSlowConsumer.createOnNextSlowConsumer(10);
long startTime = System.currentTimeMillis();
journalInput.subscribe(onNextSlowConsumer::accept,
e -> System.out.println("ReactiveRecorder " + " " + e),
() -> System.out.println("ReactiveRecorder complete [" + (System.currentTimeMillis()-startTime) + "]")
);
}
示例8: RxReporter
import io.reactivex.BackpressureStrategy; //导入依赖的package包/类
private RxReporter(Builder<M, R> builder) {
this.sender = builder.sender;
this.metrics = builder.metrics;
this.messageTimeoutNanos = builder.messageTimeoutNanos;
this.bufferedMaxMessages = builder.bufferedMaxMessages;
this.pendingMaxMessages = builder.pendingMaxMessages;
this.overflowStrategy = builder.overflowStrategy;
this.scheduler = builder.scheduler;
Flowable<SendingTask<M>> flowable = Flowable.create(this, BackpressureStrategy.MISSING);
initBackpressurePolicy(flowable)
.observeOn(Schedulers.single())
.groupBy(new MessagePartitioner())
.subscribe(new MessageGroupSubscriber(messageTimeoutNanos, bufferedMaxMessages, sender, scheduler));
}
示例9: testUpdatesChecked
import io.reactivex.BackpressureStrategy; //导入依赖的package包/类
@Test
public void testUpdatesChecked() throws Exception {
RxPaperBook book = RxPaperBook.with("UPDATES_CH", Schedulers.trampoline());
final String key = "hello";
final ComplexObject value = ComplexObject.random();
final TestSubscriber<ComplexObject> updatesSubscriber = TestSubscriber.create();
book.observe(key, ComplexObject.class, BackpressureStrategy.MISSING).subscribe(updatesSubscriber);
updatesSubscriber.assertValueCount(0);
book.write(key, value).subscribe();
updatesSubscriber.assertValueCount(1);
updatesSubscriber.assertValues(value);
final ComplexObject newValue = ComplexObject.random();
book.write(key, newValue).subscribe();
updatesSubscriber.assertValueCount(2);
updatesSubscriber.assertValues(value, newValue);
// Error value
final int wrongValue = 3;
book.write(key, wrongValue).test().assertComplete().assertNoErrors();
updatesSubscriber.assertValueCount(2);
updatesSubscriber.assertValues(value, newValue);
updatesSubscriber.assertNoErrors();
}
示例10: createYourOwnTibco
import io.reactivex.BackpressureStrategy; //导入依赖的package包/类
@Test
public void createYourOwnTibco() throws Exception {
Flowable<String> flowable = Flowable.create(new FlowableOnSubscribe<String>() {
@Override
public void subscribe(FlowableEmitter<String> e) throws Exception {
while (!e.isCancelled()) {
long numberRecords = e.requested();
System.out.println(numberRecords);
if (numberRecords > 0) {
}
}
}
}, BackpressureStrategy.BUFFER);
flowable.map(x -> x + "Yay!").subscribe(System.out::println);
}
示例11: forFlowable
import io.reactivex.BackpressureStrategy; //导入依赖的package包/类
private <T> Flowable<T> forFlowable(Flowable<T> source, BackpressureStrategy backpressureStrategy) {
return Flowable.using(this::makeDialog,
new Function<ProgressDialog, Publisher<? extends T>>() {
@Override
public Publisher<? extends T> apply(@NonNull ProgressDialog dialog) throws Exception {
return Flowable.create(emitter -> {
if (builder.cancelable) {
dialog.setOnCancelListener(dialogInterface -> emitter.onComplete());
}
dialog.setOnDismissListener(dialogInterface -> emitter.onComplete());
source.subscribe(emitter::onNext, emitter::onError, emitter::onComplete);
}, backpressureStrategy);
}
}, Dialog::dismiss);
}
示例12: shouldReturnApiStream
import io.reactivex.BackpressureStrategy; //导入依赖的package包/类
@Test
public void shouldReturnApiStream() throws Exception {
final TestSubscriber<Message> userTestSubscriber = new TestSubscriber<>();
final Observable<Message> messageViewModelMessages = messageViewModel.apiSendMessageStream();
messageViewModelMessages.toFlowable(BackpressureStrategy.LATEST).subscribe(userTestSubscriber);
userTestSubscriber.assertNoErrors();
userTestSubscriber.assertNoValues();
}
示例13: getTasks
import io.reactivex.BackpressureStrategy; //导入依赖的package包/类
@Override
public Flowable<List<Task>> getTasks() {
String[] projection = {
TaskEntry.COLUMN_NAME_ENTRY_ID,
TaskEntry.COLUMN_NAME_TITLE,
TaskEntry.COLUMN_NAME_DESCRIPTION,
TaskEntry.COLUMN_NAME_COMPLETED
};
String sql = String.format("SELECT %s FROM %s", TextUtils.join(",", projection), TaskEntry.TABLE_NAME);
return mDatabaseHelper.createQuery(TaskEntry.TABLE_NAME, sql)
.mapToList(mTaskMapperFunction)
.toFlowable(BackpressureStrategy.BUFFER);
}
示例14: getTask
import io.reactivex.BackpressureStrategy; //导入依赖的package包/类
@Override
public Flowable<Optional<Task>> getTask(@NonNull String taskId) {
String[] projection = {
TaskEntry.COLUMN_NAME_ENTRY_ID,
TaskEntry.COLUMN_NAME_TITLE,
TaskEntry.COLUMN_NAME_DESCRIPTION,
TaskEntry.COLUMN_NAME_COMPLETED
};
String sql = String.format("SELECT %s FROM %s WHERE %s LIKE ?",
TextUtils.join(",", projection), TaskEntry.TABLE_NAME, TaskEntry.COLUMN_NAME_ENTRY_ID);
return mDatabaseHelper.createQuery(TaskEntry.TABLE_NAME, sql, taskId)
.mapToOneOrDefault(cursor -> Optional.of(mTaskMapperFunction.apply(cursor)), Optional.<Task>absent())
.toFlowable(BackpressureStrategy.BUFFER);
}
示例15: adapt
import io.reactivex.BackpressureStrategy; //导入依赖的package包/类
@Override public Object adapt(Call<R> call) {
Observable<Response<R>> responseObservable = isAsync
? new CallEnqueueObservable<>(call)
: new CallExecuteObservable<>(call);
Observable<?> observable;
if (isResult) {
observable = new ResultObservable<>(responseObservable);
} else if (isBody) {
observable = new BodyObservable<>(responseObservable);
} else {
observable = responseObservable;
}
if (scheduler != null) {
observable = observable.subscribeOn(scheduler);
}
if (isFlowable) {
return observable.toFlowable(BackpressureStrategy.LATEST);
}
if (isSingle) {
return observable.singleOrError();
}
if (isMaybe) {
return observable.singleElement();
}
if (isCompletable) {
return observable.ignoreElements();
}
return observable;
}