Implement a thread-safe EventManager
class that handles event notifications asynchronously to multiple listeners. The EventManager
should be able to register listeners, deregister them, and notify them of events in a concurrent environment.
- There is already defined an
EventListener
interface with a single methodonEvent(Event e)
. This method is called whenever an event is notified. - There is already defined an
Event
class that encapsulates details of an event, such as type and source.
Implement an EventManager
class with the following capabilities:
- Listener registration: Method
registerListener(EventListener listener)
to add a new listener. - Listener deregistration: Method
deregisterListener(EventListener listener)
to remove an existing listener. - Event notification: Method
notifyEvent(Event event)
to asynchronously notify all registered listeners of an event. - Shutdown mechanism: Method
shutdown()
to properly close any resources if required.