Package civitas.celestis.event.lifecycle
Class EventThread
java.lang.Object
java.lang.Thread
civitas.celestis.event.lifecycle.EventThread
- All Implemented Interfaces:
EventManager,Module,Runnable
- Direct Known Subclasses:
SyncEventManager
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:
-
Nested Class Summary
Nested classes/interfaces inherited from class java.lang.Thread
Thread.BuilderPREVIEW, Thread.State, Thread.UncaughtExceptionHandler -
Field Summary
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY -
Constructor Summary
ConstructorsModifierConstructorDescriptionCreates a new event thread.EventThread(String name) Creates a new event thread.EventThread(String name, PrintStream printStream) Creates a new event thread.protectedEventThread(String name, Deque<Handleable> eventQueue, List<HandlerReference> handlers, PrintStream printStream) Creates a new event thread. -
Method Summary
Modifier and TypeMethodDescription<E extends Handleable>
voidcall(E event) Calls an event to this event manager, instructing it to process the event as soon as possible.voidInitializes this module.<E extends Handleable>
voidpriorityCall(E event) Calls an event to this event manager, instructing it to prioritize this event over all other events currently in the event queue.voidRegisters an event listener to this event manager.voidRegisters multiple event listeners to this event manager.voidForcefully stops this module, instructing it to interrupt all threads, and stop operating immediately regardless of its current state.voidunregister(Listener listener) Unregisters an event listener from this event manager.voidunregister(Iterable<? extends Listener> listeners) Unregisters multiple event listeners from this event manager.Methods inherited from class java.lang.Thread
activeCount, checkAccess, clone, countStackFrames, currentThread, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, isVirtual, join, join, join, join, ofPlatform, ofVirtual, onSpinWait, resume, run, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, sleep, start, startVirtualThread, stop, suspend, threadId, toString, yield
-
Constructor Details
-
EventThread
public EventThread()Creates a new event thread. -
EventThread
Creates a new event thread.- Parameters:
name- The name of this thread
-
EventThread
Creates a new event thread.- Parameters:
name- The name of this threadprintStream- 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 threadeventQueue- The event queue this thread should managehandlers- The list of handlers this thread should manageprintStream- The print stream to use to print error messages to
-
-
Method Details
-
call
Calls an event to this event manager, instructing it to process the event as soon as possible.- Specified by:
callin interfaceEventManager- Type Parameters:
E- The type of event to handle- Parameters:
event- The event of which to handle
-
priorityCall
Calls an event to this event manager, instructing it to prioritize this event over all other events currently in the event queue.- Specified by:
priorityCallin interfaceEventManager- Type Parameters:
E- The type of event to prioritize- Parameters:
event- THe event of which to prioritize
-
register
Registers an event listener to this event manager.- Specified by:
registerin interfaceEventManager- Parameters:
listener- The event listener to register to this event manager
-
register
Registers multiple event listeners to this event manager.- Specified by:
registerin interfaceEventManager- Parameters:
listeners- The iterable object containing the listeners to register
-
unregister
Unregisters an event listener from this event manager.- Specified by:
unregisterin interfaceEventManager- Parameters:
listener- The event listener to unregister from this event manager
-
unregister
Unregisters multiple event listeners from this event manager.- Specified by:
unregisterin interfaceEventManager- 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:
initializein interfaceModule
-
terminate
public void terminate()Forcefully stops this module, instructing it to interrupt all threads, and stop operating immediately regardless of its current state.
-