Event Dispatcher  v0.1.6-beta.1
Project that offers a small library that allows to subscribe and fire events.
EventPublisher< T >abstract

Detailed Description

Class that allows to register and notify event listeners.

Parameters
<T>the listener type that will provide the notification method

Definition at line 15 of file EventPublisher.java.

+ Inheritance diagram for EventPublisher< T >:

Public Member Functions

registerListener (T listener)
 
void unregisterListener (T listener)
 
void unregisterAllListeners ()
 
void notifyListeners (Consumer<? super T > action)
 

Protected Attributes

final Lock readLock = readWriteLock.readLock()
 
final Lock writeLock = readWriteLock.writeLock()
 

Private Attributes

final ReadWriteLock readWriteLock = new ReentrantReadWriteLock(true)
 
List< T > listeners = new ArrayList<>()
 

Member Function Documentation

◆ registerListener()

T registerListener ( listener)

Adds the specified listener to the list of registered listeners.

Parameters
listenerthe listener that will be called
Returns
the registered listener instance

Definition at line 29 of file EventPublisher.java.

◆ unregisterListener()

void unregisterListener ( listener)

Removes the first occurrence of the specified listener from the list of the registered listeners.

Parameters
listenerthe listener that should be removed from the list

Definition at line 50 of file EventPublisher.java.

◆ unregisterAllListeners()

void unregisterAllListeners ( )

Removes all the listeners from the list of the registered listeners.

The list will be empty after this call returns.

Definition at line 68 of file EventPublisher.java.

◆ notifyListeners()

void notifyListeners ( Consumer<? super T >  action)

Notifies and executes on each of the registered listeners the provided function.

Parameters
actionoperation that accepts a single input argument and returns no result

Definition at line 88 of file EventPublisher.java.

Member Data Documentation

◆ readWriteLock

final ReadWriteLock readWriteLock = new ReentrantReadWriteLock(true)
private

Definition at line 17 of file EventPublisher.java.

◆ readLock

final Lock readLock = readWriteLock.readLock()
protected

Definition at line 18 of file EventPublisher.java.

◆ writeLock

final Lock writeLock = readWriteLock.writeLock()
protected

Definition at line 19 of file EventPublisher.java.

◆ listeners

List<T> listeners = new ArrayList<>()
private

Definition at line 21 of file EventPublisher.java.