本文整理汇总了Java中rx.internal.util.RxRingBuffer类的典型用法代码示例。如果您正苦于以下问题:Java RxRingBuffer类的具体用法?Java RxRingBuffer怎么用?Java RxRingBuffer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
RxRingBuffer类属于rx.internal.util包,在下文中一共展示了RxRingBuffer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: start
import rx.internal.util.RxRingBuffer; //导入依赖的package包/类
static void start() {
Schedulers s = INSTANCE;
synchronized (s) {
if (s.computationScheduler instanceof SchedulerLifecycle) {
((SchedulerLifecycle) s.computationScheduler).start();
}
if (s.ioScheduler instanceof SchedulerLifecycle) {
((SchedulerLifecycle) s.ioScheduler).start();
}
if (s.newThreadScheduler instanceof SchedulerLifecycle) {
((SchedulerLifecycle) s.newThreadScheduler).start();
}
GenericScheduledExecutorService.INSTANCE.start();
RxRingBuffer.SPSC_POOL.start();
RxRingBuffer.SPMC_POOL.start();
}
}
示例2: shutdown
import rx.internal.util.RxRingBuffer; //导入依赖的package包/类
public static void shutdown() {
Schedulers s = INSTANCE;
synchronized (s) {
if (s.computationScheduler instanceof SchedulerLifecycle) {
((SchedulerLifecycle) s.computationScheduler).shutdown();
}
if (s.ioScheduler instanceof SchedulerLifecycle) {
((SchedulerLifecycle) s.ioScheduler).shutdown();
}
if (s.newThreadScheduler instanceof SchedulerLifecycle) {
((SchedulerLifecycle) s.newThreadScheduler).shutdown();
}
GenericScheduledExecutorService.INSTANCE.shutdown();
RxRingBuffer.SPSC_POOL.shutdown();
RxRingBuffer.SPMC_POOL.shutdown();
}
}
示例3: queueScalar
import rx.internal.util.RxRingBuffer; //导入依赖的package包/类
protected void queueScalar(InnerSubscriber<T> subscriber, T value) {
RxRingBuffer q = subscriber.queue;
if (q == null) {
q = RxRingBuffer.getSpscInstance();
subscriber.add(q);
subscriber.queue = q;
}
try {
q.onNext(this.nl.next(value));
emit();
} catch (MissingBackpressureException ex) {
subscriber.unsubscribe();
subscriber.onError(ex);
} catch (IllegalStateException ex2) {
if (!subscriber.isUnsubscribed()) {
subscriber.unsubscribe();
subscriber.onError(ex2);
}
}
}
示例4: request
import rx.internal.util.RxRingBuffer; //导入依赖的package包/类
public void request(long n) {
BackpressureUtils.getAndAddRequest(this.requested, n);
if (!this.started.get() && this.started.compareAndSet(false, true)) {
int sizePerSubscriber = RxRingBuffer.SIZE / this.sources.size();
int leftOver = RxRingBuffer.SIZE % this.sources.size();
for (int i = 0; i < this.sources.size(); i++) {
Observable<? extends T> o = (Observable) this.sources.get(i);
int toRequest = sizePerSubscriber;
if (i == this.sources.size() - 1) {
toRequest += leftOver;
}
MultiSourceRequestableSubscriber<T, R> s = new MultiSourceRequestableSubscriber(i, toRequest, this.child, this);
this.subscribers[i] = s;
o.unsafeSubscribe(s);
}
}
tick();
}
示例5: testBeyondBackpressureBuffer
import rx.internal.util.RxRingBuffer; //导入依赖的package包/类
@Test
public void testBeyondBackpressureBuffer() {
int n = 100 * RxRingBuffer.SIZE;
// Similar to zip
// List<Observable<?>> os = new ArrayList<Observable<?>>();
// os.add(Observable.range(0, n));
// Iterator<Integer> iter = Observable.just(os.toArray(new Observable<?>[os.size()]))
// .lift(new OperatorZip<Integer>(args->(int)args[0]))
Iterator<Integer> iter = Observable.just(Observable.range(0, n))
.lift(new OperatorMergeSorted<Integer>(naturalComparator))
.toBlocking().getIterator();
for (int i = 0; i < n; i++) {
Assert.assertTrue(iter.hasNext());
int value = iter.next();
Assert.assertEquals(i, value);
}
Assert.assertFalse(iter.hasNext());
}
示例6: testBackpressure
import rx.internal.util.RxRingBuffer; //导入依赖的package包/类
@Test
public void testBackpressure() {
final int n = 100;
final AtomicInteger max1 = new AtomicInteger();
final AtomicInteger max2 = new AtomicInteger();
Observable<Integer> o1 = Observable.range(0, RxRingBuffer.SIZE * n).delay(1, TimeUnit.SECONDS)
.doOnNext(value->max1.set(value > max1.get()? value : max1.get()));
Observable<Integer> o2 = Observable.range(RxRingBuffer.SIZE * n, RxRingBuffer.SIZE * n)
.doOnNext(value->max2.set(value - RxRingBuffer.SIZE * n > max2.get()? value - RxRingBuffer.SIZE * n: max2.get()));
Iterator<Integer> iter = Observable.just(o1, o2)
.lift(new OperatorMergeSorted<Integer>(naturalComparator))
.toBlocking().getIterator();
for (int i = 0; i < RxRingBuffer.SIZE/2; i++) {
Assert.assertTrue(iter.hasNext());
Assert.assertEquals(i, (int)iter.next());
}
Assert.assertTrue(iter.hasNext());
//make sure source observables are not fetched beyond double buffer size
//as toBlocking().getIterator() now supports backpressure
Assert.assertTrue(max1.get() <= 2 * RxRingBuffer.SIZE);
Assert.assertTrue(max2.get() <= 2 * RxRingBuffer.SIZE);
}
示例7: PublishSubscriber
import rx.internal.util.RxRingBuffer; //导入依赖的package包/类
public PublishSubscriber(AtomicReference<PublishSubscriber<T>> current) {
this.queue = UnsafeAccess.isUnsafeAvailable() ? new SpscArrayQueue(RxRingBuffer.SIZE) : new SynchronizedQueue(RxRingBuffer.SIZE);
this.nl = NotificationLite.instance();
this.producers = new AtomicReference(EMPTY);
this.current = current;
this.shouldConnect = new AtomicBoolean();
}
示例8: requestMore
import rx.internal.util.RxRingBuffer; //导入依赖的package包/类
public void requestMore(long n) {
int r = this.outstanding - ((int) n);
if (r > limit) {
this.outstanding = r;
return;
}
this.outstanding = RxRingBuffer.SIZE;
int k = RxRingBuffer.SIZE - r;
if (k > 0) {
request((long) k);
}
}
示例9: removeInner
import rx.internal.util.RxRingBuffer; //导入依赖的package包/类
void removeInner(InnerSubscriber<T> inner) {
RxRingBuffer q = inner.queue;
if (q != null) {
q.release();
}
this.subscriptions.remove(inner);
synchronized (this.innerGuard) {
InnerSubscriber<?>[] a = this.innerSubscribers;
int n = a.length;
int j = -1;
for (int i = 0; i < n; i++) {
if (inner.equals(a[i])) {
j = i;
break;
}
}
if (j < 0) {
} else if (n == 1) {
this.innerSubscribers = EMPTY;
} else {
InnerSubscriber<?>[] b = new InnerSubscriber[(n - 1)];
System.arraycopy(a, 0, b, 0, j);
System.arraycopy(a, j + 1, b, j, (n - j) - 1);
this.innerSubscribers = b;
}
}
}
示例10: OnSubscribeCombineLatest
import rx.internal.util.RxRingBuffer; //导入依赖的package包/类
public OnSubscribeCombineLatest(List<? extends Observable<? extends T>> sources, FuncN<? extends R> combinator) {
this.sources = sources;
this.combinator = combinator;
if (sources.size() > RxRingBuffer.SIZE) {
throw new IllegalArgumentException("More than RxRingBuffer.SIZE sources to combineLatest is not supported.");
}
}
示例11: ObserveOnSubscriber
import rx.internal.util.RxRingBuffer; //导入依赖的package包/类
public ObserveOnSubscriber(Scheduler scheduler, Subscriber<? super T> child) {
this.child = child;
this.recursiveScheduler = scheduler.createWorker();
if (UnsafeAccess.isUnsafeAvailable()) {
this.queue = new SpscArrayQueue(RxRingBuffer.SIZE);
} else {
this.queue = new SynchronizedQueue(RxRingBuffer.SIZE);
}
this.scheduledUnsubscribe = new ScheduledUnsubscribe(this.recursiveScheduler);
}
示例12: pollTopItem
import rx.internal.util.RxRingBuffer; //导入依赖的package包/类
/**
* Polls a top item from the priority queue. Adds the top source back to
* pending set. Not synchronized as accessed inside COUNTER_UPDATER block
*
* @param pending
* set of source observers pending a value for the merge
* @return true if we need a shutdown
*/
private boolean pollTopItem(Set<InnerSubscriber> pending) {
// get a next item in order from the priority queue
ValueSourcePair tuple = queue.poll();
T value = tuple.value;
InnerSubscriber observer = tuple.source;
// mark the wining observer as pending again
pending.add(observer);
try {
// emit the next item in order
child.onNext(value);
// we emitted so decrement the requested counter
requested.decrementAndGet();
observer.emitted++;
} catch (Throwable e) {
Exceptions.throwOrReport(e, child, value);
return true;
}
// now remove
RxRingBuffer buffer = observer.items;
buffer.poll();
// eagerly check if the next item on this queue is an onComplete
if (buffer.isCompleted(buffer.peek())) {
// we need to unsubscribe and remove from pending
pending.remove(observer);
childSubscription.remove(observer);
if (!childSubscription.hasSubscriptions()) {
// it is last upstream observer so onComplete so shut down
child.onCompleted();
return true;
}
return false; // dont request for this observer
}
if (observer.emitted > THRESHOLD) {
observer.requestMore(observer.emitted);
observer.emitted = 0;
}
return false;
}
示例13: combineLatestDelayError
import rx.internal.util.RxRingBuffer; //导入依赖的package包/类
public static <T, R> Observable<R> combineLatestDelayError(Iterable<? extends Observable<? extends T>> sources, FuncN<? extends R> combineFunction) {
return create(new OnSubscribeCombineLatest(null, sources, combineFunction, RxRingBuffer.SIZE, true));
}
示例14: concatMapIterable
import rx.internal.util.RxRingBuffer; //导入依赖的package包/类
public final <R> Observable<R> concatMapIterable(Func1<? super T, ? extends Iterable<? extends R>> collectionSelector) {
return OnSubscribeFlattenIterable.createFrom(this, collectionSelector, RxRingBuffer.SIZE);
}
示例15: concatMapEager
import rx.internal.util.RxRingBuffer; //导入依赖的package包/类
@Experimental
public final <R> Observable<R> concatMapEager(Func1<? super T, ? extends Observable<? extends R>> mapper) {
return concatMapEager(mapper, RxRingBuffer.SIZE);
}