Class Subject<T,R>

    • Method Detail

      • hasObservers

        public abstract boolean hasObservers()
        Indicates whether the Subject has Observers subscribed to it.
        Returns:
        true if there is at least one Observer subscribed to this Subject, false otherwise
      • toSerialized

        public final SerializedSubject<T,R> toSerialized()
        Wraps a Subject so that it is safe to call its various on methods from different threads.

        When you use an ordinary Subject as a Subscriber, you must take care not to call its Observer.onNext(T) method (or its other on methods) from multiple threads, as this could lead to non-serialized calls, which violates the Observable contract and creates an ambiguity in the resulting Subject.

        To protect a Subject from this danger, you can convert it into a SerializedSubject with code like the following:

         mySafeSubject = myUnsafeSubject.toSerialized(); 
        Returns:
        SerializedSubject wrapping the current Subject
      • hasThrowable

        @Experimental
         @Deprecated
        public boolean hasThrowable()
        Deprecated.  this method will be moved to each Subject class individually in the next release
        Check if the Subject has terminated with an exception.

        The operation is threadsafe.

        Returns:
        true if the subject has received a throwable through onError.
        Since:
        (If this graduates from being an Experimental class method, replace this parenthetical with the release number)
      • hasCompleted

        @Experimental
         @Deprecated
        public boolean hasCompleted()
        Deprecated.  this method will be moved to each Subject class individually in the next release
        Check if the Subject has terminated normally.

        The operation is threadsafe.

        Returns:
        true if the subject completed normally via onCompleted
        Since:
        (If this graduates from being an Experimental class method, replace this parenthetical with the release number)
      • getThrowable

        @Experimental
         @Deprecated
        public Throwable getThrowable()
        Deprecated.  this method will be moved to each Subject class individually in the next release
        Returns the Throwable that terminated the Subject.

        The operation is threadsafe.

        Returns:
        the Throwable that terminated the Subject or null if the subject hasn't terminated yet or if it terminated normally.
        Since:
        (If this graduates from being an Experimental class method, replace this parenthetical with the release number)
      • hasValue

        @Experimental
         @Deprecated
        public boolean hasValue()
        Deprecated.  this method will be moved to each Subject class individually in the next release
        Check if the Subject has any value.

        Use the getValue() method to retrieve such a value.

        Note that unless hasCompleted() or hasThrowable() returns true, the value retrieved by getValue() may get outdated.

        The operation is threadsafe.

        Returns:
        true if and only if the subject has some value but not an error
        Since:
        (If this graduates from being an Experimental class method, replace this parenthetical with the release number)
      • getValue

        @Experimental
         @Deprecated
        public T getValue()
        Deprecated.  this method will be moved to each Subject class individually in the next release
        Returns the current or latest value of the Subject if there is such a value and the subject hasn't terminated with an exception.

        The method can return null for various reasons. Use hasValue(), hasThrowable() and hasCompleted() to determine if such null is a valid value, there was an exception or the Subject terminated without receiving any value.

        The operation is threadsafe.

        Returns:
        the current value or null if the Subject doesn't have a value, has terminated with an exception or has an actual null as a value.
        Since:
        (If this graduates from being an Experimental class method, replace this parenthetical with the release number)
      • getValues

        @Experimental
         @Deprecated
        public Object[] getValues()
        Deprecated.  this method will be moved to each Subject class individually in the next release
        Returns a snapshot of the currently buffered non-terminal events.

        The operation is threadsafe.

        Returns:
        a snapshot of the currently buffered non-terminal events.
        Since:
        (If this graduates from being an Experimental class method, replace this parenthetical with the release number)
      • getValues

        @Experimental
         @Deprecated
        public T[] getValues(T[] a)
        Deprecated.  this method will be moved to each Subject class individually in the next release
        Returns a snapshot of the currently buffered non-terminal events into the provided a array or creates a new array if it has not enough capacity.

        If the subject's values fit in the specified array with room to spare (i.e., the array has more elements than the list), the element in the array immediately following the end of the subject's values is set to null.

        The operation is threadsafe.

        Parameters:
        a - the array to fill in
        Returns:
        the array a if it had enough capacity or a new array containing the available values
        Since:
        (If this graduates from being an Experimental class method, replace this parenthetical with the release number)