AutoCloseableInstanceTracker

abstract class AutoCloseableInstanceTracker<T>(val unbindOnClose: Boolean = UNBIND_ON_CLOSE_DEFAULT, setCreator: () -> MutableSet<T>? = null) : InstanceTracker<T> , AutoCloseable

InstanceTracker which also implements the AutoCloseable interface.

This implementation is best suited for InstanceTracker which also requires the use of coroutines. Note that unbind must be invoked manually before close if unbindOnClose is set to false (which is the default).

Parameters

unbindOnClose

Whether to invoke unbind automatically when close is invoked. This requires less manual coding resource management, at the expense that deadlocks may occur.

setCreator

Creator for the Set used to track instances.

Constructors

Link copied to clipboard
constructor(unbindOnClose: Boolean = UNBIND_ON_CLOSE_DEFAULT, setCreator: () -> MutableSet<T>? = null)

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard
protected val instances: MutableSet<T>
Link copied to clipboard
private val isBound: AtomicBoolean
Link copied to clipboard
private val unbindOnClose: Boolean

Functions

Link copied to clipboard
fun add(instance: T): Boolean
Link copied to clipboard
override fun close()
Link copied to clipboard
fun list(): Set<T>
Link copied to clipboard
fun remove(instance: T): Boolean
Link copied to clipboard
suspend fun unbind()

Unbinds all tracked instances.

Link copied to clipboard
protected abstract suspend fun unbindImpl()

The actual implementation to clean up tracked instances (if any).