Enum Class SubscriptionHelper

java.lang.Object
java.lang.Enum<SubscriptionHelper>
com.forgerock.rxjava3.intern.subscriptions.SubscriptionHelper
All Implemented Interfaces:
Serializable, Comparable<SubscriptionHelper>, java.lang.constant.Constable, org.reactivestreams.Subscription

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

    Nested classes/interfaces inherited from class java.lang.Enum

    Enum.EnumDesc<E extends Enum<E>>
  • Enum Constant Summary

    Enum Constants
    Enum Constant
    Description
    Represents a cancelled Subscription.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
     
    static boolean
    cancel(AtomicReference<org.reactivestreams.Subscription> field)
    Atomically swaps in the common cancelled subscription instance and cancels the previous subscription if any.
    static void
    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
    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
    setOnce(AtomicReference<org.reactivestreams.Subscription> field, org.reactivestreams.Subscription s)
    Atomically sets the subscription on the field if it is still null.
    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.
    Returns the enum constant of this class with the specified name.
    Returns an array containing the constants of this enum class, in the order they are declared.

    Methods inherited from class java.lang.Object

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

    • CANCELLED

      public static final SubscriptionHelper CANCELLED
      Represents a cancelled Subscription.

      Don't leak this instance!

  • Method Details

    • values

      public static SubscriptionHelper[] values()
      Returns an array containing the constants of this enum class, in the order they are declared.
      Returns:
      an array containing the constants of this enum class, in the order they are declared
    • valueOf

      public static SubscriptionHelper valueOf(String name)
      Returns the enum constant of this class with the specified name. The string must match exactly an identifier used to declare an enum constant in this class. (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:
      IllegalArgumentException - if this enum class has no constant with the specified name
      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
    • setOnce

      public static boolean setOnce(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.
    • cancel

      public static boolean cancel(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).