Class EventManager
java.lang.Object
com.github.philippheuer.events4j.core.EventManager
- All Implemented Interfaces:
com.github.philippheuer.events4j.api.IEventManager,java.lang.AutoCloseable
public class EventManager
extends java.lang.Object
implements com.github.philippheuer.events4j.api.IEventManager
The EventManager
- Since:
- 1.0
-
Constructor Summary
Constructors Constructor Description EventManager()Constructor -
Method Summary
Modifier and Type Method Description voidautoDiscovery()Automatic discovery of optional componentsvoidclose()Shutdownjava.util.List<com.github.philippheuer.events4j.api.domain.IEventSubscription>getActiveSubscriptions()java.util.concurrent.atomic.AtomicIntegergetConsumerSequence()Holds the current sequence for consumer registrationsjava.lang.StringgetDefaultEventHandler()Default EventHandler<E extends com.github.philippheuer.events4j.api.service.IEventHandler>
EgetEventHandler(java.lang.Class<E> eventHandlerClass)Retrieves a EventHandler of the provided typejava.util.Map<java.lang.String,java.lang.Class<? extends com.github.philippheuer.events4j.api.service.IEventHandler>>getEventHandlerCache()EventHandler Class Cachejava.util.List<com.github.philippheuer.events4j.api.service.IEventHandler>getEventHandlers()Event Handlerscom.github.philippheuer.events4j.api.service.IServiceMediatorgetServiceMediator()Holds the ServiceMediatorbooleanhasEventHandler(java.lang.Class<? extends com.github.philippheuer.events4j.api.service.IEventHandler> eventHandlerClass)Checks if a given eventHandler is registered / presentbooleanisStopped()is Stopped?<E> com.github.philippheuer.events4j.api.domain.IEventSubscriptiononEvent(java.lang.Class<E> eventClass, java.util.function.Consumer<E> consumer)Registers a event consumer<E> com.github.philippheuer.events4j.api.domain.IEventSubscriptiononEvent(java.lang.String id, java.lang.Class<E> eventClass, java.util.function.Consumer<E> consumer)Registers a event consumer and assigns a idvoidpublish(java.lang.Object event)Dispatches a eventvoidregisterEventHandler(com.github.philippheuer.events4j.api.service.IEventHandler eventHandler)Registers a EventHandlervoidsetDefaultEventHandler(java.lang.Class eventHandler)Sets the default eventHandlervoidsetDefaultEventHandler(java.lang.String eventHandler)Sets the default eventHandlerMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
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 java.util.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
public void publish(java.lang.Object event)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(java.lang.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(java.lang.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(java.lang.Class<E> eventClass, java.util.function.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(java.lang.String id, java.lang.Class<E> eventClass, java.util.function.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
public void setDefaultEventHandler(java.lang.Class eventHandler)Sets the default eventHandler- Parameters:
eventHandler- eventHandler
-
setDefaultEventHandler
public void setDefaultEventHandler(java.lang.String eventHandler)Sets the default eventHandler- Parameters:
eventHandler- canonical name of the eventHandler class
-
close
public void close()Shutdown- Specified by:
closein interfacejava.lang.AutoCloseable
-
getServiceMediator
public com.github.philippheuer.events4j.api.service.IServiceMediator getServiceMediator()Holds the ServiceMediator- Specified by:
getServiceMediatorin interfacecom.github.philippheuer.events4j.api.IEventManager
-
getEventHandlers
public java.util.List<com.github.philippheuer.events4j.api.service.IEventHandler> getEventHandlers()Event Handlers- Specified by:
getEventHandlersin interfacecom.github.philippheuer.events4j.api.IEventManager
-
isStopped
public boolean isStopped()is Stopped? -
getDefaultEventHandler
public java.lang.String getDefaultEventHandler()Default EventHandler -
getConsumerSequence
public java.util.concurrent.atomic.AtomicInteger getConsumerSequence()Holds the current sequence for consumer registrations -
getEventHandlerCache
public java.util.Map<java.lang.String,java.lang.Class<? extends com.github.philippheuer.events4j.api.service.IEventHandler>> getEventHandlerCache()EventHandler Class Cache
-