Package com.complexible.common.base
Interface AutoDisposable
- All Superinterfaces:
Disposable
- All Known Implementing Classes:
AbstractAutoDisposable
A special kind of
Disposable that keeps track of references to it and disposes the
object automatically when there are no references left. At creation time an AutoDisposable
has zero reference count so whenever same number of release() calls follows acquire()
calls, it will be automatically closed. Calling Disposable.dispose() directly will dispose the object
immediately regardless of the reference count.- Since:
- 3.0
- Version:
- 3.0
- Author:
- Evren Sirin
-
Method Summary
Modifier and TypeMethodDescription<T extends AutoDisposable>
Tacquire()Acquires a reference to this object preventing it from being automatically disposed until the reference is released.intReturn the current reference count for this object.voidrelease()Releases one of these object's references.<T extends AutoDisposable>
TTries to acquire a reference to this object.Methods inherited from interface com.complexible.common.base.Disposable
dispose
-
Method Details
-
acquire
Acquires a reference to this object preventing it from being automatically disposed until the reference is released.- Type Parameters:
T-- Returns:
- this object
-
tryAcquire
Tries to acquire a reference to this object. Returns the reference if the number of references to the object is greater than zero at the time of the call. If not, it's possible that the object has already been disposed sonullis returned instead. Note: this method should be used after the object has beenacquiredfor the first time. Before that it always returnsnull. The common use case is that the firstacquire()happens before the object is published and becomes visible to users.- Type Parameters:
T- object type- Returns:
- this object
-
release
void release() -
getRefCount
int getRefCount()Return the current reference count for this object. Provided only for informational purposes.
-