當前位置: 首頁>>代碼示例>>Java>>正文


Java Scheduler類代碼示例

本文整理匯總了Java中io.reactivex.Scheduler的典型用法代碼示例。如果您正苦於以下問題:Java Scheduler類的具體用法?Java Scheduler怎麽用?Java Scheduler使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Scheduler類屬於io.reactivex包,在下文中一共展示了Scheduler類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: starting

import io.reactivex.Scheduler; //導入依賴的package包/類
@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;
        }
      });
}
 
開發者ID:uber,項目名稱:RIBs,代碼行數:25,代碼來源:AndroidSchedulersRule.java

示例2: defaultMainThreadSchedulerIsInitializedLazily

import io.reactivex.Scheduler; //導入依賴的package包/類
@Test
public void defaultMainThreadSchedulerIsInitializedLazily() {
	Function<Callable<Scheduler>, Scheduler> safeOverride = new Function<Callable<Scheduler>, Scheduler>() {
		@Override
		public Scheduler apply(Callable<Scheduler> scheduler) {
			return new EmptyScheduler();
		}
	};
	Callable<Scheduler> unsafeDefault = new Callable<Scheduler>() {
		@Override
		public Scheduler call() throws Exception {
			throw new AssertionError();
		}
	};

	RxSwtPlugins.setInitMainThreadSchedulerHandler(safeOverride);
	RxSwtPlugins.initMainThreadScheduler(unsafeDefault);
}
 
開發者ID:SimonScholz,項目名稱:RxSWT,代碼行數:19,代碼來源:RxSwtPluginsTest.java

示例3: demo2

import io.reactivex.Scheduler; //導入依賴的package包/類
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(Objects::toString)
            .subscribe(e -> log("subscribe", e));

    WAIT_LATCH.await();
    executor.shutdown();
}
 
開發者ID:PacktPublishing,項目名稱:Reactive-Android-Programming,代碼行數:17,代碼來源:Sandbox.java

示例4: initExtractScheduler

import io.reactivex.Scheduler; //導入依賴的package包/類
/**
 * Initializes a scheduler that will be used for offloading IO work performed by {@link Extract}s
 * <p/>
 * <p/> Threads executed on this scheduler have {@link Thread#NORM_PRIORITY}
 * @param ioPoolSize Size of thread pool for this scheduler
 */
private Scheduler initExtractScheduler(Integer ioPoolSize) {
    ThreadFactory factory = newThreadFactory("TaskManager-Extract-%s", Thread.NORM_PRIORITY);
    ExecutorService executor = Executors.newFixedThreadPool(ioPoolSize, factory);
    shutdownHook.registerExecutor(executor);
    return Schedulers.from(executor);
}
 
開發者ID:salesforce,項目名稱:pyplyn,代碼行數:13,代碼來源:TaskManager.java

示例5: testapplyRequireNonNullThrowsNPE

import io.reactivex.Scheduler; //導入依賴的package包/類
@Test(expected = NullPointerException.class)
public void testapplyRequireNonNullThrowsNPE() {
	RxSwtPlugins.applyRequireNonNull(new Function<Callable<Scheduler>, Scheduler>() {

		@Override
		public Scheduler apply(Callable<Scheduler> t) throws Exception {
			return null;
		}
	}, null);
}
 
開發者ID:SimonScholz,項目名稱:RxSWT,代碼行數:11,代碼來源:RxSwtPluginsTest.java

示例6: init

import io.reactivex.Scheduler; //導入依賴的package包/類
@BeforeClass public static void init() throws Exception {
  // Tell RxAndroid to not use android main ui thread scheduler
  RxAndroidPlugins.setInitMainThreadSchedulerHandler(
      new Function<Callable<Scheduler>, Scheduler>() {
        @Override public Scheduler apply(@NonNull Callable<Scheduler> schedulerCallable)
            throws Exception {
          return Schedulers.trampoline();
        }
      });
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:11,代碼來源:HomePresenterTest.java

示例7: initLoadScheduler

import io.reactivex.Scheduler; //導入依賴的package包/類
/**
 * Initializes a scheduler that will be used for offloading IO work performed by {@link Load}s
 * <p/>
 * <p/> Threads executed on this scheduler have {@link Thread#NORM_PRIORITY}+2
 * @param ioPoolSize Size of thread pool for this scheduler
 */
private Scheduler initLoadScheduler(Integer ioPoolSize) {
    ThreadFactory factory = newThreadFactory("TaskManager-Load-%s", Thread.NORM_PRIORITY + 2);
    ExecutorService executor = Executors.newFixedThreadPool(ioPoolSize, factory);
    shutdownHook.registerExecutor(executor);
    return Schedulers.from(executor);
}
 
開發者ID:salesforce,項目名稱:pyplyn,代碼行數:13,代碼來源:TaskManager.java

示例8: applyRequireNonNull

import io.reactivex.Scheduler; //導入依賴的package包/類
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;
}
 
開發者ID:SimonScholz,項目名稱:RxSWT,代碼行數:8,代碼來源:RxSwtPlugins.java

示例9: applyAsync

import io.reactivex.Scheduler; //導入依賴的package包/類
/**
 * Overrides the default implementation, to simplify implementing async transforms
 * <p/>
 * <p/> {@link PollingTransform}s are observed on the specified scheduler
 */
