Simplify binding cache usage
All checks were successful
zdm/event-bus/pipeline/head This commit looks good
All checks were successful
zdm/event-bus/pipeline/head This commit looks good
This commit is contained in:
parent
ee9d08b2b8
commit
8609c6a90c
@ -193,9 +193,7 @@ public final class EventBus {
|
|||||||
* @since 1.2.0
|
* @since 1.2.0
|
||||||
*/
|
*/
|
||||||
private NavigableSet<EventHandler> getHandlersFor(Class<?> eventType) {
|
private NavigableSet<EventHandler> getHandlersFor(Class<?> eventType) {
|
||||||
if (bindingCache.containsKey(eventType)) {
|
return bindingCache.computeIfAbsent(eventType, k -> {
|
||||||
return bindingCache.get(eventType);
|
|
||||||
} else {
|
|
||||||
|
|
||||||
// Get handlers defined for the event class
|
// Get handlers defined for the event class
|
||||||
TreeSet<EventHandler> handlers =
|
TreeSet<EventHandler> handlers =
|
||||||
@ -208,9 +206,8 @@ public final class EventBus {
|
|||||||
if (handler.isPolymorphic())
|
if (handler.isPolymorphic())
|
||||||
handlers.add(handler);
|
handlers.add(handler);
|
||||||
|
|
||||||
bindingCache.put(eventType, handlers);
|
|
||||||
return handlers;
|
return handlers;
|
||||||
}
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -396,13 +393,13 @@ public final class EventBus {
|
|||||||
private void bindHandler(EventHandler handler) {
|
private void bindHandler(EventHandler handler) {
|
||||||
|
|
||||||
// Bind handler
|
// Bind handler
|
||||||
bindings.putIfAbsent(handler.getEventType(), new TreeSet<>(byPriority));
|
|
||||||
logger.log(Level.DEBUG, "Binding event handler {0}", handler);
|
logger.log(Level.DEBUG, "Binding event handler {0}", handler);
|
||||||
bindings.get(handler.getEventType()).add(handler);
|
bindings.computeIfAbsent(handler.getEventType(), k -> new TreeSet<>(byPriority))
|
||||||
|
.add(handler);
|
||||||
|
|
||||||
// Insert handler into cache
|
// Insert handler into cache
|
||||||
bindingCache.putIfAbsent(handler.getEventType(), new TreeSet<>(byPriority));
|
bindingCache.computeIfAbsent(handler.getEventType(), k -> new TreeSet<>(byPriority))
|
||||||
bindingCache.get(handler.getEventType()).add(handler);
|
.add(handler);
|
||||||
|
|
||||||
// Handler is polymorphic => insert where applicable
|
// Handler is polymorphic => insert where applicable
|
||||||
if (handler.isPolymorphic())
|
if (handler.isPolymorphic())
|
||||||
|
Loading…
Reference in New Issue
Block a user