Package com.complexible.common.base

# Interface AutoDisposable

All Superinterfaces:
  `Disposable`

All Known Implementing Classes:
  `AbstractAutoDisposable`

public interface AutoDisposable extends Disposable
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 Type
  Method
  Description
  `<T extends AutoDisposable>
  T`
  `acquire()`
  Acquires a reference to this object preventing it from being automatically disposed until the reference is released.
  `int`
  `getRefCount()`
  Return the current reference count for this object.
  `void`
  `release()`
  Releases one of these object's references.
  `<T extends AutoDisposable>
  T`
  `tryAcquire()`
  Tries to acquire a reference to this object.

  ### Methods inherited from interface com.complexible.common.base.Disposable

  `dispose`

- ## Method Details

  - ### acquire

    <T extends AutoDisposable> T 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

    <T extends AutoDisposable> T 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 so `null` is returned instead. Note: this method should be used after the object has been `acquired` for the first time. Before that it always returns `null`. The common use case is that the first `acquire()` happens before the object is published and becomes visible to users.
    Type Parameters:
      `T` - object type
    Returns:
      this object

  - ### release

    void release()
    Releases one of these object's references. If the number of references reaches to or goes below `0`, this object will be `disposed`. So calling this function without any preceding `acquire()` calls will cause the dispose function to be called multiple times.

  - ### getRefCount

    int getRefCount()
    Return the current reference count for this object. Provided only for informational purposes.