Search in sources :

Example 1 with SafeRunnable

use of org.webpieces.util.threading.SafeRunnable in project webpieces by deanhiller.

the class RouteLoader method createTHEModule.

// private XFuture<Void> setupSimpleStorage(Injector injector) {
// SimpleStorage storage = injector.getInstance(SimpleStorage.class);
// 
// List<XFuture<?>> futures = new ArrayList<>();
// List<NeedsSimpleStorage> needsStorage = config.getNeedsStorage();
// for(NeedsSimpleStorage bean : needsStorage) {
// XFuture<Void> future = bean.init(storage);
// futures.add(future);
// }
// 
// return XFuture.allOf(futures.toArray(new XFuture<?>[0]));
// }
public Module createTHEModule(WebAppMeta routerModule, RoutingHolder routingHolder) {
    List<Module> guiceModules = routerModule.getGuiceModules();
    if (guiceModules == null)
        guiceModules = new ArrayList<>();
    int corePoolSize = config.getScheduledThreadPoolSize();
    ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(corePoolSize, new ThreadFactory() {

        @Override
        public Thread newThread(Runnable r) {
            // always name the threads & prevent thread death
            Thread t = new Thread(new SafeRunnable(r), "webpieces-scheduling");
            t.setDaemon(true);
            return t;
        }
    });
    guiceModules.add(new WebpiecesToAppBindingModule(routingHolder, beanMeta, platformInjector, objectTranslator, scheduler, metrics));
    Module module = Modules.combine(guiceModules);
    List<Plugin> plugins = routerModule.getPlugins();
    if (plugins != null) {
        for (Plugin plugin : plugins) {
            List<Module> modules = new ArrayList<>();
            modules.addAll(plugin.getGuiceModules());
            modules.add(module);
            module = Modules.combine(modules);
        }
    }
    if (config.getWebappOverrides() != null)
        module = Modules.override(module).with(config.getWebappOverrides());
    return module;
}
Also used : ThreadFactory(java.util.concurrent.ThreadFactory) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) SafeRunnable(org.webpieces.util.threading.SafeRunnable) ArrayList(java.util.ArrayList) SafeRunnable(org.webpieces.util.threading.SafeRunnable) Module(com.google.inject.Module) Plugin(org.webpieces.router.api.plugins.Plugin)

Aggregations

Module (com.google.inject.Module)1 ArrayList (java.util.ArrayList)1 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)1 ThreadFactory (java.util.concurrent.ThreadFactory)1 Plugin (org.webpieces.router.api.plugins.Plugin)1 SafeRunnable (org.webpieces.util.threading.SafeRunnable)1