Documentation / listeners / com.femastudios.listeners / BaseListenersManager

BaseListenersManager

abstract class BaseListenersManager<Interface : Any> : FlexibleSet<Interface>, ListenersManager<Interface>

Base implementation for ListenersManager.

To invoke the currently attached listeners, you can use the method callListeners.

Constructors

<init>

Base implementation for ListenersManager.

BaseListenersManager()

Properties

baseListenersManagerSynchronizer

val baseListenersManagerSynchronizer: Any

hasListeners

Whether this ListenersManager has associated listeners

var hasListeners: Boolean

hasStrongListeners

var hasStrongListeners: Boolean

Functions

addStrongly

Adds a listener, keeping a strong reference. This means that if nobody else keeps a pointer to the listener, it won't be disposed by the Garbage Collector and will be kept in this object forever.

fun addStrongly(listener: Interface): Unit

addStronglyWithoutCallingHasListeners

Adds the given listener strongly, like addStrongly. However, if doing so would have called the onHasListenersChanges lambda, this method won't call it, and returns true. When this happens, you must call notifyHasListeners

fun addStronglyWithoutCallingHasListeners(listener: Interface): Boolean

addWeakly

Adds a listener, keeping a weak reference. This means that if nobody else keeps a pointer to the listener, it'll at some point automatically disposed by the Garbage Collector.

fun addWeakly(listener: Interface): Unit

addWeaklyWithoutCallingHasListeners

Adds the given listener weakly, like addWeakly. However, if doing so would have called the onHasListenersChanges lambda, this method won't call it, and returns true. When this happens, you must call notifyHasListeners

fun addWeaklyWithoutCallingHasListeners(listener: Interface): Boolean

callListeners

Use this method to invoke some method on the currently attached listeners.

fun callListeners(caller: (Interface) -> Unit): Unit

contains

Returns whether or not the given listener is contained in this listener manager

fun contains(listener: Interface): Boolean

notifyHasListeners

You must call this method if addWeaklyWithoutCallingHasListeners or removeWithoutCallingHasListeners or addStronglyWithoutCallingHasListeners returned true

fun notifyHasListeners(): Unit

onHasListenersChanges

Callback that will be called after hasListeners changes.

open fun onHasListenersChanges(): Unit

onHasListenersChangesImmediate

Callback that will be called immediately after hasListeners or hasStrongListeners change. This method will be executed in a synchronized context, so it's important to not acquire additional locks.

open fun onHasListenersChangesImmediate(hadListeners: Boolean, hadStrongListeners: Boolean): Unit

remove

Removes the specified listener.

fun remove(listener: Interface): Unit

removeWithoutCallingHasListeners

Removes the given listener, like remove. However, if doing so would have called the onHasListenersChanges lambda, this method won't call it, and returns true. When this happens, you must call notifyHasListeners

fun removeWithoutCallingHasListeners(listener: Interface): Boolean

Inheritors

ReflectionListenersManager

This implementation of ListenersManager is the easiest to use. Through reflection, it is possible to use it without the need to write any custom code.

open class ReflectionListenersManager<Interface : Any> : BaseListenersManager<Interface>, CallableListenersManager<Interface>