Search in sources :

Example 1 with Path

use of com.codecademy.eventhub.web.commands.Path in project EventHub by Codecademy.

the class Module method getEventHubHandler.

@Provides
private EventHubHandler getEventHubHandler(Injector injector, EventHub eventHub) throws ClassNotFoundException {
    Map<String, Provider<Command>> commandsMap = Maps.newHashMap();
    Reflections reflections = new Reflections(PACKAGE_NAME);
    Set<Class<? extends Command>> commandClasses = reflections.getSubTypesOf(Command.class);
    for (Class<? extends Command> commandClass : commandClasses) {
        String path = commandClass.getAnnotation(Path.class).value();
        //noinspection unchecked
        commandsMap.put(path, (Provider<Command>) injector.getProvider(commandClass));
    }
    return new EventHubHandler(eventHub, commandsMap);
}
Also used : Path(com.codecademy.eventhub.web.commands.Path) Command(com.codecademy.eventhub.web.commands.Command) Provider(javax.inject.Provider) Reflections(org.reflections.Reflections) Provides(com.google.inject.Provides)

Aggregations

Command (com.codecademy.eventhub.web.commands.Command)1 Path (com.codecademy.eventhub.web.commands.Path)1 Provides (com.google.inject.Provides)1 Provider (javax.inject.Provider)1 Reflections (org.reflections.Reflections)1