Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Clean up notifications code a little bit
Preparing for MID-5849 and MID-5350 resolution.
- Loading branch information
Showing
39 changed files
with
1,268 additions
and
1,445 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
...ons-impl/src/main/java/com/evolveum/midpoint/notifications/impl/EventHandlerRegistry.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
* Copyright (c) 2020 Evolveum and contributors | ||
* | ||
* This work is dual-licensed under the Apache License 2.0 | ||
* and European Union Public License. See LICENSE file for details. | ||
*/ | ||
|
||
package com.evolveum.midpoint.notifications.impl; | ||
|
||
import java.util.Map; | ||
import java.util.concurrent.ConcurrentHashMap; | ||
|
||
import org.springframework.stereotype.Component; | ||
|
||
import com.evolveum.midpoint.notifications.api.EventHandler; | ||
import com.evolveum.midpoint.notifications.api.events.Event; | ||
import com.evolveum.midpoint.schema.result.OperationResult; | ||
import com.evolveum.midpoint.task.api.Task; | ||
import com.evolveum.midpoint.util.exception.SchemaException; | ||
import com.evolveum.midpoint.util.logging.Trace; | ||
import com.evolveum.midpoint.util.logging.TraceManager; | ||
import com.evolveum.midpoint.xml.ns._public.common.common_3.EventHandlerType; | ||
|
||
/** | ||
* | ||
*/ | ||
@Component | ||
public class EventHandlerRegistry { | ||
|
||
private static final Trace LOGGER = TraceManager.getTrace(EventHandlerRegistry.class); | ||
|
||
private Map<Class<? extends EventHandlerType>, EventHandler<?, ?>> handlers = new ConcurrentHashMap<>(); | ||
|
||
public <C extends EventHandlerType, E extends Event> void registerEventHandler(Class<C> configType, EventHandler<E, C> handler) { | ||
LOGGER.trace("Registering event handler {} for config type {}", handler, configType); | ||
handlers.put(configType, handler); | ||
} | ||
|
||
public boolean forwardToHandler(Event event, EventHandlerType configuration, Task task, OperationResult result) throws SchemaException { | ||
EventHandler<?, ?> handler = handlers.get(configuration.getClass()); | ||
if (handler == null) { | ||
throw new IllegalStateException("Unknown handler for " + configuration); | ||
} else if (!handler.getEventType().isAssignableFrom(event.getClass())) { | ||
LOGGER.trace("Not forwarding event {} to handler {} because the handler does not support events of that type", | ||
event, handler); | ||
return true; | ||
} else { | ||
//noinspection unchecked,rawtypes | ||
return ((EventHandler) handler).processEvent(event, configuration, task, result); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.