Class Refs<T extends RefCounted<T>>
- java.lang.Object
-
- java.util.AbstractCollection<T>
-
- org.apache.cassandra.utils.concurrent.Refs<T>
-
- All Implemented Interfaces:
java.lang.AutoCloseable
,java.lang.Iterable<T>
,java.util.Collection<T>
public final class Refs<T extends RefCounted<T>> extends java.util.AbstractCollection<T> implements java.lang.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.
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Refs<T>
addAll(Refs<T> add)
Merge two sets of references, ensuring only one reference is retained between the two setsvoid
close()
Seerelease()
Ref<T>
get(T referenced)
java.util.Iterator<T>
iterator()
static <T extends RefCounted<T>>
Refs<T>ref(java.lang.Iterable<? extends T> reference)
void
relaseAllExcept(java.util.Collection<T> keep)
void
release()
Release ALL of the references held by this Refs collectionstatic void
release(java.lang.Iterable<? extends Ref<?>> refs)
static java.lang.Throwable
release(java.lang.Iterable<? extends Ref<?>> refs, java.lang.Throwable accumulate)
void
release(java.util.Collection<T> release)
Release a retained Ref to all of the provided objects; if any is not held, an exception will be thrownvoid
release(T referenced)
boolean
releaseIfHolds(T referenced)
Release the retained Ref to the provided object, if held, return false otherwisestatic <T extends SelfRefCounted<T>>
java.lang.Iterable<Ref<T>>selfRefs(java.lang.Iterable<T> refs)
int
size()
static <T extends RefCounted<T>>
Refs<T>tryRef(java.lang.Iterable<? extends T> reference)
Acquire a reference to all of the provided objects, or noneboolean
tryRef(T t)
Attempt to take a reference to the provided object; if it has already been released, null will be returned-
Methods inherited from class java.util.AbstractCollection
add, addAll, clear, contains, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArray, toString
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
-
-
-
Method Detail
-
release
public void release()
Release ALL of the references held by this Refs collection
-
close
public void close()
Seerelease()
- Specified by:
close
in interfacejava.lang.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(java.util.Collection<T> keep)
-
release
public void release(java.util.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 java.util.Iterator<T> iterator()
- Specified by:
iterator
in interfacejava.util.Collection<T extends RefCounted<T>>
- Specified by:
iterator
in interfacejava.lang.Iterable<T extends RefCounted<T>>
- Specified by:
iterator
in classjava.util.AbstractCollection<T extends RefCounted<T>>
-
size
public int size()
- Specified by:
size
in interfacejava.util.Collection<T extends RefCounted<T>>
- Specified by:
size
in classjava.util.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(java.lang.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(java.lang.Iterable<? extends T> reference)
-
release
public static void release(java.lang.Iterable<? extends Ref<?>> refs)
-
release
public static java.lang.Throwable release(java.lang.Iterable<? extends Ref<?>> refs, java.lang.Throwable accumulate)
-
selfRefs
public static <T extends SelfRefCounted<T>> java.lang.Iterable<Ref<T>> selfRefs(java.lang.Iterable<T> refs)
-
-