/** * Set a new latest NotificationLite value and return the active observers. * @param n the new latest value * @return the array of SubjectObservers, don't write into the array! */ SubjectObserver<T>[] next(Object n) { set(n); return state.observers; } /**
public void clear() { state.set(null); }
/** * Atomically set the terminal NotificationLite value (which could be any of the 3), * clear the active observers and return the last active observers. * @param n the terminal value * @return the last active SubjectObservers */ SubjectObserver<T>[] terminate(Object n) { set(n); active = false; State<T> oldState = state; if (oldState.terminated) { return State.NO_OBSERVERS; } return STATE_UPDATER.getAndSet(this, State.TERMINATED).observers; }
private static <T> BehaviorSubject<T> create(T defaultValue, boolean hasDefault) { final SubjectSubscriptionManager<T> state = new SubjectSubscriptionManager<T>(); if (hasDefault) { state.set(NotificationLite.instance().next(defaultValue)); } state.onAdded = new Action1<SubjectObserver<T>>() { @Override public void call(SubjectObserver<T> o) { o.emitFirst(state.get(), state.nl); } }; state.onTerminated = state.onAdded; return new BehaviorSubject<T>(state, state); }
private static <T> ClearableBehaviorSubject<T> create(T defaultValue, boolean hasDefault) { final SubjectSubscriptionManager<T> state = new SubjectSubscriptionManager<T>(); if (hasDefault) { state.set(NotificationLite.instance().next(defaultValue)); } state.onAdded = new Action1<SubjectObserver<T>>() { @Override public void call(SubjectObserver<T> o) { o.emitFirst(state.get(), state.nl); } }; state.onTerminated = state.onAdded; return new ClearableBehaviorSubject<T>(state, state); }