-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #99 from siglocpp/24671
Adds support for multiple @RequestHandler
- Loading branch information
Showing
10 changed files
with
327 additions
and
108 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
40 changes: 40 additions & 0 deletions
40
...re/src/main/java/de/taimos/dvalin/interconnect/core/config/MultiRequestHandlerConfig.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,40 @@ | ||
package de.taimos.dvalin.interconnect.core.config; | ||
|
||
import de.taimos.daemon.spring.conditional.OnSystemProperty; | ||
import de.taimos.dvalin.interconnect.core.spring.IDaemonMessageHandlerFactory; | ||
import de.taimos.dvalin.interconnect.core.spring.IDaemonMessageSender; | ||
import de.taimos.dvalin.interconnect.core.spring.MultiDaemonMessageHandler; | ||
import de.taimos.dvalin.interconnect.core.spring.RequestHandler; | ||
import de.taimos.dvalin.interconnect.model.service.IDaemonHandler; | ||
import org.springframework.context.ApplicationContext; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.context.annotation.Primary; | ||
|
||
import java.util.HashSet; | ||
import java.util.Set; | ||
|
||
/** | ||
* Copyright 2022 Taimos GmbH<br> | ||
* <br> | ||
* | ||
* @author psigloch | ||
*/ | ||
@Configuration | ||
@OnSystemProperty(propertyName = "interconnect.requesthandler.mode", propertyValue = "multi") | ||
public class MultiRequestHandlerConfig { | ||
|
||
@Bean | ||
@Primary | ||
public IDaemonMessageHandlerFactory createDaemonMessageHandlerFactory(ApplicationContext applicationContext, IDaemonMessageSender messageSender) { | ||
return logger -> { | ||
Set<Class<? extends IDaemonHandler>> handlers = new HashSet<>(); | ||
for (Object o : applicationContext.getBeansWithAnnotation(RequestHandler.class).values()) { | ||
if (o instanceof IDaemonHandler) { | ||
handlers.add(((IDaemonHandler) o).getClass()); | ||
} | ||
} | ||
return new MultiDaemonMessageHandler(logger, handlers, messageSender, applicationContext.getAutowireCapableBeanFactory()); | ||
}; | ||
} | ||
} |
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
90 changes: 90 additions & 0 deletions
90
...ct/core/src/main/java/de/taimos/dvalin/interconnect/core/daemon/DaemonMethodRegistry.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,90 @@ | ||
package de.taimos.dvalin.interconnect.core.daemon; | ||
|
||
import de.taimos.dvalin.interconnect.model.InterconnectObject; | ||
import de.taimos.dvalin.interconnect.model.service.DaemonScanner; | ||
import de.taimos.dvalin.interconnect.model.service.DaemonScanner.DaemonMethod; | ||
import de.taimos.dvalin.interconnect.model.service.IDaemonHandler; | ||
|
||
import java.util.Collection; | ||
import java.util.Collections; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
/** | ||
* Copyright 2022 Taimos GmbH<br> | ||
* <br> | ||
* | ||
* @author psigloch | ||
*/ | ||
public class DaemonMethodRegistry { | ||
|
||
private final Map<Class<? extends InterconnectObject>, RegistryEntry> registry; | ||
|
||
/** | ||
* @param aHandlerClazz the handler class | ||
*/ | ||
public DaemonMethodRegistry(final Class<? extends IDaemonHandler> aHandlerClazz) { | ||
final Map<Class<? extends InterconnectObject>, RegistryEntry> reg = new HashMap<>(); | ||
for (final DaemonScanner.DaemonMethod re : DaemonScanner.scan(aHandlerClazz)) { | ||
reg.put(re.getRequest(), new RegistryEntry(aHandlerClazz, re)); | ||
} | ||
this.registry = Collections.unmodifiableMap(reg); | ||
} | ||
|
||
/** | ||
* @param aHandlerClazzes all handler classes | ||
*/ | ||
public DaemonMethodRegistry(final Collection<Class<? extends IDaemonHandler>> aHandlerClazzes) { | ||
final Map<Class<? extends InterconnectObject>, RegistryEntry> reg = new HashMap<>(); | ||
for (Class<? extends IDaemonHandler> aHandlerClazz : aHandlerClazzes) { | ||
for (final DaemonScanner.DaemonMethod re : DaemonScanner.scan(aHandlerClazz)) { | ||
reg.put(re.getRequest(), new RegistryEntry(aHandlerClazz, re)); | ||
} | ||
} | ||
this.registry = Collections.unmodifiableMap(reg); | ||
} | ||
|
||
/** | ||
* @param icoClass the interconnect object class | ||
* @return the registry entry | ||
*/ | ||
public RegistryEntry get(Class<? extends InterconnectObject> icoClass) { | ||
return this.registry.get(icoClass); | ||
} | ||
|
||
/** | ||
* @param icoClass the interconnect object class | ||
* @return the daemon method | ||
*/ | ||
public DaemonMethod getMethod(Class<? extends InterconnectObject> icoClass) { | ||
RegistryEntry registryEntry = this.registry.get(icoClass); | ||
if (registryEntry == null) { | ||
return null; | ||
} | ||
return registryEntry.getMethod(); | ||
} | ||
|
||
public static class RegistryEntry { | ||
private final Class<? extends IDaemonHandler> aHandlerClazz; | ||
private final DaemonMethod method; | ||
|
||
RegistryEntry(Class<? extends IDaemonHandler> aHandlerClazz, DaemonMethod method) { | ||
this.aHandlerClazz = aHandlerClazz; | ||
this.method = method; | ||
} | ||
|
||
/** | ||
* @return the aHandlerClazz | ||
*/ | ||
public Class<? extends IDaemonHandler> getHandlerClazz() { | ||
return this.aHandlerClazz; | ||
} | ||
|
||
/** | ||
* @return the method | ||
*/ | ||
public DaemonMethod getMethod() { | ||
return this.method; | ||
} | ||
} | ||
} |
Oops, something went wrong.