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

io.robe.guice.scanner.ManagedScanner 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.lifecycle.Managed;
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.lifecycle.Managed} and adds them to environment
 *
 */
public class ManagedScanner implements Scanner {
    private static final Logger LOGGER = LoggerFactory.getLogger(ManagedScanner.class);

    @Override
    public void scanAndAdd(Environment environment, Injector injector, Reflections reflections) {
        Set> managedClasses = reflections.getSubTypesOf(Managed.class);
        for (Class managed : managedClasses) {
            environment.lifecycle().manage(injector.getInstance(managed));
            LOGGER.info("Added managed: " + managed);
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy