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
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidAutomatic discovery of optional componentsvoidclose()Shutdown@NonNull List<com.github.philippheuer.events4j.api.domain.IEventSubscription>Holds the current sequence for consumer registrationsDefault EventHandler<E extends com.github.philippheuer.events4j.api.service.IEventHandler>
@NonNull EgetEventHandler(@NonNull 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(@NonNull Class<? extends com.github.philippheuer.events4j.api.service.IEventHandler> eventHandlerClass) Checks if a given eventHandler is registered / presentbooleanis Stopped?<E> @NonNull com.github.philippheuer.events4j.api.domain.IEventSubscriptionRegisters a event consumer<E> @Nullable com.github.philippheuer.events4j.api.domain.IEventSubscriptionRegisters a event consumer and assigns a idvoidDispatches a eventvoidregisterEventHandler(@NonNull 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(@NonNull 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 @NonNull 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(@NonNull 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> @NonNull E getEventHandler(@NonNull 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> @NonNull com.github.philippheuer.events4j.api.domain.IEventSubscription onEvent(@NonNull Class<E> eventClass, @NonNull 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> @Nullable com.github.philippheuer.events4j.api.domain.IEventSubscription onEvent(@NonNull String id, @NonNull Class<E> eventClass, @NonNull 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
-