From 41dee760bdf15e010f9ed34b54446eeec80cc2bc Mon Sep 17 00:00:00 2001 From: Massimiliano Assante Date: Thu, 13 Apr 2017 15:17:52 +0000 Subject: [PATCH] fixes the cases when the pop3 email server would not respond for a while git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/portal/social-mail-servlet@146891 82a268e6-3cf1-43bd-a215-b396298e98cf --- pom.xml | 2 +- .../gcube/portal/PortalSchedulerService.java | 31 ------------------- .../gcube/portal/socialmail/PeriodicTask.java | 15 ++++++--- 3 files changed, 11 insertions(+), 37 deletions(-) diff --git a/pom.xml b/pom.xml index b958867..f536c15 100644 --- a/pom.xml +++ b/pom.xml @@ -11,7 +11,7 @@ org.gcube.portal social-mail-servlet war - 2.1.1-SNAPSHOT + 2.2.0-SNAPSHOT social-mail-servlet Webapp This component read periodically email replies from user wanting to reply to a post via email diff --git a/src/main/java/org/gcube/portal/PortalSchedulerService.java b/src/main/java/org/gcube/portal/PortalSchedulerService.java index c29bc86..52120fc 100644 --- a/src/main/java/org/gcube/portal/PortalSchedulerService.java +++ b/src/main/java/org/gcube/portal/PortalSchedulerService.java @@ -83,38 +83,7 @@ public class PortalSchedulerService extends HttpServlet { _log.warn("Could not read popAccount data portal name", e); } _log.info("EmailParser stared for " + portalName + ", pollingInterval (in minutes)=" + pollingInterval); - - boolean keepPolling = true; - while (keepPolling) { - try { - int newPolling = getPollingInterval(); - if (newPolling <= 0) { - pop3Scheduler.shutdown(); - _log.info("EmailParser stopped for " + popAccount.getPortalName() + ", found value less than 1 in gcube-data.properties file under $CATALINA_HOME/conf"); - keepPolling = false; - } - else if (newPolling != pollingInterval) { - pollingInterval = newPolling; - pop3Scheduler.shutdown(); - _log.debug("Current thread EmailParser stopped, starting new one with different polling rate ... ->" + pollingInterval); - pop3Scheduler = Executors.newScheduledThreadPool(1); - pop3Scheduler.scheduleAtFixedRate(new PeriodicTask(store, popAccount, request), 0, pollingInterval, TimeUnit.MINUTES); - _log.debug("EmailParser restarts in " + pollingInterval + " minutes, to change this polling delay edit gcube-data.properties file under $CATALINA_HOME/conf"); - } - Thread.sleep(pollingInterval * 1000 * 60); - } catch (Exception e) { - e.printStackTrace(); - } - } - - - - toReturn = "
Check Notification Email Started ...
"; - - // Thread likesThread = new Thread(new PeriodicTask(store, popAccount, request)); - // likesThread.start(); - response.setContentType("text/html"); response.getWriter().write(toReturn); } diff --git a/src/main/java/org/gcube/portal/socialmail/PeriodicTask.java b/src/main/java/org/gcube/portal/socialmail/PeriodicTask.java index 093090a..1b48929 100644 --- a/src/main/java/org/gcube/portal/socialmail/PeriodicTask.java +++ b/src/main/java/org/gcube/portal/socialmail/PeriodicTask.java @@ -74,7 +74,7 @@ import com.sun.mail.util.MailSSLSocketFactory; public class PeriodicTask implements Runnable { private static final Log _log = LogFactoryUtil.getLog(PeriodicTask.class); private static final String APP_ID_NEWSFEED = "org.gcube.portlets.user.newsfeed.server.NewsServiceImpl"; - + private DatabookStore socialStore; private EmailPopAccount popAccount; private SocialNetworkingSite site; @@ -93,11 +93,16 @@ public class PeriodicTask implements Runnable { @Override public void run() { - _log.debug("PeriodicTask starting for portal/site having name: " + popAccount.getPortalName()); - check(popAccount.getPortalName(), popAccount.getPop3Server(), popAccount.getPop3user(), popAccount.getPop3password()); + try { + _log.debug("PeriodicTask starting for portal/site having name: " + popAccount.getPortalName()); + check(popAccount.getPortalName(), popAccount.getPop3Server(), popAccount.getPop3user(), popAccount.getPop3password()); + } catch (Exception e) { + _log.error("Exception during check email account, exiting ans stopping thread... "); + Thread.currentThread().interrupt(); + } } - - + + /** * @return a fake session usuful for Notifications */