Class Refs<T extends RefCounted<T>>

java.lang.Object
java.util.AbstractCollection<T>
org.apache.cassandra.utils.concurrent.Refs<T>
All Implemented Interfaces:
AutoCloseable, Iterable<T>, Collection<T>

public final class Refs<T extends RefCounted<T>> extends AbstractCollection<T> implements AutoCloseable
A collection of managed Ref references to RefCounted objects, and the objects they are referencing. Care MUST be taken when using this collection, as if a permanent reference to it leaks we will not be alerted to a lack of reference release. All of the java.util.Collection operations that modify the collection are unsupported.
  • Constructor Details

    • Refs

      public Refs()
    • Refs

      public Refs(Map<T,Ref<T>> references)
  • Method Details

    • release

      public void release()
      Release ALL of the references held by this Refs collection
    • close

      public void close()
      Specified by:
      close in interface AutoCloseable
    • get

      public Ref<T> get(T referenced)
      Parameters:
      referenced - the object we have a Ref to
      Returns:
      the Ref to said object
    • release

      public void release(T referenced)
      Parameters:
      referenced - the object we have a Ref to
    • releaseIfHolds

      public boolean releaseIfHolds(T referenced)
      Release the retained Ref to the provided object, if held, return false otherwise
      Parameters:
      referenced - the object we retain a Ref to
      Returns:
      return true if we held a reference to the object, and false otherwise
    • relaseAllExcept

      public void relaseAllExcept(Collection<T> keep)
    • release

      public void release(Collection<T> release)
      Release a retained Ref to all of the provided objects; if any is not held, an exception will be thrown
      Parameters:
      release -
    • tryRef

      public boolean tryRef(T t)
      Attempt to take a reference to the provided object; if it has already been released, null will be returned
      Parameters:
      t - object to acquire a reference to
      Returns:
      true iff success
    • iterator

      public Iterator<T> iterator()
      Specified by:
      iterator in interface Collection<T extends RefCounted<T>>
      Specified by:
      iterator in interface Iterable<T extends RefCounted<T>>
      Specified by:
      iterator in class AbstractCollection<T extends RefCounted<T>>
    • size

      public int size()
      Specified by:
      size in interface Collection<T extends RefCounted<T>>
      Specified by:
      size in class AbstractCollection<T extends RefCounted<T>>
    • addAll

      public Refs<T> addAll(Refs<T> add)
      Merge two sets of references, ensuring only one reference is retained between the two sets
    • tryRef

      public static <T extends RefCounted<T>> Refs<T> tryRef(Iterable<? extends T> reference)
      Acquire a reference to all of the provided objects, or none
    • ref

      public static <T extends RefCounted<T>> Refs<T> ref(Iterable<? extends T> reference)
    • release

      public static void release(Iterable<? extends Ref<?>> refs)
    • release

      public static Throwable release(Iterable<? extends Ref<?>> refs, Throwable accumulate)
    • selfRefs

      public static <T extends SelfRefCounted<T>> Iterable<Ref<T>> selfRefs(Iterable<T> refs)