diff --git a/src/main/java/org/gcube/portal/PortalSchedulerService.java b/src/main/java/org/gcube/portal/PortalSchedulerService.java
index a5c09e2..560c905 100644
--- a/src/main/java/org/gcube/portal/PortalSchedulerService.java
+++ b/src/main/java/org/gcube/portal/PortalSchedulerService.java
@@ -3,9 +3,12 @@ package org.gcube.portal;
import static org.gcube.resources.discovery.icclient.ICFactory.clientFor;
import static org.gcube.resources.discovery.icclient.ICFactory.queryFor;
+import java.io.File;
+import java.io.FileInputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
+import java.util.Properties;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
@@ -16,12 +19,14 @@ import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.gcube.common.encryption.StringEncrypter;
+import org.gcube.common.portal.GCubePortalConstants;
import org.gcube.common.portal.PortalContext;
import org.gcube.common.resources.gcore.ServiceEndpoint;
import org.gcube.common.resources.gcore.ServiceEndpoint.AccessPoint;
import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.portal.databook.server.DBCassandraAstyanaxImpl;
import org.gcube.portal.databook.server.DatabookStore;
+import org.gcube.portal.notifications.thread.LikeNotificationsThread;
import org.gcube.portal.socialmail.EmailPopAccount;
import org.gcube.portal.socialmail.PeriodicTask;
import org.gcube.resources.discovery.client.api.DiscoveryClient;
@@ -47,14 +52,14 @@ public class PortalSchedulerService extends HttpServlet {
private static final String POP3_SERVER_NAME = "Pop3MailServer";
- private static final int POP3_MINUTES_DELAY = 1;
+ private static final String POP3_POLLING_MINUTES_INTERVAL = "pop3pollinginminutes";
private static DatabookStore store;
public void init() {
store = new DBCassandraAstyanaxImpl();
}
-
+
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
@@ -67,17 +72,32 @@ public class PortalSchedulerService extends HttpServlet {
e.printStackTrace();
}
- ScheduledExecutorService pop3Scheduler = Executors.newScheduledThreadPool(1);
- pop3Scheduler.scheduleAtFixedRate(new PeriodicTask(store, popAccount, request), 0, POP3_MINUTES_DELAY, TimeUnit.MINUTES);
+ //ScheduledExecutorService pop3Scheduler = Executors.newScheduledThreadPool(1);
- String toReturn = "
Check Notification Email Started ...
";
+
+ String toReturn = "Check Notification Email Starting ...
";
response.setContentType("text/html");
response.getWriter().write(toReturn);
+
+ //pop3Scheduler.scheduleAtFixedRate(new PeriodicTask(store, popAccount, request), 0, POP3_MINUTES_DELAY, TimeUnit.MINUTES);
+ while (true) {
+ Thread likesThread = new Thread(new PeriodicTask(store, popAccount, request));
+ likesThread.start();
+ try {
+ int pollingInterval = getPollingInterval();
+ _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 (InterruptedException e) {
+ e.printStackTrace();
+ }
+ }
+
+
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {}
-
+
/**
*
* @param request
@@ -105,7 +125,7 @@ public class PortalSchedulerService extends HttpServlet {
}
private EmailPopAccount getPopAccountData(Group site) throws GroupRetrievalFault {
-
+
_log.debug("Found site for vhost, name " + site.getName() + " reading custom field: " + CustomAttributeKeys.GATEWAY_SITE_NAME);
String gatewayName = (String) new LiferayGroupManager().readCustomAttr(site.getGroupId(), CustomAttributeKeys.GATEWAY_SITE_NAME.getKeyName());
@@ -158,7 +178,35 @@ public class PortalSchedulerService extends HttpServlet {
return toReturn;
}
-
+ /**
+ * read the time interval in minutes from a property file and returns it
+ */
+ public int getPollingInterval() {
+ //get the portles to look for from the property file
+ Properties props = new Properties();
+ int toReturn = 3;
+ try {
+ String propertyfile = getCatalinaHome() + File.separator + "conf" + File.separator + "gcube-data.properties";
+ File propsFile = new File(propertyfile);
+ FileInputStream fis = new FileInputStream(propsFile);
+ props.load(fis);
+ toReturn = Integer.parseInt(props.getProperty(POP3_POLLING_MINUTES_INTERVAL));
+ }
+ //catch exception in case properties file does not exist
+ catch(IOException e) {
+ _log.error("gcube-data.properties file not found under $CATALINA_HOME/conf dir, returning default interval in minutes = " + toReturn);
+ return toReturn;
+ }
+ _log.debug("Returning poling interval in minutes: " + toReturn );
+ return toReturn;
+ }
+ /**
+ *
+ * @return $CATALINA_HOME
+ */
+ private static String getCatalinaHome() {
+ return (System.getenv("CATALINA_HOME").endsWith("/") ? System.getenv("CATALINA_HOME") : System.getenv("CATALINA_HOME")+"/");
+ }
}
\ No newline at end of file