Search in sources :

Example 1 with ScheduledTask

use of com.commafeed.backend.task.ScheduledTask in project commafeed by Athou.

the class CommaFeedModule method configure.

@Override
protected void configure() {
    CacheService cacheService = config.getApplicationSettings().getCache() == CacheType.NOOP ? new NoopCacheService() : new RedisCacheService(config.getRedisPoolFactory().build());
    log.info("using cache {}", cacheService.getClass());
    bind(CacheService.class).toInstance(cacheService);
    Multibinder<AbstractFaviconFetcher> faviconMultibinder = Multibinder.newSetBinder(binder(), AbstractFaviconFetcher.class);
    faviconMultibinder.addBinding().to(YoutubeFaviconFetcher.class);
    faviconMultibinder.addBinding().to(FacebookFaviconFetcher.class);
    faviconMultibinder.addBinding().to(DefaultFaviconFetcher.class);
    Multibinder<FeedURLProvider> urlProviderMultibinder = Multibinder.newSetBinder(binder(), FeedURLProvider.class);
    urlProviderMultibinder.addBinding().to(InPageReferenceFeedURLProvider.class);
    urlProviderMultibinder.addBinding().to(YoutubeFeedURLProvider.class);
    Multibinder<ScheduledTask> taskMultibinder = Multibinder.newSetBinder(binder(), ScheduledTask.class);
    taskMultibinder.addBinding().to(OldStatusesCleanupTask.class);
    taskMultibinder.addBinding().to(OldEntriesCleanupTask.class);
    taskMultibinder.addBinding().to(OrphanedFeedsCleanupTask.class);
    taskMultibinder.addBinding().to(OrphanedContentsCleanupTask.class);
    ApplicationSettings settings = config.getApplicationSettings();
    if (settings.isGraphiteEnabled()) {
        final String graphitePrefix = settings.getGraphitePrefix();
        final String graphiteHost = settings.getGraphiteHost();
        final int graphitePort = settings.getGraphitePort();
        final int graphiteInterval = settings.getGraphiteInterval();
        log.info("Graphite Metrics will be sent to host={}, port={}, prefix={}, interval={}sec", graphiteHost, graphitePort, graphitePrefix, graphiteInterval);
        final Graphite graphite = new Graphite(new InetSocketAddress(graphiteHost, graphitePort));
        final GraphiteReporter reporter = GraphiteReporter.forRegistry(metrics).prefixedWith(graphitePrefix).convertRatesTo(TimeUnit.SECONDS).convertDurationsTo(TimeUnit.MILLISECONDS).filter(MetricFilter.ALL).build(graphite);
        reporter.start(graphiteInterval, TimeUnit.SECONDS);
    } else {
        log.info("Graphite Metrics Disabled. Metrics will not be sent.");
    }
}
Also used : RedisCacheService(com.commafeed.backend.cache.RedisCacheService) InetSocketAddress(java.net.InetSocketAddress) GraphiteReporter(com.codahale.metrics.graphite.GraphiteReporter) AbstractFaviconFetcher(com.commafeed.backend.favicon.AbstractFaviconFetcher) ScheduledTask(com.commafeed.backend.task.ScheduledTask) NoopCacheService(com.commafeed.backend.cache.NoopCacheService) ApplicationSettings(com.commafeed.CommaFeedConfiguration.ApplicationSettings) Graphite(com.codahale.metrics.graphite.Graphite) InPageReferenceFeedURLProvider(com.commafeed.backend.urlprovider.InPageReferenceFeedURLProvider) FeedURLProvider(com.commafeed.backend.urlprovider.FeedURLProvider) YoutubeFeedURLProvider(com.commafeed.backend.urlprovider.YoutubeFeedURLProvider) RedisCacheService(com.commafeed.backend.cache.RedisCacheService) CacheService(com.commafeed.backend.cache.CacheService) NoopCacheService(com.commafeed.backend.cache.NoopCacheService)

Example 2 with ScheduledTask

use of com.commafeed.backend.task.ScheduledTask in project commafeed by Athou.

the class CommaFeedApplication method run.

