当前位置: 首页>>代码示例>>Java>>正文


Java BackpressureStrategy类代码示例

本文整理汇总了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());
}
 
开发者ID:LaurenceYang,项目名称:EasyHttp,代码行数:25,代码来源:RxEasyHttpManager.java

示例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));
}
 
开发者ID:BANKEX,项目名称:smart-asset-iot-android-demo,代码行数:17,代码来源:RxLocationManager.java

示例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
            });
}
 
开发者ID:kevalpatel2106,项目名称:smart-lens,代码行数:24,代码来源:BarcodeScannerFragment.java

示例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();
    }
 
开发者ID:fengzhizi715,项目名称:SAF-AOP,代码行数:20,代码来源:AsyncAspect.java

示例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));

}
 
开发者ID:PacktPublishing,项目名称:Reactive-Programming-With-Java-9,代码行数:21,代码来源:DemoFlowable.java

示例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);

}
 
开发者ID:charafau,项目名称:TurboChat,代码行数:22,代码来源:MessageViewModelTest.java

示例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) + "]")
        );

    }
 
开发者ID:danielshaya,项目名称:reactivejournal,代码行数:20,代码来源:RxJournalBackPressureBuffer.java

示例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));
}
 
开发者ID:tramchamploo,项目名称:buffer-slayer,代码行数:17,代码来源:RxReporter.java

示例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();
}
 
开发者ID:pakoito,项目名称:RxPaper2,代码行数:23,代码来源:RxPaperBookTest.java

示例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);
}
 
开发者ID:dhinojosa,项目名称:rxjavatraining,代码行数:18,代码来源:TibcoObservableTest.java

示例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);
}
 
开发者ID:datalink747,项目名称:RxProgress,代码行数:16,代码来源:RxProgress.java

示例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();

}
 
开发者ID:charafau,项目名称:TurboChat,代码行数:12,代码来源:MessageViewModelTest.java

示例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);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:14,代码来源:TasksLocalDataSource.java

示例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);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:15,代码来源:TasksLocalDataSource.java

示例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;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:33,代码来源:RxJava2CallAdapter.java


注:本文中的io.reactivex.BackpressureStrategy类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。