Enum SubscriptionHelper

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Comparable<SubscriptionHelper>, org.reactivestreams.Subscription

    public enum SubscriptionHelper
    extends java.lang.Enum<SubscriptionHelper>
    implements org.reactivestreams.Subscription
    Utility methods to validate Subscriptions in the various onSubscribe calls.
    • Enum Constant Summary

      Enum Constants 
      Enum Constant Description
      CANCELLED
      Represents a cancelled Subscription.
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private SubscriptionHelper()  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void cancel()  
      static boolean cancel​(java.util.concurrent.atomic.AtomicReference<org.reactivestreams.Subscription> field)
      Atomically swaps in the common cancelled subscription instance and cancels the previous subscription if any.
      static void deferredRequest​(java.util.concurrent.atomic.AtomicReference<org.reactivestreams.Subscription> field, java.util.concurrent.atomic.AtomicLong requested, long n)
      Atomically requests from the Subscription in the field if not null, otherwise accumulates the request amount in the requested field to be requested once the field is set to non-null.
      static boolean deferredSetOnce​(java.util.concurrent.atomic.AtomicReference<org.reactivestreams.Subscription> field, java.util.concurrent.atomic.AtomicLong requested, org.reactivestreams.Subscription s)
      Atomically sets the new Subscription on the field and requests any accumulated amount from the requested field.
      static boolean replace​(java.util.concurrent.atomic.AtomicReference<org.reactivestreams.Subscription> field, org.reactivestreams.Subscription s)
      Atomically sets the subscription on the field but does not cancel the previous subscription.
      static void reportMoreProduced​(long n)
      Reports to the plugin error handler that there were more values produced than requested, which is a sign of internal backpressure handling bug.
      static void reportSubscriptionSet()
      Reports that the subscription is already set to the RxJavaPlugins error handler, which is an indication of a onSubscribe management bug.
      void request​(long n)  
      static boolean set​(java.util.concurrent.atomic.AtomicReference<org.reactivestreams.Subscription> field, org.reactivestreams.Subscription s)
      Atomically sets the subscription on the field and cancels the previous subscription if any.
      static boolean setOnce​(java.util.concurrent.atomic.AtomicReference<org.reactivestreams.Subscription> field, org.reactivestreams.Subscription s)
      Atomically sets the subscription on the field if it is still null.
      static boolean setOnce​(java.util.concurrent.atomic.AtomicReference<org.reactivestreams.Subscription> field, org.reactivestreams.Subscription s, long request)
      Atomically sets the subscription on the field if it is still null and issues a positive request to the given Subscription.
      static boolean validate​(long n)
      Validates that the n is positive.
      static boolean validate​(org.reactivestreams.Subscription current, org.reactivestreams.Subscription next)
      Verifies that current is null, next is not null, otherwise signals errors to the RxJavaPlugins and returns false.
      static SubscriptionHelper valueOf​(java.lang.String name)
      Returns the enum constant of this type with the specified name.
      static SubscriptionHelper[] values()
      Returns an array containing the constants of this enum type, in the order they are declared.
      • Methods inherited from class java.lang.Enum

        clone, compareTo, equals, finalize, getDeclaringClass, hashCode, name, ordinal, toString, valueOf
      • Methods inherited from class java.lang.Object

        getClass, notify, notifyAll, wait, wait, wait
    • Enum Constant Detail

      • CANCELLED

        public static final SubscriptionHelper CANCELLED
        Represents a cancelled Subscription.

        Don't leak this instance!

    • Constructor Detail

      • SubscriptionHelper

        private SubscriptionHelper()
    • Method Detail

      • values

        public static SubscriptionHelper[] values()
        Returns an array containing the constants of this enum type, in the order they are declared. This method may be used to iterate over the constants as follows:
        for (SubscriptionHelper c : SubscriptionHelper.values())
            System.out.println(c);
        
        Returns:
        an array containing the constants of this enum type, in the order they are declared
      • valueOf

        public static SubscriptionHelper valueOf​(java.lang.String name)
        Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (Extraneous whitespace characters are not permitted.)
        Parameters:
        name - the name of the enum constant to be returned.
        Returns:
        the enum constant with the specified name
        Throws:
        java.lang.IllegalArgumentException - if this enum type has no constant with the specified name
        java.lang.NullPointerException - if the argument is null
      • request

        public void request​(long n)
        Specified by:
        request in interface org.reactivestreams.Subscription
      • cancel

        public void cancel()
        Specified by:
        cancel in interface org.reactivestreams.Subscription
      • validate

        public static boolean validate​(org.reactivestreams.Subscription current,
                                       org.reactivestreams.Subscription next)
        Verifies that current is null, next is not null, otherwise signals errors to the RxJavaPlugins and returns false.
        Parameters:
        current - the current Subscription, expected to be null
        next - the next Subscription, expected to be non-null
        Returns:
        true if the validation succeeded
      • reportSubscriptionSet

        public static void reportSubscriptionSet()
        Reports that the subscription is already set to the RxJavaPlugins error handler, which is an indication of a onSubscribe management bug.
      • validate

        public static boolean validate​(long n)
        Validates that the n is positive.
        Parameters:
        n - the request amount
        Returns:
        false if n is non-positive.
      • reportMoreProduced

        public static void reportMoreProduced​(long n)
        Reports to the plugin error handler that there were more values produced than requested, which is a sign of internal backpressure handling bug.
        Parameters:
        n - the overproduction amount
      • set

        public static boolean set​(java.util.concurrent.atomic.AtomicReference<org.reactivestreams.Subscription> field,
                                  org.reactivestreams.Subscription s)
        Atomically sets the subscription on the field and cancels the previous subscription if any.
        Parameters:
        field - the target field to set the new subscription on
        s - the new subscription
        Returns:
        true if the operation succeeded, false if the target field holds the CANCELLED instance.
        See Also:
        replace(AtomicReference, Subscription)
      • setOnce

        public static boolean setOnce​(java.util.concurrent.atomic.AtomicReference<org.reactivestreams.Subscription> field,
                                      org.reactivestreams.Subscription s)
        Atomically sets the subscription on the field if it is still null.

        If the field is not null and doesn't contain the CANCELLED instance, the reportSubscriptionSet() is called.

        Parameters:
        field - the target field
        s - the new subscription to set
        Returns:
        true if the operation succeeded, false if the target field was not null.
      • replace

        public static boolean replace​(java.util.concurrent.atomic.AtomicReference<org.reactivestreams.Subscription> field,
                                      org.reactivestreams.Subscription s)
        Atomically sets the subscription on the field but does not cancel the previous subscription.
        Parameters:
        field - the target field to set the new subscription on
        s - the new subscription
        Returns:
        true if the operation succeeded, false if the target field holds the CANCELLED instance.
        See Also:
        set(AtomicReference, Subscription)
      • cancel

        public static boolean cancel​(java.util.concurrent.atomic.AtomicReference<org.reactivestreams.Subscription> field)
        Atomically swaps in the common cancelled subscription instance and cancels the previous subscription if any.
        Parameters:
        field - the target field to dispose the contents of
        Returns:
        true if the swap from the non-cancelled instance to the common cancelled instance happened in the caller's thread (allows further one-time actions).
      • deferredSetOnce

        public static boolean deferredSetOnce​(java.util.concurrent.atomic.AtomicReference<org.reactivestreams.Subscription> field,
                                              java.util.concurrent.atomic.AtomicLong requested,
                                              org.reactivestreams.Subscription s)
        Atomically sets the new Subscription on the field and requests any accumulated amount from the requested field.
        Parameters:
        field - the target field for the new Subscription
        requested - the current requested amount
        s - the new Subscription, not null (verified)
        Returns:
        true if the Subscription was set the first time
      • deferredRequest

        public static void deferredRequest​(java.util.concurrent.atomic.AtomicReference<org.reactivestreams.Subscription> field,
                                           java.util.concurrent.atomic.AtomicLong requested,
                                           long n)
        Atomically requests from the Subscription in the field if not null, otherwise accumulates the request amount in the requested field to be requested once the field is set to non-null.
        Parameters:
        field - the target field that may already contain a Subscription
        requested - the current requested amount
        n - the request amount, positive (verified)
      • setOnce

        public static boolean setOnce​(java.util.concurrent.atomic.AtomicReference<org.reactivestreams.Subscription> field,
                                      org.reactivestreams.Subscription s,
                                      long request)
        Atomically sets the subscription on the field if it is still null and issues a positive request to the given Subscription.

        If the field is not null and doesn't contain the CANCELLED instance, the reportSubscriptionSet() is called.

        Parameters:
        field - the target field
        s - the new subscription to set
        request - the amount to request, positive (not verified)
        Returns:
        true if the operation succeeded, false if the target field was not null.
        Since:
        2.1.11