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 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:
      registerEventHandler in interface com.github.philippheuer.events4j.api.IEventManager
      Parameters:
      eventHandler - IEventHandler
    • getActiveSubscriptions

      public @NonNull List<com.github.philippheuer.events4j.api.domain.IEventSubscription> getActiveSubscriptions()
      Specified by:
      getActiveSubscriptions in interface com.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(@NonNull Object event)
      Dispatches a event
      Specified by:
      publish in interface com.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:
      hasEventHandler in interface com.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:
      getEventHandler in interface com.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:
      onEvent in interface com.github.philippheuer.events4j.api.IEventManager
      Type Parameters:
      E - the event type
      Parameters:
      eventClass - the event class to obtain events from
      consumer - 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 id

      This method will return null if the id was already used.

      Type Parameters:
      E - the event type
      Parameters:
      id - unique id used to identify this consumer
      eventClass - the event class to obtain events from
      consumer - the event consumer / handler method
      Returns:
      a new Disposable of the given eventType
    • setDefaultEventHandler

      public void setDefaultEventHandler(Class eventHandler)
      Sets the default eventHandler
      Parameters:
      eventHandler - eventHandler
    • setDefaultEventHandler

      public void setDefaultEventHandler(String eventHandler)
      Sets the default eventHandler
      Parameters:
      eventHandler - canonical name of the eventHandler class
    • close

      public void close()
      Shutdown
      Specified by:
      close in interface AutoCloseable
    • getServiceMediator

      public com.github.philippheuer.events4j.api.service.IServiceMediator getServiceMediator()
      Holds the ServiceMediator
      Specified by:
      getServiceMediator in interface com.github.philippheuer.events4j.api.IEventManager
    • getEventHandlers

      public List<com.github.philippheuer.events4j.api.service.IEventHandler> getEventHandlers()
      Event Handlers
      Specified by:
      getEventHandlers in interface com.github.philippheuer.events4j.api.IEventManager
    • isStopped

      public boolean isStopped()
      is Stopped?
    • getDefaultEventHandler

      public String getDefaultEventHandler()
      Default EventHandler
    • getConsumerSequence

      public AtomicInteger 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