Search in sources :

Example 1 with ApplicationSettings

use of com.commafeed.CommaFeedConfiguration.ApplicationSettings 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 ApplicationSettings

use of com.commafeed.CommaFeedConfiguration.ApplicationSettings in project commafeed by Athou.

the class MailService method sendMail.

public void sendMail(User user, String subject, String content) throws Exception {
    ApplicationSettings settings = config.getApplicationSettings();
    final String username = settings.getSmtpUserName();
    final String password = settings.getSmtpPassword();
    final String fromAddress = Optional.ofNullable(settings.getSmtpFromAddress()).orElse(settings.getSmtpUserName());
    String dest = user.getEmail();
    Properties props = new Properties();
    props.put("mail.smtp.auth", "true");
    props.put("mail.smtp.starttls.enable", "" + settings.isSmtpTls());
    props.put("mail.smtp.host", settings.getSmtpHost());
    props.put("mail.smtp.port", "" + settings.getSmtpPort());
    Session session = Session.getInstance(props, new Authenticator() {

        @Override
        protected PasswordAuthentication getPasswordAuthentication() {
            return new PasswordAuthentication(username, password);
        }
    });
    Message message = new MimeMessage(session);
    message.setFrom(new InternetAddress(fromAddress, "CommaFeed"));
    message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(dest));
    message.setSubject("CommaFeed - " + subject);
    message.setContent(content, "text/html; charset=utf-8");
    Transport.send(message);
}
Also used : ApplicationSettings(com.commafeed.CommaFeedConfiguration.ApplicationSettings) InternetAddress(javax.mail.internet.InternetAddress) Message(javax.mail.Message) MimeMessage(javax.mail.internet.MimeMessage) MimeMessage(javax.mail.internet.MimeMessage) Properties(java.util.Properties) Authenticator(javax.mail.Authenticator) Session(javax.mail.Session) PasswordAuthentication(javax.mail.PasswordAuthentication)

Aggregations

ApplicationSettings (com.commafeed.CommaFeedConfiguration.ApplicationSettings)2 Graphite (com.codahale.metrics.graphite.Graphite)1 GraphiteReporter (com.codahale.metrics.graphite.GraphiteReporter)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 ScheduledTask (com.commafeed.backend.task.ScheduledTask)1 FeedURLProvider (com.commafeed.backend.urlprovider.FeedURLProvider)1 InPageReferenceFeedURLProvider (com.commafeed.backend.urlprovider.InPageReferenceFeedURLProvider)1 YoutubeFeedURLProvider (com.commafeed.backend.urlprovider.YoutubeFeedURLProvider)1 InetSocketAddress (java.net.InetSocketAddress)1 Properties (java.util.Properties)1 Authenticator (javax.mail.Authenticator)1 Message (javax.mail.Message)1 PasswordAuthentication (javax.mail.PasswordAuthentication)1 Session (javax.mail.Session)1 InternetAddress (javax.mail.internet.InternetAddress)1 MimeMessage (javax.mail.internet.MimeMessage)1