diff --git a/pom.xml b/pom.xml index 1d99474..4078117 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ dev.kske event-bus - 0.0.1 + 0.0.2 Event Bus An event handling framework for Java utilizing annotations. diff --git a/src/main/java/dev/kske/eventbus/EventBus.java b/src/main/java/dev/kske/eventbus/EventBus.java index ca14bc7..f4f54f5 100644 --- a/src/main/java/dev/kske/eventbus/EventBus.java +++ b/src/main/java/dev/kske/eventbus/EventBus.java @@ -6,6 +6,9 @@ import java.util.concurrent.ConcurrentHashMap; /** * Event listeners can be registered at an event bus to be notified when an event is dispatched. *

+ * A singleton instance of this class can be lazily created and acquired using the + * {@link EventBus#getInstance()} method. + *

* This is a thread-safe implementation. * * @author Kai S. K. Engelbart @@ -14,6 +17,20 @@ import java.util.concurrent.ConcurrentHashMap; */ public final class EventBus { + private static EventBus singletonInstance; + + /** + * Produces a singleton instance of the event bus. It is lazily initialized on the first call. + * + * @return a singleton instance of the event bus. + * @since 0.0.2 + */ + public static EventBus getInstance() { + if (singletonInstance == null) + singletonInstance = new EventBus(); + return singletonInstance; + } + private final Map, Collection> bindings = new ConcurrentHashMap<>(); private final Set registeredListeners = ConcurrentHashMap.newKeySet();