@ -6,7 +6,6 @@ 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 ;
@ -19,14 +18,12 @@ 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 ;
@ -49,9 +46,11 @@ import com.liferay.portal.service.VirtualHostLocalServiceUtil;
public class PortalSchedulerService extends HttpServlet {
private static final Logger _log = LoggerFactory . getLogger ( PortalSchedulerService . class ) ;
private static final String POP3_POLLING_MINUTES_INTERVAL = "pop3pollinginminutes" ;
private static final String POP3_SERVER_NAME = "Pop3MailServer" ;
private static DatabookStore store ;
public void init ( ) {
@ -71,14 +70,86 @@ public class PortalSchedulerService extends HttpServlet {
}
String toReturn = "<DIV>Check Notification Email Starting ... </DIV>" ;
Thread likesThread = new Thread ( new PeriodicTask ( store , popAccount , request ) ) ;
likesThread . start ( ) ;
int pollingInterval = getPollingInterval ( ) ;
ScheduledExecutorService pop3Scheduler = Executors . newScheduledThreadPool ( 1 ) ;
pop3Scheduler . scheduleAtFixedRate ( new PeriodicTask ( store , popAccount , request ) , 0 , pollingInterval , TimeUnit . MINUTES ) ;
String portalName = "unknown" ;
try {
popAccount . getPortalName ( ) ;
}
catch ( NullPointerException e ) {
_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 = "<DIV>Check Notification Email Started ... </DIV>" ;
// Thread likesThread = new Thread(new PeriodicTask(store, popAccount, request));
// likesThread.start();
response . setContentType ( "text/html" ) ;
response . getWriter ( ) . write ( 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 = 7 ;
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" ) + "/" ) ;
}
protected void doPost ( HttpServletRequest request , HttpServletResponse response ) throws ServletException , IOException { }
/ * *
@ -162,5 +233,5 @@ public class PortalSchedulerService extends HttpServlet {
}
}