Package com.complexible.common.base
Class AbstractAutoDisposable
java.lang.Object
com.complexible.common.base.AbstractAutoDisposable
- All Implemented Interfaces:
AutoDisposable,Disposable
- Author:
- Evren Sirin
-
Constructor Summary
Constructors -
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.intReturns the current reference count.voidrelease()Releases one of these object's references.<T extends AutoDisposable>
TTries to acquire a reference to this object.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.complexible.common.base.Disposable
dispose
-
Constructor Details
-
AbstractAutoDisposable
public AbstractAutoDisposable()
-
-
Method Details
-
acquire
Description copied from interface:AutoDisposableAcquires a reference to this object preventing it from being automatically disposed until the reference is released.- Specified by:
acquirein interfaceAutoDisposable- Type Parameters:
T-- Returns:
- this object
-
tryAcquire
Description copied from interface:AutoDisposableTries 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 firstAutoDisposable.acquire()happens before the object is published and becomes visible to users.- Specified by:
tryAcquirein interfaceAutoDisposable- Type Parameters:
T- object type- Returns:
- this object
-
release
public void release()Description copied from interface:AutoDisposableReleases one of these object's references. If the number of references reaches to or goes below0, this object will bedisposed. So calling this function without any precedingAutoDisposable.acquire()calls will cause the dispose function to be called multiple times.- Specified by:
releasein interfaceAutoDisposable
-
getRefCount
public int getRefCount()Returns the current reference count.- Specified by:
getRefCountin interfaceAutoDisposable
-