1 package com.fermod.event;
3 import java.util.ArrayList;
5 import java.util.concurrent.locks.Lock;
6 import java.util.concurrent.locks.ReadWriteLock;
7 import java.util.concurrent.locks.ReentrantReadWriteLock;
8 import java.util.function.Consumer;
17 private final ReadWriteLock
readWriteLock =
new ReentrantReadWriteLock(
true);
32 this.writeLock.lock();
36 this.listeners.add(listener);
39 this.writeLock.unlock();
53 this.writeLock.lock();
57 this.listeners.remove(listener);
60 this.writeLock.unlock();
71 this.writeLock.lock();
75 this.listeners.clear();
78 this.writeLock.unlock();
95 this.listeners.forEach(action);
98 this.readLock.unlock();
void notifyListeners(Consumer<? super T > action)
Notifies and executes on each of the registered listeners the provided function.
void unregisterAllListeners()
Removes all the listeners from the list of the registered listeners.
final ReadWriteLock readWriteLock
T registerListener(T listener)
Adds the specified listener to the list of registered listeners.
void unregisterListener(T listener)
Removes the first occurrence of the specified listener from the list of the registered listeners.
Class that allows to register and notify event listeners.