docs/javadoc/reference/com/facebook/common/references/CloseableReference.html
|
|
Summary: Nested Classes | Constants | Fields | Protected Ctors | Methods | Protected Methods | Inherited Methods | [Expand All]
public abstract class
extends Object
implements Closeable Cloneable
| java.lang.Object | | ↳ | com.facebook.common.references.CloseableReference<T> |
| Known Direct Subclasses
DefaultCloseableReference<T>, FinalizerCloseableReference<T>, NoOpCloseableReference<T>, RefCountCloseableReference<T>
| DefaultCloseableReference<T> | | | FinalizerCloseableReference<T> | | | NoOpCloseableReference<T> | | | RefCountCloseableReference<T> | |
|
A smart pointer-like class for Java.
This class allows reference-counting semantics in a Java-friendlier way. A single object can have any number of CloseableReferences pointing to it. When all of these have been closed, the object either has its close() method called, if it implements Closeable, or its designated release(T), if it does not.
Callers can construct a CloseableReference wrapping a Closeable with:
Closeable foo;
CloseableReference c = CloseableReference.of(foo);
Objects that do not implement Closeable can still use this class, but must supply a ResourceReleaser:
Object foo;
ResourceReleaser<Object> fooReleaser;
CloseableReference c = CloseableReference.of(foo, fooReleaser);
When making a logical copy, callers should call clone():
CloseableReference copy = c.clone();
When each copy of CloseableReference is no longer needed, close should be called:
copy.close();
c.close();
As with any Closeable, try-finally semantics may be needed to ensure that close is called.
Do not rely upon the finalizer; the purpose of this class is for expensive resources to be released without waiting for the garbage collector. The finalizer will log an error if the close method has not been called.
| Nested Classes |
|---|
| @interface |
| interface |
| Constants |
|---|
| int |
| int |
| int |
| int |
| Fields |
|---|
| protected boolean |
| protected final CloseableReference.LeakHandler |
| protected final SharedReference<T> |
| protected final Throwable |
| Protected Constructors |
|---|
| Public Methods |
|---|
| abstract CloseableReference<T> |
| Returns a new CloseableReference to the same underlying SharedReference. |
| static <T> CloseableReference<T> |
| Returns the cloned reference if valid, null otherwise. |
| static <T> List<CloseableReference<T>> |
| Clones a collection of references and returns a list. |
| synchronized CloseableReference<T> |
| void |
| Closes this CloseableReference. |
| static void |
| Closes the references in the iterable handling null. |
| static void |
| Closes the reference handling null. |
| synchronized T |
| Returns the underlying Closeable if this reference is not closed yet. |
| synchronized SharedReference<T> |
| A test-only method to get the underlying references. |
| int |
| Method used for tracking Closeables pointed by CloseableReference. |
| synchronized boolean |
| Checks if this closable-reference is valid i.e. |
| static boolean |
| Checks if the closable-reference is valid i.e. |
| static <T extends Closeable> CloseableReference<T> |
| Constructs a CloseableReference. |
| static <T> CloseableReference<T> |
| Constructs a CloseableReference (wrapping a SharedReference) of T with provided ResourceReleaser. |
| static <T> CloseableReference<T> |
| static <T> CloseableReference<T> |
| Constructs a CloseableReference (wrapping a SharedReference) of T with provided ResourceReleaser and a custom handler that's run if a leak is detected in the finalizer. |
| static <T extends Closeable> CloseableReference<T> |
Constructs a CloseableReference with a custom CloseableReference.LeakHandler that's run if a reference is not closed when the finalizer is called. |
| static void |
| static boolean |
| Protected Methods |
|---|
| void |
| [Expand] Inherited Methods | | --- | | From class java.lang.Object
| Object | clone() | | boolean | equals(Object arg0) | | void | finalize() | | final Class<?> | getClass() | | int | hashCode() | | final void | notify() | | final void | notifyAll() | | String | toString() | | final void | wait(long arg0, int arg1) | | final void | wait(long arg0) | | final void | wait() |
| | From interface java.io.Closeable
| abstract void | close() |
| | From interface java.lang.AutoCloseable
| abstract void | close() |
|
Constant Value: 0 (0x00000000)
Constant Value: 1 (0x00000001)
Constant Value: 3 (0x00000003)
Constant Value: 2 (0x00000002)
Returns a new CloseableReference to the same underlying SharedReference. The SharedReference ref-count is incremented.
Returns the cloned reference if valid, null otherwise.
| ref | the reference to clone |
Clones a collection of references and returns a list. Returns null if the list is null. If the list is non-null, clones each reference. If a reference cannot be cloned due to already being closed, the list will contain a null value in its place.
| refs | the references to clone |
Closes this CloseableReference.
Decrements the reference count of the underlying object. If it is zero, the object will be released.
This method is idempotent. Calling it multiple times on the same instance has no effect.
Closes the references in the iterable handling null.
| references | the reference to close |
Closes the reference handling null.
| ref | the reference to close |
Returns the underlying Closeable if this reference is not closed yet. Otherwise IllegalStateException is thrown.
A test-only method to get the underlying references.
DO NOT USE in application code.
Method used for tracking Closeables pointed by CloseableReference. Use only for debugging and logging.
Checks if this closable-reference is valid i.e. is not closed.
Checks if the closable-reference is valid i.e. is not null, and is not closed.
Constructs a CloseableReference.
Returns null if the parameter is null.
Constructs a CloseableReference (wrapping a SharedReference) of T with provided ResourceReleaser. If t is null, this will just return null.
Constructs a CloseableReference (wrapping a SharedReference) of T with provided ResourceReleaser and a custom handler that's run if a leak is detected in the finalizer. If t is null, this will just return null.
Constructs a CloseableReference with a custom CloseableReference.LeakHandler that's run if a reference is not closed when the finalizer is called.
Returns null if the parameter is null.
| Throwable | |
+Generated by Doclava. +