miércoles, 27 de diciembre de 2017

Guice small code receipt and Spark framework

La clase que utiliza el injector
System.setProperty("user","santi");

Injector injector = Guice.createInjector(new GuiceMod());
ConfigurationService config = injector.getInstance(Key.get(ConfigurationService.class, Names.named("config")));
System.out.println(config.getKey("user"));


threadPool(250,15,30000);


Random random= new Random();
long rand = random.nextLong();

System.out.println("Shutdown code: "+rand);
get("/sample",(req,res)-> {
            return "Hello World!!!";
        });

        get("/sd_"+rand,(request, response) -> {
            stop();
            return "";
        });
El modulo

/**
 * Created by santiago on 12/26/17.
 */
public class GuiceMod extends AbstractModule{


    @Override
    protected void configure() {

    }

    @Provides
    @Singleton
    @Named("config")
    public ConfigurationService getConfig(){
        return new ConfigurationImpl();
    }

}