modified so that the polling interval is modifiable at runtime
git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/portal/social-mail-servlet@131055 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
6cd25ea0a9
commit
72bb81a301
|
@ -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.clientFor;
|
||||||
import static org.gcube.resources.discovery.icclient.ICFactory.queryFor;
|
import static org.gcube.resources.discovery.icclient.ICFactory.queryFor;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Properties;
|
||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.Executors;
|
||||||
import java.util.concurrent.ScheduledExecutorService;
|
import java.util.concurrent.ScheduledExecutorService;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
@ -16,12 +19,14 @@ import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
import org.gcube.common.encryption.StringEncrypter;
|
import org.gcube.common.encryption.StringEncrypter;
|
||||||
|
import org.gcube.common.portal.GCubePortalConstants;
|
||||||
import org.gcube.common.portal.PortalContext;
|
import org.gcube.common.portal.PortalContext;
|
||||||
import org.gcube.common.resources.gcore.ServiceEndpoint;
|
import org.gcube.common.resources.gcore.ServiceEndpoint;
|
||||||
import org.gcube.common.resources.gcore.ServiceEndpoint.AccessPoint;
|
import org.gcube.common.resources.gcore.ServiceEndpoint.AccessPoint;
|
||||||
import org.gcube.common.scope.api.ScopeProvider;
|
import org.gcube.common.scope.api.ScopeProvider;
|
||||||
import org.gcube.portal.databook.server.DBCassandraAstyanaxImpl;
|
import org.gcube.portal.databook.server.DBCassandraAstyanaxImpl;
|
||||||
import org.gcube.portal.databook.server.DatabookStore;
|
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.EmailPopAccount;
|
||||||
import org.gcube.portal.socialmail.PeriodicTask;
|
import org.gcube.portal.socialmail.PeriodicTask;
|
||||||
import org.gcube.resources.discovery.client.api.DiscoveryClient;
|
import org.gcube.resources.discovery.client.api.DiscoveryClient;
|
||||||
|
@ -47,7 +52,7 @@ public class PortalSchedulerService extends HttpServlet {
|
||||||
|
|
||||||
private static final String POP3_SERVER_NAME = "Pop3MailServer";
|
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;
|
private static DatabookStore store;
|
||||||
|
|
||||||
|
@ -67,13 +72,28 @@ public class PortalSchedulerService extends HttpServlet {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
ScheduledExecutorService pop3Scheduler = Executors.newScheduledThreadPool(1);
|
//ScheduledExecutorService pop3Scheduler = Executors.newScheduledThreadPool(1);
|
||||||
pop3Scheduler.scheduleAtFixedRate(new PeriodicTask(store, popAccount, request), 0, POP3_MINUTES_DELAY, TimeUnit.MINUTES);
|
|
||||||
|
|
||||||
String toReturn = "<DIV>Check Notification Email Started ... </DIV>";
|
|
||||||
|
String toReturn = "<DIV>Check Notification Email Starting ... </DIV>";
|
||||||
|
|
||||||
response.setContentType("text/html");
|
response.setContentType("text/html");
|
||||||
response.getWriter().write(toReturn);
|
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 {}
|
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {}
|
||||||
|
@ -159,6 +179,34 @@ public class PortalSchedulerService extends HttpServlet {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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")+"/");
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue