Class EventThread

java.lang.Object
java.lang.Thread
civitas.celestis.event.lifecycle.EventThread
All Implemented Interfaces:
EventManager, Module, Runnable
Direct Known Subclasses:
SyncEventManager

public class EventThread extends Thread implements EventManager
A thread which processes events. Event threads can either have an independent queue and list of handlers, or share the resources with other threads. The sharing of event queues or handler lists can be achieved by extending this class and using the protected constructor to initialize the instance. The constructor is not public to ensure that any multithreading is properly handled by a subclass which has proper synchronization measures.
See Also:
  • Constructor Details

    • EventThread

      public EventThread()
      Creates a new event thread.
    • EventThread

      public EventThread(@Nonnull String name)
      Creates a new event thread.
      Parameters:
      name - The name of this thread
    • EventThread

      public EventThread(@Nonnull String name, @Nonnull PrintStream printStream)
      Creates a new event thread.
      Parameters:
      name - The name of this thread
      printStream - The print stream to print error messages to
    • EventThread

      protected EventThread(@Nonnull String name, @Nonnull Deque<Handleable> eventQueue, @Nonnull List<HandlerReference> handlers, @Nonnull PrintStream printStream)
      Creates a new event thread. If the event queue and/or list of handler references are shared across threads, they must be a thread-safe collection. They must also not be immutable.
      Parameters:
      name - The name of this thread
      eventQueue - The event queue this thread should manage
      handlers - The list of handlers this thread should manage
      printStream - The print stream to use to print error messages to
  • Method Details

    • call

      public <E extends Handleable> void call(@Nonnull E event)
      Calls an event to this event manager, instructing it to process the event as soon as possible.
      Specified by:
      call in interface EventManager
      Type Parameters:
      E - The type of event to handle
      Parameters:
      event - The event of which to handle
    • priorityCall

      public <E extends Handleable> void priorityCall(@Nonnull E event)
      Calls an event to this event manager, instructing it to prioritize this event over all other events currently in the event queue.
      Specified by:
      priorityCall in interface EventManager
      Type Parameters:
      E - The type of event to prioritize
      Parameters:
      event - THe event of which to prioritize
    • register

      public void register(@Nonnull Listener listener)
      Registers an event listener to this event manager.
      Specified by:
      register in interface EventManager
      Parameters:
      listener - The event listener to register to this event manager
    • register

      public void register(@Nonnull Iterable<? extends Listener> listeners)
      Registers multiple event listeners to this event manager.
      Specified by:
      register in interface EventManager
      Parameters:
      listeners - The iterable object containing the listeners to register
    • unregister

      public void unregister(@Nonnull Listener listener)
      Unregisters an event listener from this event manager.
      Specified by:
      unregister in interface EventManager
      Parameters:
      listener - The event listener to unregister from this event manager
    • unregister

      public void unregister(@Nonnull Iterable<? extends Listener> listeners)
      Unregisters multiple event listeners from this event manager.
      Specified by:
      unregister in interface EventManager
      Parameters:
      listeners - The iterable object containing the listeners to unregister
    • initialize

      public void initialize()
      Initializes this module. This is expected to be called before any other method of this module is called.
      Specified by:
      initialize in interface Module
    • terminate

      public void terminate()
      Forcefully stops this module, instructing it to interrupt all threads, and stop operating immediately regardless of its current state.
      Specified by:
      terminate in interface Module