@Override
public void run(CommaFeedConfiguration config, Environment environment) throws Exception {
    // guice init
    Injector injector = Guice.createInjector(new CommaFeedModule(hibernateBundle.getSessionFactory(), config, environment.metrics()));
    // session management
    environment.servlets().setSessionHandler(config.getSessionHandlerFactory().build());
    // support for "@SecurityCheck User user" injection
    environment.jersey().register(new SecurityCheckFactoryProvider.Binder(injector.getInstance(UserService.class)));
    // support for "@Context SessionHelper sessionHelper" injection
    environment.jersey().register(new SessionHelperFactoryProvider.Binder());
    // REST resources
    environment.jersey().setUrlPattern("/rest/*");
    ((DefaultServerFactory) config.getServerFactory()).setJerseyRootPath("/rest/*");
    environment.jersey().register(injector.getInstance(AdminREST.class));
    environment.jersey().register(injector.getInstance(CategoryREST.class));
    environment.jersey().register(injector.getInstance(EntryREST.class));
    environment.jersey().register(injector.getInstance(FeedREST.class));
    environment.jersey().register(injector.getInstance(PubSubHubbubCallbackREST.class));
    environment.jersey().register(injector.getInstance(ServerREST.class));
    environment.jersey().register(injector.getInstance(UserREST.class));
    // Servlets
    environment.servlets().addServlet("next", injector.getInstance(NextUnreadServlet.class)).addMapping("/next");
    environment.servlets().addServlet("logout", injector.getInstance(LogoutServlet.class)).addMapping("/logout");
    environment.servlets().addServlet("customCss", injector.getInstance(CustomCssServlet.class)).addMapping("/custom_css.css");
    environment.servlets().addServlet("analytics.js", injector.getInstance(AnalyticsServlet.class)).addMapping("/analytics.js");
    // Scheduled tasks
    Set<ScheduledTask> tasks = injector.getInstance(Key.get(new TypeLiteral<Set<ScheduledTask>>() {
    }));
    ScheduledExecutorService executor = environment.lifecycle().scheduledExecutorService("task-scheduler", true).threads(tasks.size()).build();
    for (ScheduledTask task : tasks) {
        task.register(executor);
    }
    // database init/changelogs
    environment.lifecycle().manage(injector.getInstance(StartupService.class));
    // background feed fetching
    environment.lifecycle().manage(injector.getInstance(FeedRefreshTaskGiver.class));
    environment.lifecycle().manage(injector.getInstance(FeedRefreshWorker.class));
    environment.lifecycle().manage(injector.getInstance(FeedRefreshUpdater.class));
    // cache configuration
    // prevent caching on REST resources, except for favicons
    environment.servlets().addFilter("cache-filter", new CacheBustingFilter() {

        @Override
        public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
            String path = ((HttpServletRequest) request).getRequestURI();
            if (path.contains("/feed/favicon")) {
                chain.doFilter(request, response);
            } else {
                super.doFilter(request, response, chain);
            }
        }
    }).addMappingForUrlPatterns(EnumSet.of(DispatcherType.REQUEST), false, "/rest/*");
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) ServletRequest(javax.servlet.ServletRequest) CategoryREST(com.commafeed.frontend.resource.CategoryREST) PubSubHubbubCallbackREST(com.commafeed.frontend.resource.PubSubHubbubCallbackREST) FilterChain(javax.servlet.FilterChain) UserREST(com.commafeed.frontend.resource.UserREST) ServerREST(com.commafeed.frontend.resource.ServerREST) SecurityCheckFactoryProvider(com.commafeed.frontend.auth.SecurityCheckFactoryProvider) FeedRefreshTaskGiver(com.commafeed.backend.feed.FeedRefreshTaskGiver) FeedRefreshWorker(com.commafeed.backend.feed.FeedRefreshWorker) HttpServletRequest(javax.servlet.http.HttpServletRequest) SessionHelperFactoryProvider(com.commafeed.frontend.session.SessionHelperFactoryProvider) TypeLiteral(com.google.inject.TypeLiteral) Injector(com.google.inject.Injector) ServletResponse(javax.servlet.ServletResponse) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) StartupService(com.commafeed.backend.service.StartupService) ScheduledTask(com.commafeed.backend.task.ScheduledTask) CacheBustingFilter(io.dropwizard.servlets.CacheBustingFilter) FeedREST(com.commafeed.frontend.resource.FeedREST) EntryREST(com.commafeed.frontend.resource.EntryREST) FeedRefreshUpdater(com.commafeed.backend.feed.FeedRefreshUpdater) AdminREST(com.commafeed.frontend.resource.AdminREST) DefaultServerFactory(io.dropwizard.server.DefaultServerFactory)

Aggregations

ScheduledTask (com.commafeed.backend.task.ScheduledTask)2 Graphite (com.codahale.metrics.graphite.Graphite)1 GraphiteReporter (com.codahale.metrics.graphite.GraphiteReporter)1 ApplicationSettings (com.commafeed.CommaFeedConfiguration.ApplicationSettings)1 CacheService (com.commafeed.backend.cache.CacheService)1 NoopCacheService (com.commafeed.backend.cache.NoopCacheService)1 RedisCacheService (com.commafeed.backend.cache.RedisCacheService)1 AbstractFaviconFetcher (com.commafeed.backend.favicon.AbstractFaviconFetcher)1 FeedRefreshTaskGiver (com.commafeed.backend.feed.FeedRefreshTaskGiver)1 FeedRefreshUpdater (com.commafeed.backend.feed.FeedRefreshUpdater)1 FeedRefreshWorker (com.commafeed.backend.feed.FeedRefreshWorker)1 StartupService (com.commafeed.backend.service.StartupService)1 FeedURLProvider (com.commafeed.backend.urlprovider.FeedURLProvider)1 InPageReferenceFeedURLProvider (com.commafeed.backend.urlprovider.InPageReferenceFeedURLProvider)1 YoutubeFeedURLProvider (com.commafeed.backend.urlprovider.YoutubeFeedURLProvider)1 SecurityCheckFactoryProvider (com.commafeed.frontend.auth.SecurityCheckFactoryProvider)1 AdminREST (com.commafeed.frontend.resource.AdminREST)1 CategoryREST (com.commafeed.frontend.resource.CategoryREST)1 EntryREST (com.commafeed.frontend.resource.EntryREST)1 FeedREST (com.commafeed.frontend.resource.FeedREST)1