--- android/TrainInfoService/src/dk/thoerup/traininfoservice/StatisticsListener.java 2010/06/09 21:11:07 814 +++ android/TrainInfoService/src/dk/thoerup/traininfoservice/StatisticsListener.java 2010/09/08 08:11:00 1030 @@ -2,13 +2,17 @@ import java.util.Timer; import java.util.TimerTask; +import java.util.logging.Logger; import javax.servlet.ServletContext; import javax.servlet.ServletContextEvent; import javax.servlet.ServletContextListener; +import javax.servlet.annotation.WebListener; - +@WebListener public class StatisticsListener implements ServletContextListener { + + Logger log = Logger.getLogger(StatisticsListener.class.getName()); Timer timer = null; int update_interval; @@ -16,7 +20,19 @@ public void contextInitialized(ServletContextEvent sce) { update_interval = getUpdateInterval( sce.getServletContext() ); + + + + if (! sce.getServletContext().getRealPath("/").startsWith("/home/app/") ) { + //if path not starts with /home/app then it is not running on a production server and we only collects stats on prod servers + log.info("This is not a prod. server, dont start Statistics saver"); + return; + } + + + if ( update_interval > 0 ) { + log.info("Statistics saver started with update_interval=" + update_interval); timer = new Timer(); TimerTask statsUpdate = new TimerTask() { @@ -27,12 +43,15 @@ }; timer.schedule(statsUpdate, 0, update_interval); + } else { + log.info("Statistics saver disabled (update_interval == 0) "); } } public void contextDestroyed(ServletContextEvent sce) { - if ( update_interval > 0 ) { + log.info("StatisticsListener::contextDestroyed"); + if ( timer != null ) { timer.cancel(); Statistics.getInstance().saveStats(); }