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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionMerge two sets of references, ensuring only one reference is retained between the two setsvoidclose()Seerelease()iterator()static <T extends RefCounted<T>>
Refs<T>voidrelaseAllExcept(Collection<T> keep) voidrelease()Release ALL of the references held by this Refs collectionstatic voidstatic Throwablevoidrelease(Collection<T> release) Release a retained Ref to all of the provided objects; if any is not held, an exception will be thrownvoidbooleanreleaseIfHolds(T referenced) Release the retained Ref to the provided object, if held, return false otherwisestatic <T extends SelfRefCounted<T>>
Iterable<Ref<T>>intsize()static <T extends RefCounted<T>>
Refs<T>Acquire a reference to all of the provided objects, or nonebooleanAttempt to take a reference to the provided object; if it has already been released, null will be returnedMethods inherited from class java.util.AbstractCollection
add, addAll, clear, contains, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArray, toStringMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.Collection
equals, hashCode, parallelStream, removeIf, spliterator, stream, toArray
-
Constructor Details
-
Refs
public Refs() -
Refs
-
-
Method Details
-
release
public void release()Release ALL of the references held by this Refs collection -
close
public void close()Seerelease()- Specified by:
closein interfaceAutoCloseable
-
get
- Parameters:
referenced- the object we have a Ref to- Returns:
- the Ref to said object
-
release
- Parameters:
referenced- the object we have a Ref to
-
releaseIfHolds
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
-
release
Release a retained Ref to all of the provided objects; if any is not held, an exception will be thrown- Parameters:
release-
-
tryRef
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
- Specified by:
iteratorin interfaceCollection<T extends RefCounted<T>>- Specified by:
iteratorin interfaceIterable<T extends RefCounted<T>>- Specified by:
iteratorin classAbstractCollection<T extends RefCounted<T>>
-
size
public int size()- Specified by:
sizein interfaceCollection<T extends RefCounted<T>>- Specified by:
sizein classAbstractCollection<T extends RefCounted<T>>
-
addAll
Merge two sets of references, ensuring only one reference is retained between the two sets -
tryRef
Acquire a reference to all of the provided objects, or none -
ref
-
release
-
release
-
selfRefs
-