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


Java Worker类代码示例

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


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

示例1: testCachedScheduledReset

import rx.Scheduler.Worker; //导入依赖的package包/类
@Test
public void testCachedScheduledReset() {
    TestScheduler scheduler = new TestScheduler();
    Worker worker = scheduler.createWorker();
    try {
        final AtomicInteger count = new AtomicInteger(0);
        Observable<Integer> source = Observable.defer(new Func0<Observable<Integer>>() {
            @Override
            public Observable<Integer> call() {
                return Observable.just(count.incrementAndGet());
            }
        })
                // cache
                .compose(Transformers.<Integer> cache(5, TimeUnit.MINUTES, worker));
        assertEquals(1, (int) source.toBlocking().single());
        scheduler.advanceTimeBy(1, TimeUnit.MINUTES);
        assertEquals(1, (int) source.toBlocking().single());
        scheduler.advanceTimeBy(1, TimeUnit.MINUTES);
        assertEquals(1, (int) source.toBlocking().single());
        scheduler.advanceTimeBy(3, TimeUnit.MINUTES);
        assertEquals(2, (int) source.toBlocking().single());
        assertEquals(2, (int) source.toBlocking().single());
    } finally {
        worker.unsubscribe();
    }
}
 
开发者ID:davidmoten,项目名称:rxjava-extras,代码行数:27,代码来源:ObsTest.java

示例2: call

