io.reactivex.Scheduler Java Examples
The following examples show how to use
io.reactivex.Scheduler.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RxJava2CachedCallAdapter.java From retrocache with Apache License 2.0 | 6 votes |
RxJava2CachedCallAdapter(Cache<String, byte[]> cachingSystem, Type responseType, Scheduler scheduler, Retrofit retrofit, Annotation[] annotations, boolean mAsync, boolean mResult, boolean mBody, boolean mFlowable, boolean mSingle, boolean mMaybe, boolean mCompletable) { this.mCachingSystem = cachingSystem; this.mResponseType = responseType; this.mScheduler = scheduler; this.mRetrofit = retrofit; this.mAnnotations = annotations; this.mAsync = mAsync; this.mResult = mResult; this.mBody = mBody; this.mFlowable = mFlowable; this.mSingle = mSingle; this.mMaybe = mMaybe; this.mCompletable = mCompletable; }
Example #2
Source File: AndroidSchedulersRule.java From RIBs with Apache License 2.0 | 6 votes |
@Override protected void starting(Description description) { if (restoreHandlers) { // https://github.com/ReactiveX/RxAndroid/pull/358 // originalInitMainThreadInitHandler = // RxAndroidPlugins.getInitMainThreadScheduler(); // originalMainThreadHandler = RxAndroidPlugins.getMainThreadScheduler(); } RxAndroidPlugins.reset(); RxAndroidPlugins.setInitMainThreadSchedulerHandler( new Function<Callable<Scheduler>, Scheduler>() { @Override public Scheduler apply(Callable<Scheduler> schedulerCallable) throws Exception { return delegatingMainThreadScheduler; } }); RxAndroidPlugins.setMainThreadSchedulerHandler( new Function<Scheduler, Scheduler>() { @Override public Scheduler apply(Scheduler scheduler) throws Exception { return delegatingMainThreadScheduler; } }); }
Example #3
Source File: DisconnectOperation.java From RxAndroidBle with Apache License 2.0 | 6 votes |
@Inject DisconnectOperation( RxBleGattCallback rxBleGattCallback, BluetoothGattProvider bluetoothGattProvider, @Named(DeviceModule.MAC_ADDRESS) String macAddress, BluetoothManager bluetoothManager, @Named(ClientComponent.NamedSchedulers.BLUETOOTH_INTERACTION) Scheduler bluetoothInteractionScheduler, @Named(DeviceModule.DISCONNECT_TIMEOUT) TimeoutConfiguration timeoutConfiguration, ConnectionStateChangeListener connectionStateChangeListener) { this.rxBleGattCallback = rxBleGattCallback; this.bluetoothGattProvider = bluetoothGattProvider; this.macAddress = macAddress; this.bluetoothManager = bluetoothManager; this.bluetoothInteractionScheduler = bluetoothInteractionScheduler; this.timeoutConfiguration = timeoutConfiguration; this.connectionStateChangeListener = connectionStateChangeListener; }
Example #4
Source File: Sandbox.java From Reactive-Android-Programming with MIT License | 6 votes |
private static void demo2() throws Exception { final ExecutorService executor = Executors.newFixedThreadPool(1000); final Scheduler pooledScheduler = Schedulers.from(executor); Observable.range(1, 10000) .flatMap(i -> Observable.just(i) .subscribeOn(pooledScheduler) .map(Sandbox::importantLongTask) ) .doOnTerminate(WAIT_LATCH::countDown) .map(Object::toString) .subscribe(e -> log("subscribe", e)); WAIT_LATCH.await(); executor.shutdown(); }
Example #5
Source File: CharacteristicLongWriteOperation.java From RxAndroidBle with Apache License 2.0 | 6 votes |
CharacteristicLongWriteOperation( BluetoothGatt bluetoothGatt, RxBleGattCallback rxBleGattCallback, @Named(ClientComponent.NamedSchedulers.BLUETOOTH_INTERACTION) Scheduler bluetoothInteractionScheduler, @Named(ConnectionModule.OPERATION_TIMEOUT) TimeoutConfiguration timeoutConfiguration, BluetoothGattCharacteristic bluetoothGattCharacteristic, PayloadSizeLimitProvider batchSizeProvider, WriteOperationAckStrategy writeOperationAckStrategy, WriteOperationRetryStrategy writeOperationRetryStrategy, byte[] bytesToWrite) { this.bluetoothGatt = bluetoothGatt; this.rxBleGattCallback = rxBleGattCallback; this.bluetoothInteractionScheduler = bluetoothInteractionScheduler; this.timeoutConfiguration = timeoutConfiguration; this.bluetoothGattCharacteristic = bluetoothGattCharacteristic; this.batchSizeProvider = batchSizeProvider; this.writeOperationAckStrategy = writeOperationAckStrategy; this.writeOperationRetryStrategy = writeOperationRetryStrategy; this.bytesToWrite = bytesToWrite; }
Example #6
Source File: RxBus.java From YiZhi with Apache License 2.0 | 6 votes |
/** * 用于处理订阅事件在那个线程中执行 * * @param observable d * @param subscriberMethod d * @return Observable */ private Flowable postToObservable(Flowable observable, SubscriberMethod subscriberMethod) { Scheduler scheduler; switch (subscriberMethod.threadMode) { case MAIN: scheduler = AndroidSchedulers.mainThread(); break; case NEW_THREAD: scheduler = Schedulers.newThread(); break; case CURRENT_THREAD: scheduler = Schedulers.trampoline(); break; default: throw new IllegalStateException("Unknown thread mode: " + subscriberMethod.threadMode); } return observable.observeOn(scheduler); }
Example #7
Source File: DownloadTaskImpl.java From MyBookshelf with GNU General Public License v3.0 | 6 votes |
private void whenError(Scheduler scheduler) { if (!isDownloading) { return; } if (isFinishing()) { stopDownload(); if (downloadBook.getSuccessCount() == 0) { onDownloadError(downloadBook); } else { onDownloadComplete(downloadBook); } } else { toDownload(scheduler); } }
Example #8
Source File: RxBus.java From RxBus2 with Apache License 2.0 | 6 votes |
/** * 用于处理订阅事件在那个线程中执行 * * @param observable d * @param subscriberMethod d * @return Observable */ private Flowable postToObservable(Flowable observable, SubscriberMethod subscriberMethod) { Scheduler scheduler; switch (subscriberMethod.threadMode) { case MAIN: scheduler = AndroidSchedulers.mainThread(); break; case NEW_THREAD: scheduler = Schedulers.newThread(); break; case CURRENT_THREAD: scheduler = Schedulers.trampoline(); break; default: throw new IllegalStateException("Unknown thread mode: " + subscriberMethod.threadMode); } return observable.observeOn(scheduler); }
Example #9
Source File: BriteContentResolver.java From sqlbrite with Apache License 2.0 | 5 votes |
BriteContentResolver(ContentResolver contentResolver, Logger logger, Scheduler scheduler, ObservableTransformer<Query, Query> queryTransformer) { this.contentResolver = contentResolver; this.logger = logger; this.scheduler = scheduler; this.queryTransformer = queryTransformer; }
Example #10
Source File: Transformers.java From rxjava2-extras with Apache License 2.0 | 5 votes |
/** * Buffers the source {@link Flowable} into {@link List}s, emitting Lists when * the size of a list reaches {@code maxSize} or if the elapsed time since last * emission from the source reaches the given duration. * * @param maxSize * max size of emitted lists * @param duration * function that based on the last emission calculates the elapsed * time to be used before emitting a buffered list * @param unit * unit of {@code duration} * @param scheduler * scheduler to use to schedule emission of a buffer (as a list) if * the time since last emission from the source reaches duration * @param <T> * type of the source stream items * @return source with operator applied */ public static <T> FlowableTransformer<T, List<T>> buffer(final int maxSize, final Function<? super T, ? extends Long> duration, final TimeUnit unit, final Scheduler scheduler) { final BiPredicate<List<T>, MyOptional<T>> condition = new BiPredicate<List<T>, MyOptional<T>>() { @Override public boolean test(List<T> list, MyOptional<T> x) throws Exception { return list.size() < maxSize && x.isPresent(); } }; Function<MyOptional<T>, Long> timeout = new Function<MyOptional<T>, Long>() { @Override public Long apply(MyOptional<T> t) throws Exception { return duration.apply(t.get()); } }; final FlowableTransformer<MyOptional<T>, MyOptional<T>> insert = insert(timeout, unit, Functions.constant(MyOptional.<T>empty()), scheduler); final FlowableTransformer<MyOptional<T>, List<T>> collectWhile = collectWhile( // // factory ListFactoryHolder.<T>factory(), // // add function MyOptional.<T>addIfPresent(), // // condition condition); return new FlowableTransformer<T, List<T>>() { @Override public Publisher<List<T>> apply(Flowable<T> source) { return source // .map(MyOptional.<T>of()) // .compose(insert) // .compose(collectWhile) // need this filter because sometimes nothing gets added to list .filter(MyOptional.<T>listHasElements()); // } }; }
Example #11
Source File: RxAndroidPlugins.java From atlas with Apache License 2.0 | 5 votes |
static Scheduler applyRequireNonNull(Function<Callable<Scheduler>, Scheduler> f, Callable<Scheduler> s) { Scheduler scheduler = apply(f,s); if (scheduler == null) { throw new NullPointerException("Scheduler Callable returned null"); } return scheduler; }
Example #12
Source File: RxJavaUtils.java From storio with Apache License 2.0 | 5 votes |
@CheckResult @NonNull public static Completable subscribeOn( @NonNull StorIOSQLite storIOSQLite, @NonNull Completable completable ) { final Scheduler scheduler = storIOSQLite.defaultRxScheduler(); return scheduler != null ? completable.subscribeOn(scheduler) : completable; }
Example #13
Source File: StorageClient.java From java-unified-sdk with Apache License 2.0 | 5 votes |
private Observable wrapObservableInBackground(Observable observable) { if (null == observable) { return null; } Scheduler scheduler = Schedulers.io(); if (asynchronized) { observable = observable.subscribeOn(scheduler); } if (null != defaultCreator) { observable = observable.observeOn(scheduler); } return observable; }
Example #14
Source File: ThreadHelper.java From AndroidGodEye with Apache License 2.0 | 5 votes |
public static void setupRxjava() { TestScheduler testScheduler = new TestScheduler(); RxJavaPlugins.setComputationSchedulerHandler(new Function<Scheduler, Scheduler>() { @Override public Scheduler apply(Scheduler scheduler) throws Exception { return testScheduler; } }); }
Example #15
Source File: DelegatingIdlingResourceSchedulerTest.java From RxIdler with Apache License 2.0 | 5 votes |
@Test public void runningWorkReportsBusy() { Scheduler.Worker worker = scheduler.createWorker(); worker.schedule(new Runnable() { @Override public void run() { assertBusy(); } }); delegate.triggerActions(); }
Example #16
Source File: RxReporter.java From buffer-slayer with Apache License 2.0 | 5 votes |
private MessageGroupSubscriber(long messageTimeoutNanos, int bufferedMaxMessages, Sender<M, R> sender, Scheduler scheduler) { this.messageTimeoutNanos = messageTimeoutNanos == 0 ? Long.MAX_VALUE : messageTimeoutNanos; this.bufferedMaxMessages = bufferedMaxMessages; this.sender = sender; this.scheduler = scheduler; }
Example #17
Source File: ConcurrencyTest.java From Java-programming-methodology-Rxjava-articles with Apache License 2.0 | 5 votes |
@Test void custom_Scheduler_test() { Scheduler customScheduler = custom_Scheduler(); Observable.just("Apple", "Orange", "Appla") .subscribeOn(customScheduler) .map(ConcurrencyTest::delayCalculation) .observeOn(customScheduler) .map(String::length) .subscribe(ConcurrencyTest::log); sleep(10000); }
Example #18
Source File: Ob1G5CollectionService.java From xDrip with GNU General Public License v3.0 | 5 votes |
@NonNull @Override public Observable<Void> asObservable(BluetoothGatt bluetoothGatt, RxBleGattCallback rxBleGattCallback, Scheduler scheduler) throws Throwable { return Observable.fromCallable(() -> refreshDeviceCache(bluetoothGatt)) .delay(delay_ms, TimeUnit.MILLISECONDS, Schedulers.computation()) .subscribeOn(scheduler); }
Example #19
Source File: Code5.java From rxjava2-lab with Apache License 2.0 | 5 votes |
public static void main(String[] args) throws Exception { Scheduler scheduler = Schedulers.from(newFixedThreadPool(10, threadFactory)); CountDownLatch latch = new CountDownLatch(1); // Synchronous emission Observable<Object> observable = Observable.create(emitter -> { for (String superHero : SUPER_HEROES) { log("Emitting: " + superHero); emitter.onNext(superHero); } log("Completing"); emitter.onComplete(); }); log("---------------- Subscribing"); observable .subscribeOn(scheduler) .subscribe( item -> log("Received " + item), error -> log("Error"), () -> { log("Complete"); latch.countDown(); }); log("---------------- Subscribed"); latch.await(); }
Example #20
Source File: SendAssetInteractor.java From iroha-android with Apache License 2.0 | 5 votes |
@Inject SendAssetInteractor(@Named(ApplicationModule.JOB) Scheduler jobScheduler, @Named(ApplicationModule.UI) Scheduler uiScheduler, ManagedChannel managedChannel, PreferencesUtil preferencesUtil) { super(jobScheduler, uiScheduler); this.channel = managedChannel; this.preferenceUtils = preferencesUtil; }
Example #21
Source File: BriteDatabase.java From sqlbrite with Apache License 2.0 | 5 votes |
BriteDatabase(SupportSQLiteOpenHelper helper, Logger logger, Scheduler scheduler, ObservableTransformer<Query, Query> queryTransformer) { this.helper = helper; this.logger = logger; this.scheduler = scheduler; this.queryTransformer = queryTransformer; }
Example #22
Source File: RxJavaUtils.java From storio with Apache License 2.0 | 5 votes |
@CheckResult @NonNull public static <T> Flowable<T> subscribeOn( @NonNull StorIOContentResolver storIOContentResolver, @NonNull Flowable<T> flowable ) { final Scheduler scheduler = storIOContentResolver.defaultRxScheduler(); return scheduler != null ? flowable.subscribeOn(scheduler) : flowable; }
Example #23
Source File: LatestOverflowStrategyTest.java From smallrye-reactive-messaging with Apache License 2.0 | 5 votes |
@Incoming("hello") @Outgoing("out") public Flowable<String> consume(Flowable<String> values) { Scheduler scheduler = Schedulers.from(executor); return values .observeOn(scheduler) .delay(1, TimeUnit.MILLISECONDS, scheduler) .doOnError(err -> { downstreamFailure = err; }); }
Example #24
Source File: SetOperationTests.java From java-unified-sdk with Apache License 2.0 | 5 votes |
public SetOperationTests(String testName) { super(testName); AppConfiguration.config(true, new AppConfiguration.SchedulerCreator() { public Scheduler create() { return Schedulers.newThread(); } }); Configure.initializeRuntime(); }
Example #25
Source File: AdamantApiWrapper.java From adamant-android with GNU General Public License v3.0 | 5 votes |
public AdamantApiWrapper(AdamantApiBuilder apiBuilder, AdamantKeyGenerator keyGenerator, Scheduler scheduler) { this.apiBuilder = apiBuilder; this.keyGenerator = keyGenerator; this.scheduler = scheduler; buildApi(); }
Example #26
Source File: JamBaseBluetoothService.java From xDrip with GNU General Public License v3.0 | 5 votes |
@NonNull @Override public Observable<Void> asObservable(BluetoothGatt bluetoothGatt, RxBleGattCallback rxBleGattCallback, Scheduler scheduler) throws Throwable { return Observable.fromCallable(() -> refreshDeviceCache(bluetoothGatt)) .delay(delay_ms, TimeUnit.MILLISECONDS, Schedulers.computation()) .subscribeOn(scheduler); }
Example #27
Source File: GetAccountTransactionsInteractor.java From iroha-android with Apache License 2.0 | 5 votes |
@Inject GetAccountTransactionsInteractor(@Named(ApplicationModule.JOB) Scheduler jobScheduler, @Named(ApplicationModule.UI) Scheduler uiScheduler, PreferencesUtil preferenceUtils, ManagedChannel channel) { super(jobScheduler, uiScheduler); this.preferenceUtils = preferenceUtils; this.channel = channel; }
Example #28
Source File: AVObjectAsyncTest.java From java-unified-sdk with Apache License 2.0 | 5 votes |
public AVObjectAsyncTest(String testName) { super(testName); AppConfiguration.config(true, new AppConfiguration.SchedulerCreator() { public Scheduler create() { return Schedulers.newThread(); } }); Configure.initializeRuntime(); }
Example #29
Source File: DatabaseCreator.java From rxjava2-jdbc with Apache License 2.0 | 5 votes |
public static Database create(int maxSize, boolean big, Scheduler scheduler) { NonBlockingConnectionPool pool = Pools.nonBlocking() // .connectionProvider(connectionProvider(nextUrl(), big)) // .maxPoolSize(maxSize) // .scheduler(scheduler) // .build(); return Database.from(pool, () -> { pool.close(); scheduler.shutdown(); }); }
Example #30
Source File: UIThread.java From Android-CleanArchitecture with Apache License 2.0 | 4 votes |
@Override public Scheduler getScheduler() { return AndroidSchedulers.mainThread(); }