Class EventManager
java.lang.Object
com.github.philippheuer.events4j.core.EventManager
- All Implemented Interfaces:
com.github.philippheuer.events4j.api.IEventManager,AutoCloseable
public class EventManager
extends Object
implements com.github.philippheuer.events4j.api.IEventManager
The EventManager
- Since:
- 1.0
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidAutomatic discovery of optional componentsvoidclose()ShutdownList<com.github.philippheuer.events4j.api.domain.IEventSubscription>Holds the current sequence for consumer registrationsDefault EventHandler<E extends com.github.philippheuer.events4j.api.service.IEventHandler>
EgetEventHandler(Class<E> eventHandlerClass) Retrieves a EventHandler of the provided typeEventHandler Class CacheList<com.github.philippheuer.events4j.api.service.IEventHandler>Event Handlerscom.github.philippheuer.events4j.api.service.IServiceMediatorHolds the ServiceMediatorbooleanhasEventHandler(Class<? extends com.github.philippheuer.events4j.api.service.IEventHandler> eventHandlerClass) Checks if a given eventHandler is registered / presentbooleanis Stopped?<E> com.github.philippheuer.events4j.api.domain.IEventSubscriptionRegisters a event consumer<E> com.github.philippheuer.events4j.api.domain.IEventSubscriptionRegisters a event consumer and assigns a idvoidDispatches a eventvoidregisterEventHandler(com.github.philippheuer.events4j.api.service.IEventHandler eventHandler) Registers a EventHandlervoidsetDefaultEventHandler(Class eventHandler) Sets the default eventHandlervoidsetDefaultEventHandler(String eventHandler) Sets the default eventHandler
-
Constructor Details
-
EventManager
public EventManager()Constructor
-
-
Method Details
-
registerEventHandler
public void registerEventHandler(com.github.philippheuer.events4j.api.service.IEventHandler eventHandler) Registers a EventHandler- Specified by:
registerEventHandlerin interfacecom.github.philippheuer.events4j.api.IEventManager- Parameters:
eventHandler- IEventHandler
-
getActiveSubscriptions
public List<com.github.philippheuer.events4j.api.domain.IEventSubscription> getActiveSubscriptions()- Specified by:
getActiveSubscriptionsin interfacecom.github.philippheuer.events4j.api.IEventManager- Returns:
- returns the list of all active subscriptions
-
autoDiscovery
public void autoDiscovery()Automatic discovery of optional components -
publish
Dispatches a event- Specified by:
publishin interfacecom.github.philippheuer.events4j.api.IEventManager- Parameters:
event- A event of any kinds, should implement IEvent if possible
-
hasEventHandler
public boolean hasEventHandler(Class<? extends com.github.philippheuer.events4j.api.service.IEventHandler> eventHandlerClass) Checks if a given eventHandler is registered / present- Specified by:
hasEventHandlerin interfacecom.github.philippheuer.events4j.api.IEventManager- Parameters:
eventHandlerClass- the event handler class- Returns:
- boolean
-
getEventHandler
public <E extends com.github.philippheuer.events4j.api.service.IEventHandler> E getEventHandler(Class<E> eventHandlerClass) Retrieves a EventHandler of the provided type- Specified by:
getEventHandlerin interfacecom.github.philippheuer.events4j.api.IEventManager- Type Parameters:
E- the eventHandler type- Parameters:
eventHandlerClass- the event handler class- Returns:
- a reference to the requested event handler
-
onEvent
public <E> com.github.philippheuer.events4j.api.domain.IEventSubscription onEvent(Class<E> eventClass, Consumer<E> consumer) Registers a event consumer- Specified by:
onEventin interfacecom.github.philippheuer.events4j.api.IEventManager- Type Parameters:
E- the event type- Parameters:
eventClass- the event class to obtain events fromconsumer- the event consumer / handler method- Returns:
- a new Disposable of the given eventType
-
onEvent
public <E> com.github.philippheuer.events4j.api.domain.IEventSubscription onEvent(String id, Class<E> eventClass, Consumer<E> consumer) Registers a event consumer and assigns a idThis method will return null if the id was already used.
- Type Parameters:
E- the event type- Parameters:
id- unique id used to identify this consumereventClass- the event class to obtain events fromconsumer- the event consumer / handler method- Returns:
- a new Disposable of the given eventType
-
setDefaultEventHandler
Sets the default eventHandler- Parameters:
eventHandler- eventHandler
-
setDefaultEventHandler
Sets the default eventHandler- Parameters:
eventHandler- canonical name of the eventHandler class
-
close
public void close()Shutdown- Specified by:
closein interfaceAutoCloseable
-
getServiceMediator
public com.github.philippheuer.events4j.api.service.IServiceMediator getServiceMediator()Holds the ServiceMediator- Specified by:
getServiceMediatorin interfacecom.github.philippheuer.events4j.api.IEventManager
-
getEventHandlers
Event Handlers- Specified by:
getEventHandlersin interfacecom.github.philippheuer.events4j.api.IEventManager
-
isStopped
public boolean isStopped()is Stopped? -
getDefaultEventHandler
Default EventHandler -
getConsumerSequence
Holds the current sequence for consumer registrations -
getEventHandlerCache
public Map<String,Class<? extends com.github.philippheuer.events4j.api.service.IEventHandler>> getEventHandlerCache()EventHandler Class Cache
-