@Override
public Flowable<List<List<Transmutation>>> applyAsync(List<List<Transmutation>> input, Scheduler scheduler) {
    // determine if the implementing class should run
    if (skipTransform(input)) {
        return Flowable.just(input);
    }

    // remove items that should not be processed
    List<List<Transmutation>> toProcess = filter(input);
    if (isNull(toProcess)) {
        logger.info("Stopping processing in {} due to threshold not met...", this.getClass().getSimpleName());
        return Flowable.empty();
    }

    return Flowable.just(toProcess)
            .observeOn(scheduler)

            // send payload
            .map(this::sendRequest)

            .flatMap(req -> tryRetrieve(req, -1))

            // or timeout after the specified number of ms
            .timeout(timeoutMillis(), TimeUnit.MILLISECONDS)
            .doOnError(this::logAsyncError)
            .onErrorResumeNext(Flowable.empty());
}
 
開發者ID:salesforce,項目名稱:pyplyn,代碼行數:33,代碼來源:PollingTransform.java

示例10: getInitMainThreadSchedulerHandlerReturnsHandler

import io.reactivex.Scheduler; //導入依賴的package包/類
@Test
public void getInitMainThreadSchedulerHandlerReturnsHandler() {
    Function<Callable<Scheduler>, Scheduler> handler = new Function<Callable<Scheduler>, Scheduler>() {
        @Override public Scheduler apply(Callable<Scheduler> schedulerCallable) throws Exception {
            return Schedulers.trampoline();
        }
    };
    RxAndroidPlugins.setInitMainThreadSchedulerHandler(handler);
    assertSame(handler, RxAndroidPlugins.getInitMainThreadSchedulerHandler());
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:11,代碼來源:RxAndroidPluginsTest.java

示例11: RxJava2CallAdapter

import io.reactivex.Scheduler; //導入依賴的package包/類
RxJava2CallAdapter(Type responseType, Scheduler scheduler, boolean isAsync, boolean isResult,
    boolean isBody, boolean isFlowable, boolean isSingle, boolean isMaybe,
    boolean isCompletable) {
  this.responseType = responseType;
  this.scheduler = scheduler;
  this.isAsync = isAsync;
  this.isResult = isResult;
  this.isBody = isBody;
  this.isFlowable = isFlowable;
  this.isSingle = isSingle;
  this.isMaybe = isMaybe;
  this.isCompletable = isCompletable;
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:14,代碼來源:RxJava2CallAdapter.java

示例12: MessageGroupSubscriber

import io.reactivex.Scheduler; //導入依賴的package包/類
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;
}
 
開發者ID:tramchamploo,項目名稱:buffer-slayer,代碼行數:10,代碼來源:RxReporter.java

示例13: runningWorkReportsBusy

import io.reactivex.Scheduler; //導入依賴的package包/類
@Test public void runningWorkReportsBusy() {
  Scheduler.Worker worker = scheduler.createWorker();
  worker.schedule(new Runnable() {
    @Override public void run() {
      assertBusy();
    }
  });
  delegate.triggerActions();
}
 
開發者ID:square,項目名稱:RxIdler,代碼行數:10,代碼來源:DelegatingIdlingResourceSchedulerTest.java

示例14: TodayWeatherViewModel

import io.reactivex.Scheduler; //導入依賴的package包/類
@Inject @Replaceable
public TodayWeatherViewModel(NavigationController navigation,
                             @RxObservable(PAGE) Observable<Integer> pageChangeObservable,
                             PermissionService permissionService,
                             LocationService locationService, WeatherService weatherService,
                             TodayWeatherResponseFilter weatherParser,
                             @RxScheduler(MAIN) Scheduler androidScheduler) {
    super(navigation, pageChangeObservable, permissionService, locationService, weatherService, weatherParser, androidScheduler);
}
 
開發者ID:aschattney,項目名稱:dagger-test-example,代碼行數:10,代碼來源:TodayWeatherViewModel.java

示例15: RxToFXListBinding

import io.reactivex.Scheduler; //導入依賴的package包/類
public RxToFXListBinding(Scheduler scheduler, ObservableList<E> rxList, javafx.collections.ObservableList<E> fxList) {
    this.rxList = rxList;
    this.fxList = fxList;
    fxList.clear();
    disposer.register(rxList.observable().observeOn(scheduler).subscribe(fxList::add));
    disposer.register(rxList.onAdded().observeOn(scheduler).subscribe(c -> fxList.add(c.getIndex(), c.getValue())));
    disposer.register(rxList.onRemoved().observeOn(scheduler).subscribe(c -> fxList.remove(c.getIndex())));
    disposer.register(rxList.onUpdatedChanged().observeOn(scheduler).subscribe(c ->
            fxList.set(c.getNewValue().getIndex(), c.getOldValue().getValue())));
    disposer.register(rxList.onMoved().observeOn(scheduler).subscribe(c ->
            fxList.add(c.getNewValue().getIndex(), fxList.remove(c.getOldValue().getIndex()))));
}
 
開發者ID:FHannes,項目名稱:RxJavaCollections,代碼行數:13,代碼來源:RxToFXListBinding.java


注:本文中的io.reactivex.Scheduler類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。