import rx.Scheduler.Worker; //导入依赖的package包/类
public Subscription call(final TimeoutSubscriber<T> timeoutSubscriber, final Long seqId, Worker inner) {
    if (this.val$firstTimeoutSelector == null) {
        return Subscriptions.unsubscribed();
    }
    try {
        return ((Observable) this.val$firstTimeoutSelector.call()).unsafeSubscribe(new Subscriber<U>() {
            public void onCompleted() {
                timeoutSubscriber.onTimeout(seqId.longValue());
            }

            public void onError(Throwable e) {
                timeoutSubscriber.onError(e);
            }

            public void onNext(U u) {
                timeoutSubscriber.onTimeout(seqId.longValue());
            }
        });
    } catch (Throwable t) {
        Exceptions.throwOrReport(t, timeoutSubscriber);
        return Subscriptions.unsubscribed();
    }
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:24,代码来源:OperatorTimeoutWithSelector.java

示例3: call

import rx.Scheduler.Worker; //导入依赖的package包/类
public void call(final Subscriber<? super Long> child) {
    final Worker worker = this.scheduler.createWorker();
    child.add(worker);
    worker.schedulePeriodically(new Action0() {
        long counter;

        public void call() {
            try {
                Subscriber subscriber = child;
                long j = this.counter;
                this.counter = 1 + j;
                subscriber.onNext(Long.valueOf(j));
            } catch (Throwable e) {
                worker.unsubscribe();
            } finally {
                Exceptions.throwOrReport(e, child);
            }
        }
    }, this.initialDelay, this.period, this.unit);
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:21,代码来源:OnSubscribeTimerPeriodically.java

示例4: call

import rx.Scheduler.Worker; //导入依赖的package包/类
public Subscriber<? super T> call(Subscriber<? super List<T>> child) {
    Worker inner = this.scheduler.createWorker();
    SerializedSubscriber<List<T>> serialized = new SerializedSubscriber(child);
    if (this.timespan == this.timeshift) {
        ExactSubscriber bsub = new ExactSubscriber(serialized, inner);
        bsub.add(inner);
        child.add(bsub);
        bsub.scheduleExact();
        return bsub;
    }
    Subscriber bsub2 = new InexactSubscriber(serialized, inner);
    bsub2.add(inner);
    child.add(bsub2);
    bsub2.startNewChunk();
    bsub2.scheduleChunk();
    return bsub2;
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:18,代码来源:OperatorBufferWithTime.java

示例5: start

import rx.Scheduler.Worker; //导入依赖的package包/类
public void start() {
    Worker w = Schedulers.computation().createWorker();
    if (this.schedulerWorker.compareAndSet(null, w)) {
        w.schedulePeriodically(new Action0() {
            public void call() {
                int size = ObjectPool.this.pool.size();
                int i;
                if (size < ObjectPool.this.minSize) {
                    int sizeToBeAdded = ObjectPool.this.maxSize - size;
                    for (i = 0; i < sizeToBeAdded; i++) {
                        ObjectPool.this.pool.add(ObjectPool.this.createObject());
                    }
                } else if (size > ObjectPool.this.maxSize) {
                    int sizeToBeRemoved = size - ObjectPool.this.maxSize;
                    for (i = 0; i < sizeToBeRemoved; i++) {
                        ObjectPool.this.pool.poll();
                    }
                }
            }
        }, this.validationInterval, this.validationInterval, TimeUnit.SECONDS);
    } else {
        w.unsubscribe();
    }
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:25,代码来源:ObjectPool.java

示例6: doWorkOnNewTrampoline

import rx.Scheduler.Worker; //导入依赖的package包/类
private static Worker doWorkOnNewTrampoline(final String key, final ArrayList<String> workDone) {
    Worker worker = Schedulers.trampoline().createWorker();
    worker.schedule(new Action0() {

        @Override
        public void call() {
            String msg = key + ".1";
            workDone.add(msg);
            System.out.println(msg);
            Worker worker3 = Schedulers.trampoline().createWorker();
            worker3.schedule(createPrintAction(key + ".B.1", workDone));
            worker3.schedule(createPrintAction(key + ".B.2", workDone));
        }

    });
    return worker;
}
 
开发者ID:akarnokd,项目名称:RxJavaFlow,代码行数:18,代码来源:TrampolineSchedulerTest.java

示例7: startScheduledResetAgain

import rx.Scheduler.Worker; //导入依赖的package包/类
private static <T> void startScheduledResetAgain(final long duration, final TimeUnit unit,
        final Scheduler scheduler, final AtomicReference<CachedObservable<T>> cacheRef,
        final AtomicReference<Optional<Worker>> workerRef) {

    Action0 action = new Action0() {
        @Override
        public void call() {
            cacheRef.get().reset();
        }
    };
    // CAS loop to cancel the current worker and create a new one
    while (true) {
        Optional<Worker> wOld = workerRef.get();
        if (wOld == null) {
            // we are finished
            return;
        }
        Optional<Worker> w = Optional.of(scheduler.createWorker());
        if (workerRef.compareAndSet(wOld, w)) {
            if (wOld.isPresent())
                wOld.get().unsubscribe();
            w.get().schedule(action, duration, unit);
            break;
        }
    }
}
 
开发者ID:davidmoten,项目名称:rxjava-extras,代码行数:27,代码来源:Obs.java

示例8: blockUntilWorkFinished

import rx.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 Action0() {

            @Override
            public void call() {
                worker.unsubscribe();
                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,项目名称:rxjava-extras,代码行数:24,代码来源:Schedulers.java

示例9: call

import rx.Scheduler.Worker; //导入依赖的package包/类
@Override
public Subscriber<? super T> call(Subscriber<? super T> child) {
    Subscriber<T> parent;
    if (firstTime.compareAndSet(true, false)) {
        // don't delay subscription for the first time
        parent = Subscribers.from(child);
    } else {
        final PublishSubject<T> subject = PublishSubject.create();
        Worker worker = scheduler.createWorker();
        worker.schedule(() -> {
            subject.unsafeSubscribe(child);
        }, duration, units);
        child.add(worker);
        parent = Subscribers.from(subject);
    }
    child.add(parent);
    return parent;
}
 
开发者ID:amsa-code,项目名称:risky,代码行数:19,代码来源:OperatorSubscriptionInterval.java

示例10: from

import rx.Scheduler.Worker; //导入依赖的package包/类
/**
 * Converts from {@link ListenableFuture} to {@link rx.Observable}.
 * 
 * @param future  the {@link ListenableFuture} to register a listener on.
 * @param scheduler  the {@link Scheduler} where the callback will be executed.  The will be where the {@link Observer#onNext(Object)} call from.
 * @return an {@link Observable} that emits the one value when the future completes.
 */
public static <T> Observable<T> from(final ListenableFuture<T> future, final Scheduler scheduler) {
    final Worker worker = scheduler.createWorker();
    return from(future, new Executor() {
        @Override
        public void execute(final Runnable command) {
            worker.schedule(new Action0() {
                @Override
                public void call() {
                    try {
                        command.run();
                    } finally {
                        worker.unsubscribe();
                    }
                }
            });
        }
    });
}
 
开发者ID:ReactiveX,项目名称:RxJavaGuava,代码行数:26,代码来源:ListenableFutureObservable.java

示例11: call

import rx.Scheduler.Worker; //导入依赖的package包/类
@Override
public void call(final Subscriber<? super Long> child) {
    Worker worker = scheduler.createWorker();
    child.add(worker);
    worker.schedule(new Action0() {
        @Override
        public void call() {
            try {
                child.onNext(0L);
            } catch (Throwable t) {
                child.onError(t);
                return;
            }
            child.onCompleted();
        }
    }, time, unit);
}
 
开发者ID:OpenNTF,项目名称:org.openntf.domino,代码行数:18,代码来源:OnSubscribeTimerOnce.java

示例12: call

import rx.Scheduler.Worker; //导入依赖的package包/类
@Override
public void call(final Subscriber<? super Long> child) {
    final Worker worker = scheduler.createWorker();
    child.add(worker);
    worker.schedulePeriodically(new Action0() {
        long counter;
        @Override
        public void call() {
            try {
                child.onNext(counter++);
            } catch (Throwable e) {
                try {
                    child.onError(e);
                } finally {
                    worker.unsubscribe();
                }
            }
        }
        
    }, initialDelay, period, unit);
}
 
开发者ID:OpenNTF,项目名称:org.openntf.domino,代码行数:22,代码来源:OnSubscribeTimerPeriodically.java

示例13: call

import rx.Scheduler.Worker; //导入依赖的package包/类
public Subscriber<? super T> call(final Subscriber<? super T> child) {
    Worker worker = this.scheduler.createWorker();
    child.add(worker);
    final AtomicBoolean gate = new AtomicBoolean();
    worker.schedule(new Action0() {
        public void call() {
            gate.set(true);
        }
    }, this.time, this.unit);
    return new Subscriber<T>(child) {
        public void onNext(T t) {
            if (gate.get()) {
                child.onNext(t);
            }
        }

        public void onError(Throwable e) {
            try {
                child.onError(e);
            } finally {
                unsubscribe();
            }
        }

        public void onCompleted() {
            try {
                child.onCompleted();
            } finally {
                unsubscribe();
            }
        }
    };
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:34,代码来源:OperatorSkipTimed.java

示例14: call

import rx.Scheduler.Worker; //导入依赖的package包/类
public void call(final Subscriber<? super T> s) {
    Worker worker = this.scheduler.createWorker();
    s.add(worker);
    worker.schedule(new Action0() {
        public void call() {
            if (!s.isUnsubscribed()) {
                OnSubscribeDelaySubscription.this.source.unsafeSubscribe(Subscribers.wrap(s));
            }
        }
    }, this.time, this.unit);
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:12,代码来源:OnSubscribeDelaySubscription.java

示例15: ExactSubscriber

import rx.Scheduler.Worker; //导入依赖的package包/类
public ExactSubscriber(Subscriber<? super Observable<T>> child, Worker worker) {
    this.child = new SerializedSubscriber(child);
    this.worker = worker;
    child.add(Subscriptions.create(new Action0(OperatorWindowWithTime.this) {
        public void call() {
            if (ExactSubscriber.this.state.consumer == null) {
                ExactSubscriber.this.unsubscribe();
            }
        }
    }));
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:12,代码来源:OperatorWindowWithTime.java


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