Compare commits
No commits in common. "40d48cb9592780844402eb1b94f809d4cd6cbd5a" and "866a5471140586047d965df092d0ce64d7c89ecb" have entirely different histories.
40d48cb959
...
866a547114
@ -66,27 +66,10 @@ public final class EventBus {
|
|||||||
return singletonInstance;
|
return singletonInstance;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
private final Map<Class<?>, TreeSet<EventHandler>> bindings =
|
||||||
* Event handler bindings (target class to handlers registered for that class), does not contain
|
new ConcurrentHashMap<>();
|
||||||
* other (polymorphic) handlers.
|
private final Set<Object> registeredListeners =
|
||||||
*
|
ConcurrentHashMap.newKeySet();
|
||||||
* @since 0.0.1
|
|
||||||
*/
|
|
||||||
private final Map<Class<?>, TreeSet<EventHandler>> bindings = new ConcurrentHashMap<>();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Stores all registered event listeners (which declare event handlers) and prevents them from
|
|
||||||
* being garbage collected.
|
|
||||||
*
|
|
||||||
* @since 0.0.1
|
|
||||||
*/
|
|
||||||
private final Set<Object> registeredListeners = ConcurrentHashMap.newKeySet();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The current event dispatching state, local to each thread.
|
|
||||||
*
|
|
||||||
* @since 0.1.0
|
|
||||||
*/
|
|
||||||
private final ThreadLocal<DispatchState> dispatchState =
|
private final ThreadLocal<DispatchState> dispatchState =
|
||||||
ThreadLocal.withInitial(DispatchState::new);
|
ThreadLocal.withInitial(DispatchState::new);
|
||||||
|
|
||||||
@ -96,7 +79,6 @@ public final class EventBus {
|
|||||||
*
|
*
|
||||||
* @param event the event to dispatch
|
* @param event the event to dispatch
|
||||||
* @throws EventBusException if an event handler isn't accessible or has an invalid signature
|
* @throws EventBusException if an event handler isn't accessible or has an invalid signature
|
||||||
* @throws NullPointerException if the specified event is {@code null}
|
|
||||||
* @since 0.0.1
|
* @since 0.0.1
|
||||||
*/
|
*/
|
||||||
public void dispatch(Object event) throws EventBusException {
|
public void dispatch(Object event) throws EventBusException {
|
||||||
@ -191,9 +173,8 @@ public final class EventBus {
|
|||||||
* Registers an event listener at this event bus.
|
* Registers an event listener at this event bus.
|
||||||
*
|
*
|
||||||
* @param listener the listener to register
|
* @param listener the listener to register
|
||||||
* @throws EventBusException if the listener is already registered or a declared event
|
* @throws EventBusException if the listener is already registered or a declared event handler
|
||||||
* handler does not comply with the specification
|
* does not comply with the specification
|
||||||
* @throws NullPointerException if the specified listener is {@code null}
|
|
||||||
* @since 0.0.1
|
* @since 0.0.1
|
||||||
* @see Event
|
* @see Event
|
||||||
*/
|
*/
|
||||||
@ -248,7 +229,6 @@ public final class EventBus {
|
|||||||
Objects.requireNonNull(listener);
|
Objects.requireNonNull(listener);
|
||||||
logger.log(Level.INFO, "Removing event listener {0}", listener.getClass().getName());
|
logger.log(Level.INFO, "Removing event listener {0}", listener.getClass().getName());
|
||||||
|
|
||||||
// Remove bindings from binding map
|
|
||||||
for (var binding : bindings.values()) {
|
for (var binding : bindings.values()) {
|
||||||
var it = binding.iterator();
|
var it = binding.iterator();
|
||||||
while (it.hasNext()) {
|
while (it.hasNext()) {
|
||||||
@ -259,8 +239,6 @@ public final class EventBus {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove the listener itself
|
|
||||||
registeredListeners.remove(listener);
|
registeredListeners.remove(listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,18 +1,14 @@
|
|||||||
package dev.kske.eventbus.core;
|
package dev.kske.eventbus.core;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This unchecked exception is specific to the event bus and can be thrown under the following
|
* This runtime exception is thrown when an event bus error occurs. This can
|
||||||
* circumstances:
|
* either occur while registering event listeners with invalid handlers, or when
|
||||||
* <ul>
|
* an event handler throws an exception.
|
||||||
* <li>An event handler throws an exception (which is stored as the cause)</li>
|
|
||||||
* <li>An event listener with an invalid event handler is registered</li>
|
|
||||||
* <li>{@link EventBus#cancel()} is invoked from outside an active dispatch thread</li>
|
|
||||||
* </ul>
|
|
||||||
*
|
*
|
||||||
* @author Kai S. K. Engelbart
|
* @author Kai S. K. Engelbart
|
||||||
* @since 0.0.1
|
* @since 0.0.1
|
||||||
*/
|
*/
|
||||||
public final class EventBusException extends RuntimeException {
|
public class EventBusException extends RuntimeException {
|
||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
2
pom.xml
2
pom.xml
@ -9,7 +9,7 @@
|
|||||||
<packaging>pom</packaging>
|
<packaging>pom</packaging>
|
||||||
|
|
||||||
<name>Event Bus</name>
|
<name>Event Bus</name>
|
||||||
<description>An event handling library for Java utilizing annotations.</description>
|
<description>An event handling framework for Java utilizing annotations.</description>
|
||||||
<url>https://git.kske.dev/kske/event-bus</url>
|
<url>https://git.kske.dev/kske/event-bus</url>
|
||||||
|
|
||||||
<modules>
|
<modules>
|
||||||
|
Loading…
Reference in New Issue
Block a user