Skip to content

io microsphere event DirectEventDispatcher

github-actions[bot] edited this page Mar 24, 2026 · 3 revisions

DirectEventDispatcher

Type: Class | Module: microsphere-java-core | Package: io.microsphere.event | Since: 1.0.0

Source: microsphere-java-core/src/main/java/io/microsphere/event/DirectEventDispatcher.java

Overview

A concrete implementation of AbstractEventDispatcher that uses a direct (synchronous) execution model.

This class dispatches events directly on the calling thread, ensuring sequential execution of listeners. It is suitable for simple use cases where asynchronous or parallel processing is not required.

Key Features

- **Synchronous Dispatching:** Events are processed immediately on the thread that calls `#dispatch(Event)`.
- **Ordered Listener Execution:** Listeners are executed in the order determined by their priority (via the `Prioritized` interface).
- **Thread-Safe Registration:** Listener registration and removal operations are thread-safe.

Example Usage

`// Create an instance of DirectEventDispatcher
DirectEventDispatcher dispatcher = new DirectEventDispatcher();

// Register a listener
dispatcher.addEventListener((EventListener) event -> System.out.println("Event handled!"));

// Dispatch an event
dispatcher.dispatch(new MyEvent());
`

Execution Model

All event listeners are executed sequentially on the same thread that invokes the #dispatch(Event) method. This ensures predictable execution order but may impact performance if any listener performs long-running operations.

Declaration

public final class DirectEventDispatcher extends AbstractEventDispatcher

Author: Mercy

Version Information

  • Introduced in: 1.0.0
  • Current Project Version: 0.2.2-SNAPSHOT

Version Compatibility

This component is tested and compatible with the following Java versions:

Java Version Status
Java 8 ✅ Compatible
Java 11 ✅ Compatible
Java 17 ✅ Compatible
Java 21 ✅ Compatible
Java 25 ✅ Compatible

Examples

// Create an instance of DirectEventDispatcher
DirectEventDispatcher dispatcher = new DirectEventDispatcher();

// Register a listener
dispatcher.addEventListener((EventListener<MyEvent>) event -> System.out.println("Event handled!"));

// Dispatch an event
dispatcher.dispatch(new MyEvent());

Usage

Maven Dependency

Add the following dependency to your pom.xml:

<dependency>
    <groupId>io.github.microsphere-projects</groupId>
    <artifactId>microsphere-java-core</artifactId>
    <version>${microsphere-java.version}</version>
</dependency>

Tip: Use the BOM (microsphere-java-dependencies) for consistent version management. See the Getting Started guide.

Import

import io.microsphere.event.DirectEventDispatcher;

See Also

  • AbstractEventDispatcher
  • EventDispatcher
  • EventListener
  • Prioritized

This documentation was auto-generated from the source code of microsphere-java.

Home

annotation-processor

java-annotations

java-core

java-test

jdk-tools

lang-model

Clone this wiki locally