All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.robe.guice.scanner.TaskScanner Maven / Gradle / Ivy

There is a newer version: 0.5.0.0-1039
Show newest version
package io.robe.guice.scanner;

import com.google.inject.Injector;
import io.dropwizard.servlets.tasks.Task;
import io.dropwizard.setup.Environment;
import org.reflections.Reflections;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Set;

/**
 * Collects all classes extended {@link io.dropwizard.servlets.tasks.Task} and adds them to admin servlet
 */
public class TaskScanner  implements Scanner{
    private static final Logger LOGGER = LoggerFactory.getLogger(TaskScanner.class);

    @Override
    public void scanAndAdd(Environment environment, Injector injector, Reflections reflections) {
        Set> taskClasses = reflections.getSubTypesOf(Task.class);
        for (Class task : taskClasses) {
            environment.admin().addTask(injector.getInstance(task));
            LOGGER.info("Added task: " + task);
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy