@Override public Observable<List<ChangeNotification<T>>> call(Observable<ChangeNotification<T>> notifications) { final AtomicBoolean bufferStart = new AtomicBoolean(); final AtomicReference<List<ChangeNotification<T>>> bufferRef = new AtomicReference<>(); return notifications.map(new Func1<ChangeNotification<T>, List<ChangeNotification<T>>>() { @Override public List<ChangeNotification<T>> call(ChangeNotification<T> notification) { List<ChangeNotification<T>> buffer = bufferRef.get(); if (notification instanceof StreamStateNotification) { BufferState bufferState = ((StreamStateNotification<T>) notification).getBufferState(); if (bufferState == BufferState.BufferStart) { bufferStart.set(true); } else { // BufferEnd bufferStart.set(false); bufferRef.set(null); return buffer; } } else if (bufferStart.get()) { if (buffer == null) { bufferRef.set(buffer = new ArrayList<ChangeNotification<T>>()); } buffer.add(notification); } else { return Collections.singletonList(notification); } return null; } }).filter(RxFunctions.filterNullValuesFunc()); } };
@Override public Observable<ChangeNotification<InstanceInfo>> forInterest(final Interest<InstanceInfo> interest) { return relay.mergeWith( remoteBatchingRegistry.forInterest(interest) .map(new Func1<StreamStateNotification.BufferState, ChangeNotification<InstanceInfo>>() { @Override public ChangeNotification<InstanceInfo> call(StreamStateNotification.BufferState state) { if (state == StreamStateNotification.BufferState.BufferEnd) { return new StreamStateNotification<>(state, interest); } return null; } }) .filter(RxFunctions.filterNullValuesFunc()) ); }
}).filter(RxFunctions.filterNullValuesFunc());
.filter(RxFunctions.filterNullValuesFunc()) .materialize()
.filter(RxFunctions.filterNullValuesFunc()) .materialize()