@SuppressWarnings("unchecked") ReplayDisposable<T>[] terminate(Object terminalValue) { if (buffer.compareAndSet(null, terminalValue)) { return observers.getAndSet(TERMINATED); } return TERMINATED; }
/** * Makes sure the item cached by the head node in a bounded * ReplaySubject is released (as it is never part of a replay). * <p> * By default, live bounded buffers will remember one item before * the currently receivable one to ensure subscribers can always * receive a continuous sequence of items. A terminated ReplaySubject * automatically releases this inaccessible item. * <p> * The method must be called sequentially, similar to the standard * {@code onXXX} methods. * @since 2.1.11 - experimental */ @Experimental public void cleanupBuffer() { buffer.trimHead(); }
@Override public void onError(Throwable t) { ObjectHelper.requireNonNull(t, "onError called with null. Null values are generally not allowed in 2.x operators and sources."); if (done) { RxJavaPlugins.onError(t); return; } done = true; Object o = NotificationLite.error(t); ReplayBuffer<T> b = buffer; b.addFinal(o); for (ReplayDisposable<T> rs : terminate(o)) { b.replay(rs); } }
/* test*/ int size() { return buffer.size(); }
@Override protected void subscribeActual(Observer<? super T> observer) { ReplayDisposable<T> rs = new ReplayDisposable<T>(observer, this); observer.onSubscribe(rs); if (!rs.cancelled) { if (add(rs)) { if (rs.cancelled) { remove(rs); return; } } buffer.replay(rs); } }
@Override public boolean hasComplete() { Object o = buffer.get(); return NotificationLite.isComplete(o); }
/** * Returns true if the subject has any value. * <p>The method is thread-safe. * @return true if the subject has any value */ public boolean hasValue() { return buffer.size() != 0; // NOPMD }
@Override public boolean hasThrowable() { Object o = buffer.get(); return NotificationLite.isError(o); }
/** * Returns a typed array containing a snapshot of all values of the Subject. * <p>The method follows the conventions of Collection.toArray by setting the array element * after the last value to null (if the capacity permits). * <p>The method is thread-safe. * @param array the target array to copy values into if it fits * @return the given array if the values fit into it or a new array containing all values */ public T[] getValues(T[] array) { return buffer.getValues(array); }
/** * Returns a single value the Subject currently has or null if no such value exists. * <p>The method is thread-safe. * @return a single value the Subject currently has or null if no such value exists */ @Nullable public T getValue() { return buffer.getValue(); }
@Override @Nullable public Throwable getThrowable() { Object o = buffer.get(); if (NotificationLite.isError(o)) { return NotificationLite.getError(o); } return null; }
/** * Makes sure the item cached by the head node in a bounded * ReplaySubject is released (as it is never part of a replay). * <p> * By default, live bounded buffers will remember one item before * the currently receivable one to ensure subscribers can always * receive a continuous sequence of items. A terminated ReplaySubject * automatically releases this inaccessible item. * <p> * The method must be called sequentially, similar to the standard * {@code onXXX} methods. * <p>History: 2.1.11 - experimental * @since 2.2 */ public void cleanupBuffer() { buffer.trimHead(); }
@Override public void onError(Throwable t) { ObjectHelper.requireNonNull(t, "onError called with null. Null values are generally not allowed in 2.x operators and sources."); if (done) { RxJavaPlugins.onError(t); return; } done = true; Object o = NotificationLite.error(t); ReplayBuffer<T> b = buffer; b.addFinal(o); for (ReplayDisposable<T> rs : terminate(o)) { b.replay(rs); } }
@Override protected void subscribeActual(Observer<? super T> observer) { ReplayDisposable<T> rs = new ReplayDisposable<T>(observer, this); observer.onSubscribe(rs); if (!rs.cancelled) { if (add(rs)) { if (rs.cancelled) { remove(rs); return; } } buffer.replay(rs); } }
/* test*/ int size() { return buffer.size(); }
/** * Returns true if the subject has any value. * <p>The method is thread-safe. * @return true if the subject has any value */ public boolean hasValue() { return buffer.size() != 0; // NOPMD }
@Override public boolean hasComplete() { Object o = buffer.get(); return NotificationLite.isComplete(o); }