@Override public void call(Subscriber<? super BufferState> subscriber) { updatesSubject.pause(); try { BufferState current = shouldBatch(interest); subscriber.onNext(current); updatesSubject.map(new Func1<Boolean, BufferState>() { @Override public BufferState call(Boolean tick) { return shouldBatch(interest); } }).subscribe(subscriber); } finally { updatesSubject.resume(); } } }).distinctUntilChanged();
@Override public Iterator<ChangeNotification<T>> iterator() { if (isDone()) { return EMPTY_ITERATOR; } try { notificationSubject.pause(); return _newIterator(); } finally { notificationSubject.resume(); } }
@Override public void call(Subscriber<? super ChangeNotification<T>> subscriber) { // We need to buffer all the changes while the init state is replayed. // Because new instance holder updates will be added while we replay them, they will be // partially visible by the subscriber. When we replay buffered real time updates, // they may overlap with what was already sent from the init holder. // TODO can we make this buffering cheaper? final PauseableSubject<ChangeNotification<T>> realTimeSubject = PauseableSubject.create(); realTimeSubject.pause(); realTimeSource.subscribe(realTimeSubject); realTimeSubject.mergeWith(Observable.from(initStateHolder).doOnCompleted(new Action0() { @Override public void call() { realTimeSubject.resume(); } })).subscribe(subscriber); } });
/** * Return an observable of all matching InstanceInfo for the current registry snapshot, * as {@link ChangeNotification}s * @param interest * @return an observable of all matching InstanceInfo for the current registry snapshot, * as {@link ChangeNotification}s */ @Override public Observable<ChangeNotification<InstanceInfo>> forInterest(Interest<InstanceInfo> interest) { try { // TODO: this method can be run concurrently from different channels, unless we run everything on single server event loop. // It is possible that the same instanceinfo will be both in snapshot and paused notification queue. pauseableSubject.pause(); // Pause notifications till we get a snapshot of current registry (registry.values()) if (interest instanceof MultipleInterests) { return indexRegistry.forCompositeInterest((MultipleInterests) interest, this); } else { return indexRegistry.forInterest(interest, pauseableSubject, new InstanceInfoInitStateHolder(getSnapshotForInterest(interest), interest)); } } finally { pauseableSubject.resume(); } }