'Micronaut getting bean with parametrized Qualifier
I want to do something like this (I know its not semantically correct):
ctx.getBean(SendHandler.class, Qualifiers.by...(@OpCode(code=1)));
Getting a SendHandler implementation with the @OpCode qualifier.
I know that i could call Qualifiers.bySterotype(Class<? extends Annotation> stereotype), but here i cant pass the code param to the qualifier an this way could get any implementation with the @OpCode annotation.
Code for SendHandler and @OpCode and an example implementation:
public interface SendHandler {
void createMessage(WebSocket webSocket, DiscordSocketSettings socketData);
}
@Qualifier
@Retention(RUNTIME)
public @interface OpCode {
int code();
}
@Bean
@OpCode(code = 1)
public class Heartbeat implements SendHandler {
private static final Logger LOGGER = LoggerFactory.getLogger(Heartbeat.class);
@Override
public void createMessage(WebSocket webSocket, DiscordSocketSettings socketData) {
if (socketData.getMissedHeartbeatAcknowledged() > 2) {
LOGGER.warn("[{}/{}] Missed 2 heartbeats. Reconnecting!", socketData.getShardingId(), socketData.getShardingCount());
// closing the socket is enough
// reconnecting is handled in DiscordAdapter when we disconnected
//TODO: handle reconnecting in discord adapter
webSocket.sendClose(4900, "RECONNECT");
return;
}
//TODO: send actual heartbeat
//TODO: add new hearbeat ack to be awaited in socketSettings
LOGGER.debug("Discord <- [{}/{}] Sending heartbeat", socketData.getShardingId(), socketData.getShardingCount());
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
