Created
December 11, 2021 05:15
-
-
Save asvignesh/f92e6f0df7fb0881fe2e16ec43f6aff5 to your computer and use it in GitHub Desktop.
Factory
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
@Component | |
@Slf4j | |
public class AwsRequestHandlerDi { | |
private static final Map<ApplicationCommands, INimesaAwsJob> myServiceCache = new HashMap<>(); | |
private final List<INimesaAwsJob> handlers; | |
@Autowired | |
private AwsRequestHandlerDi(List<INimesaAwsJob> handlers) { | |
this.handlers = handlers; | |
} | |
public static INimesaAwsJob getService(String command) { | |
ApplicationCommands applicationCommands = ApplicationCommands | |
.valueOf(command); | |
INimesaAwsJob service = myServiceCache.get(applicationCommands); | |
if (null == service) { | |
throw new RuntimeException("Unknown service type: " + applicationCommands); | |
} | |
return service; | |
} | |
@PostConstruct | |
public void initMyServiceCache() { | |
for (INimesaAwsJob service : handlers) { | |
RequestHandler annotation = service.getClass().getAnnotation(RequestHandler.class); | |
ApplicationCommands[] commands = annotation.command(); | |
for (ApplicationCommands command : commands) { | |
myServiceCache.put(command, service); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment