• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java Worker类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中io.reactivex.Scheduler.Worker的典型用法代码示例。如果您正苦于以下问题:Java Worker类的具体用法?Java Worker怎么用?Java Worker使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



Worker类属于io.reactivex.Scheduler包,在下文中一共展示了Worker类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: workerScheduleOnceUsesHook

import io.reactivex.Scheduler.Worker; //导入依赖的package包/类
@Test
public void workerScheduleOnceUsesHook() {
    final CountingRunnable newCounter = new CountingRunnable();
    final AtomicReference<Runnable> runnableRef = new AtomicReference<>();
    RxJavaPlugins.setScheduleHandler(new Function<Runnable, Runnable>() {
        @Override public Runnable apply(Runnable runnable) {
            runnableRef.set(runnable);
            return newCounter;
        }
    });

    Worker worker = scheduler.createWorker();

    CountingRunnable counter = new CountingRunnable();
    worker.schedule(counter);

    // Verify our runnable was passed to the schedulers hook.
    assertSame(counter, runnableRef.get());

    runUiThreadTasks();
    // Verify the scheduled runnable was the one returned from the hook.
    assertEquals(1, newCounter.get());
    assertEquals(0, counter.get());
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:25,代码来源:HandlerSchedulerTest.java


示例2: workerScheduleOnceWithDelayUsesHook

import io.reactivex.Scheduler.Worker; //导入依赖的package包/类
@Test
public void workerScheduleOnceWithDelayUsesHook() {
    final CountingRunnable newCounter = new CountingRunnable();
    final AtomicReference<Runnable> runnableRef = new AtomicReference<>();
    RxJavaPlugins.setScheduleHandler(new Function<Runnable, Runnable>() {
        @Override public Runnable apply(Runnable runnable) {
            runnableRef.set(runnable);
            return newCounter;
        }
    });

    Worker worker = scheduler.createWorker();

    CountingRunnable counter = new CountingRunnable();
    worker.schedule(counter, 1, MINUTES);

    // Verify our runnable was passed to the schedulers hook.
    assertSame(counter, runnableRef.get());

    idleMainLooper(1, MINUTES);
    runUiThreadTasks();
    // Verify the scheduled runnable was the one returned from the hook.
    assertEquals(1, newCounter.get());
    assertEquals(0, counter.get());
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:26,代码来源:HandlerSchedulerTest.java


示例3: workerSchedulePeriodicallyReschedulesItself

import io.reactivex.Scheduler.Worker; //导入依赖的package包/类
@Test @Ignore("Implementation delegated to default RxJava implementation")
public void workerSchedulePeriodicallyReschedulesItself() {
    Worker worker = scheduler.createWorker();

    CountingRunnable counter = new CountingRunnable();
    worker.schedulePeriodically(counter, 1, 1, MINUTES);

    runUiThreadTasks();
    assertEquals(0, counter.get());

    idleMainLooper(1, MINUTES);
    runUiThreadTasks();
    assertEquals(1, counter.get());

    idleMainLooper(1, MINUTES);
    runUiThreadTasks();
    assertEquals(2, counter.get());

    idleMainLooper(1, MINUTES);
    runUiThreadTasks();
    assertEquals(3, counter.get());
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:23,代码来源:HandlerSchedulerTest.java


示例4: workerSchedulePeriodicallyDisposedDoesNotRun

import io.reactivex.Scheduler.Worker; //导入依赖的package包/类
@Test @Ignore("Implementation delegated to default RxJava implementation")
public void workerSchedulePeriodicallyDisposedDoesNotRun() {
    Worker worker = scheduler.createWorker();

    CountingRunnable counter = new CountingRunnable();
    Disposable disposable = worker.schedulePeriodically(counter, 1, 1, MINUTES);

    runUiThreadTasks();
    assertEquals(0, counter.get());

    idleMainLooper(1, MINUTES);
    runUiThreadTasks();
    assertEquals(1, counter.get());

    idleMainLooper(1, MINUTES);
    runUiThreadTasks();
    assertEquals(2, counter.get());

    disposable.dispose();

    idleMainLooper(1, MINUTES);
    runUiThreadTasks();
    assertEquals(2, counter.get());
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:25,代码来源:HandlerSchedulerTest.java


示例5: workerUnsubscriptionDuringSchedulingCancelsScheduledAction

import io.reactivex.Scheduler.Worker; //导入依赖的package包/类
@Test
public void workerUnsubscriptionDuringSchedulingCancelsScheduledAction() {
    final AtomicReference<Worker> workerRef = new AtomicReference<>();
    RxJavaPlugins.setScheduleHandler(new Function<Runnable, Runnable>() {
        @Override public Runnable apply(Runnable runnable) {
            // Purposefully unsubscribe in an asinine point after the normal unsubscribed check.
            workerRef.get().dispose();
            return runnable;
        }
    });

    Worker worker = scheduler.createWorker();
    workerRef.set(worker);

    CountingRunnable counter = new CountingRunnable();
    worker.schedule(counter);

    runUiThreadTasks();
    assertEquals(0, counter.get());
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:21,代码来源:HandlerSchedulerTest.java


示例6: workerUnsubscriptionDoesNotAffectOtherWorkers

import io.reactivex.Scheduler.Worker; //导入依赖的package包/类
@Test
public void workerUnsubscriptionDoesNotAffectOtherWorkers() {
    Worker workerA = scheduler.createWorker();
    CountingRunnable counterA = new CountingRunnable();
    workerA.schedule(counterA, 1, MINUTES);

    Worker workerB = scheduler.createWorker();
    CountingRunnable counterB = new CountingRunnable();
    workerB.schedule(counterB, 1, MINUTES);

    workerA.dispose();

    runUiThreadTasksIncludingDelayedTasks();
    assertEquals(0, counterA.get());
    assertEquals(1, counterB.get());
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:17,代码来源:HandlerSchedulerTest.java


示例7: workerPeriodic

import io.reactivex.Scheduler.Worker; //导入依赖的package包/类
@Test
public void workerPeriodic() throws Exception {
    Task t = new Task(3);

    Worker w = SwingSchedulers.edt().createWorker();
    try {
        Disposable d = w.schedulePeriodically(t, 100, 100, TimeUnit.MILLISECONDS);

        Assert.assertTrue(t.await(5, TimeUnit.SECONDS));

        d.dispose();

        Thread.sleep(500);

        Assert.assertEquals(3, t.calls);
    } finally {
        w.dispose();
    }
}
 
开发者ID:akarnokd,项目名称:RxJava2Swing,代码行数:20,代码来源:SwingSchedulersTest.java


示例8: workerDispose

import io.reactivex.Scheduler.Worker; //导入依赖的package包/类
@Test
public void workerDispose() throws Exception {
    Task t = new Task(1);

    Worker w = SwingSchedulers.edt().createWorker();
    try {
        Disposable d = w.schedule(t, 500, TimeUnit.MILLISECONDS);

        Thread.sleep(100);

        d.dispose();

        Thread.sleep(500);

        Assert.assertEquals(0, t.calls);
    } finally {
        w.dispose();
    }
}
 
开发者ID:akarnokd,项目名称:RxJava2Swing,代码行数:20,代码来源:SwingSchedulersTest.java


示例9: futureDisposeRace

import io.reactivex.Scheduler.Worker; //导入依赖的package包/类
@Test(timeout = 5000)
public void futureDisposeRace() throws Exception {
    SharedScheduler scheduler = new SharedScheduler(Schedulers.computation());
    try {
        Worker w = scheduler.createWorker();
        for (int i = 0; i < 1000; i++) {
           w.schedule(this);
        }

        while (calls != 1000) {
            Thread.sleep(100);
        }
    } finally {
        scheduler.shutdown();
    }
}
 
开发者ID:akarnokd,项目名称:RxJava2Extensions,代码行数:17,代码来源:SharedSchedulerTest.java


示例10: taskThrows

import io.reactivex.Scheduler.Worker; //导入依赖的package包/类
protected void taskThrows(Scheduler s) throws InterruptedException {
    try {
        List<Throwable> errors = TestHelper.trackPluginErrors();

        Worker w = s.createWorker();

        w.schedule(new Runnable() {
            @Override
            public void run() {
                calls.getAndIncrement();
                throw new IllegalStateException();
            }
        });

        while (errors.isEmpty()) {
            Thread.sleep(20);
        }

        TestHelper.assertError(errors, 0, IllegalStateException.class);
    } finally {
        s.shutdown();
    }
}
 
开发者ID:akarnokd,项目名称:RxJava2Extensions,代码行数:24,代码来源:ParallelSchedulerTest.java


示例11: setFutureRace

import io.reactivex.Scheduler.Worker; //导入依赖的package包/类
@Test
public void setFutureRace() {
    final Scheduler s = new ParallelScheduler(2, true);
    try {
        for (int i = 0; i < 1000; i++) {
            final Worker w = s.createWorker();

            Runnable r1 = new Runnable() {
                @Override
                public void run() {
                    w.schedule(ParallelSchedulerTest.this);
                }
            };

            Runnable r2 = new Runnable() {
                @Override
                public void run() {
                    w.dispose();
                }
            };
            TestHelper.race(r1, r2, Schedulers.single());
        }
    } finally {
        s.shutdown();
    }
}
 
开发者ID:akarnokd,项目名称:RxJava2Extensions,代码行数:27,代码来源:ParallelSchedulerTest.java


示例12: workerCrash

import io.reactivex.Scheduler.Worker; //导入依赖的package包/类
@Test(timeout = 10000)
public void workerCrash() {
    List<Throwable> errors = TestHelper.trackPluginErrors();
    try {
        final BlockingScheduler scheduler = new BlockingScheduler();
        scheduler.execute(new Action() {
            @Override
            public void run() throws Exception {
                final Worker worker = scheduler.createWorker();
                worker.schedule(new Runnable() {
                    @Override
                    public void run() {
                        worker.dispose();
                        scheduler.shutdown();
                        throw new IllegalArgumentException();
                    }
                });
            }
        });

        TestHelper.assertError(errors, 0, IllegalArgumentException.class);
    } finally {
        RxJavaPlugins.reset();
    }
}
 
开发者ID:akarnokd,项目名称:RxJava2Extensions,代码行数:26,代码来源:BlockingSchedulerTest.java


示例13: blockUntilWorkFinished

import io.reactivex.Scheduler.Worker; //导入依赖的package包/类
public static void blockUntilWorkFinished(Scheduler scheduler, int numThreads, long timeout, TimeUnit unit) {
    final CountDownLatch latch = new CountDownLatch(numThreads);
    for (int i = 1; i <= numThreads; i++) {
        final Worker worker = scheduler.createWorker();
        worker.schedule(new Runnable() {
            @Override
            public void run() {
                worker.dispose();
                latch.countDown();
            }
        });
    }
    try {
        boolean finished = latch.await(timeout, unit);
        if (!finished) {
            throw new RuntimeException("timeout occured waiting for work to finish");
        }
    } catch (InterruptedException e) {
        throw new RuntimeException(e);
    }
}
 
开发者ID:davidmoten,项目名称:rxjava2-extras,代码行数:22,代码来源:SchedulerHelper.java


示例14: workerScheduleOncePostsImmediately

import io.reactivex.Scheduler.Worker; //导入依赖的package包/类
@Test
public void workerScheduleOncePostsImmediately() {
    Worker worker = scheduler.createWorker();

    CountingRunnable counter = new CountingRunnable();
    worker.schedule(counter);

    runUiThreadTasks();
    assertEquals(1, counter.get());
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:11,代码来源:HandlerSchedulerTest.java


示例15: workerScheduleOnceWithNegativeDelayPostsImmediately

import io.reactivex.Scheduler.Worker; //导入依赖的package包/类
@Test
public void workerScheduleOnceWithNegativeDelayPostsImmediately() {
    Worker worker = scheduler.createWorker();

    CountingRunnable counter = new CountingRunnable();
    worker.schedule(counter, -1, TimeUnit.MINUTES);

    runUiThreadTasks();
    assertEquals(1, counter.get());
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:11,代码来源:HandlerSchedulerTest.java


示例16: workerScheduleOnceDisposedDoesNotRun

import io.reactivex.Scheduler.Worker; //导入依赖的package包/类
@Test
public void workerScheduleOnceDisposedDoesNotRun() {
    Worker worker = scheduler.createWorker();

    CountingRunnable counter = new CountingRunnable();
    Disposable disposable = worker.schedule(counter);
    disposable.dispose();

    runUiThreadTasks();
    assertEquals(0, counter.get());
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:12,代码来源:HandlerSchedulerTest.java


示例17: workerScheduleOnceWithDelayPostsWithDelay

import io.reactivex.Scheduler.Worker; //导入依赖的package包/类
@Test
public void workerScheduleOnceWithDelayPostsWithDelay() {
    Worker worker = scheduler.createWorker();

    CountingRunnable counter = new CountingRunnable();
    worker.schedule(counter, 1, MINUTES);

    runUiThreadTasks();
    assertEquals(0, counter.get());

    idleMainLooper(1, MINUTES);
    runUiThreadTasks();
    assertEquals(1, counter.get());
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:15,代码来源:HandlerSchedulerTest.java


示例18: workerScheduleOnceWithDelayDisposedDoesNotRun

import io.reactivex.Scheduler.Worker; //导入依赖的package包/类
@Test
public void workerScheduleOnceWithDelayDisposedDoesNotRun() {
    Worker worker = scheduler.createWorker();

    CountingRunnable counter = new CountingRunnable();
    Disposable disposable = worker.schedule(counter, 1, MINUTES);

    idleMainLooper(30, SECONDS);
    disposable.dispose();

    idleMainLooper(30, SECONDS);
    runUiThreadTasks();
    assertEquals(0, counter.get());
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:15,代码来源:HandlerSchedulerTest.java


示例19: workerSchedulePeriodicallyUsesHookOnce

import io.reactivex.Scheduler.Worker; //导入依赖的package包/类
@Test @Ignore("Implementation delegated to default RxJava implementation")
public void workerSchedulePeriodicallyUsesHookOnce() {
    Worker worker = scheduler.createWorker();

    final CountingRunnable newCounter = new CountingRunnable();
    final AtomicReference<Runnable> runnableRef = new AtomicReference<>();
    RxJavaPlugins.setScheduleHandler(new Function<Runnable, Runnable>() {
        @Override public Runnable apply(Runnable runnable) {
            runnableRef.set(runnable);
            return newCounter;
        }
    });

    CountingRunnable counter = new CountingRunnable();
    worker.schedulePeriodically(counter, 1, 1, MINUTES);

    // Verify our action was passed to the schedulers hook.
    assertSame(counter, runnableRef.get());
    runnableRef.set(null);

    idleMainLooper(1, MINUTES);
    runUiThreadTasks();
    // Verify the scheduled action was the one returned from the hook.
    assertEquals(1, newCounter.get());
    assertEquals(0, counter.get());

    // Ensure the hook was not called again when the runnable re-scheduled itself.
    assertNull(runnableRef.get());
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:30,代码来源:HandlerSchedulerTest.java


示例20: workerSchedulePeriodicallyDisposedDuringRunDoesNotReschedule

import io.reactivex.Scheduler.Worker; //导入依赖的package包/类
@Test @Ignore("Implementation delegated to default RxJava implementation")
public void workerSchedulePeriodicallyDisposedDuringRunDoesNotReschedule() {
    Worker worker = scheduler.createWorker();

    final AtomicReference<Disposable> disposableRef = new AtomicReference<>();
    CountingRunnable counter = new CountingRunnable() {
        @Override public void run() {
            super.run();
            if (get() == 2) {
                disposableRef.get().dispose();
            }
        }
    };
    Disposable disposable = worker.schedulePeriodically(counter, 1, 1, MINUTES);
    disposableRef.set(disposable);

    runUiThreadTasks();
    assertEquals(0, counter.get());

    idleMainLooper(1, MINUTES);
    runUiThreadTasks();
    assertEquals(1, counter.get());

    idleMainLooper(1, MINUTES);
    runUiThreadTasks();
    assertEquals(2, counter.get());

    // Dispose will have happened here during the last run() execution.

    idleMainLooper(1, MINUTES);
    runUiThreadTasks();
    assertEquals(2, counter.get());
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:34,代码来源:HandlerSchedulerTest.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java SimpleWikiConfiguration类代码示例发布时间:2022-05-23
下一篇:
Java JcePBESecretKeyEncryptorBuilder类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap