Code for cleaning up old job directories
authorSasha <Main-laptop2>
Fri, 14 Jun 2013 11:49:32 +0000 (12:49 +0100)
committerSasha <Main-laptop2>
Fri, 14 Jun 2013 11:49:32 +0000 (12:49 +0100)
WEB-INF/web.xml
webservices/compbio/ws/server/ShutdownEngines.java [deleted file]

index 8c2fc89..863ae58 100644 (file)
@@ -9,7 +9,7 @@
 \r
        <!-- JABAWS listeners -->\r
        <listener>\r
-               <listener-class>compbio.ws.server.ShutdownEngines</listener-class>\r
+               <listener-class>compbio.ws.server.MainManager</listener-class>\r
        </listener>\r
        <listener>\r
                <listener-class>compbio.stat.servlet.StatisticCollector</listener-class>\r
diff --git a/webservices/compbio/ws/server/ShutdownEngines.java b/webservices/compbio/ws/server/ShutdownEngines.java
deleted file mode 100644 (file)
index c858f44..0000000
+++ /dev/null
@@ -1,128 +0,0 @@
-/* Copyright (c) 2011 Peter Troshin\r
- *  \r
- *  JAva Bioinformatics Analysis Web Services (JABAWS) @version: 2.0     \r
- * \r
- *  This library is free software; you can redistribute it and/or modify it under the terms of the\r
- *  Apache License version 2 as published by the Apache Software Foundation\r
- * \r
- *  This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without\r
- *  even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the Apache \r
- *  License for more details.\r
- * \r
- *  A copy of the license is in apache_license.txt. It is also available here:\r
- * @see: http://www.apache.org/licenses/LICENSE-2.0.txt\r
- * \r
- * Any republication or derived work distributed in source code form\r
- * must include this copyright and license notice.\r
- */\r
-package compbio.ws.server;\r
-\r
-import java.util.concurrent.Executors;\r
-import java.util.concurrent.ScheduledExecutorService;\r
-import java.util.concurrent.ScheduledFuture;\r
-import java.util.concurrent.TimeUnit;\r
-\r
-import javax.servlet.ServletContextEvent;\r
-import javax.servlet.ServletContextListener;\r
-\r
-import org.apache.log4j.Logger;\r
-\r
-import compbio.stat.collector.DirCleaner;\r
-import compbio.stat.collector.StatDB;\r
-import compbio.engine.conf.PropertyHelperManager;\r
-import compbio.engine.local.ExecutableWrapper;\r
-import compbio.engine.local.LocalExecutorService;\r
-import compbio.util.PropertyHelper;\r
-import compbio.util.Util;\r
-\r
-/**\r
- * Two tasks:\r
- * 1. Switch off engines if JABAWS web application is un-deployed, or web server is shutdown\r
- * 2. delete old job directories\r
- * \r
- * @author Peter Troshin\r
- * @author Alexander Sherstnev\r
- * @version 2.0\r
- */\r
-public class ShutdownEngines implements ServletContextListener {\r
-\r
-       private final Logger log = Logger.getLogger(ShutdownEngines.class);\r
-       static PropertyHelper ph = PropertyHelperManager.getPropertyHelper();\r
-       \r
-       private ScheduledFuture<?> localcl;\r
-       private ScheduledFuture<?> clustercl;\r
-       private ScheduledExecutorService executor;\r
-       \r
-       @Override\r
-       public void contextDestroyed(ServletContextEvent ignored) {\r
-               // stop cleaning job directories\r
-//             try {\r
-                       if (null != localcl) {\r
-                               localcl.cancel(true);\r
-                       }\r
-                       if (null != clustercl) {\r
-                               clustercl.cancel(true);\r
-                       }\r
-                       //executor.shutdown();\r
-                       //executor.awaitTermination(3, TimeUnit.SECONDS);\r
-//             } catch (InterruptedException e) {\r
-//                     log.warn(e.getMessage(), e);\r
-//             }\r
-               // Shutdown local engine\r
-               log.info("JABAWS context is destroyed. Shutting down engines...");\r
-               LocalExecutorService.shutDown();\r
-               log.info("Local engine is shutdown OK");\r
-               ExecutableWrapper.shutdownService();\r
-               log.info("Individual executables stream engine is shutdown OK");\r
-       }\r
-\r
-       @Override\r
-       public void contextInitialized(ServletContextEvent arg0) {\r
-               log.info("Initializing directory cleaners");\r
-               executor = Executors.newScheduledThreadPool(2);\r
-\r
-               // configure cluster cleaner\r
-               String clusterWorkDir = getClusterJobDir();\r
-               int clusterDirLifespan = PropertyHelperManager.getIntProperty(ph.getProperty("cluster.jobdir.maxlifespan"));\r
-               int clusterCleaningRate = PropertyHelperManager.getIntProperty(ph.getProperty("cluster.jobdir.cleaning.frequency"));\r
-               boolean cleanClasterDir = PropertyHelperManager.getBooleanProperty(ph.getProperty("cluster.stat.collector.enable"));\r
-               \r
-               if (0 < clusterDirLifespan && cleanClasterDir) {\r
-                       DirCleaner clusterDirCleaner = new DirCleaner(  clusterWorkDir, clusterDirLifespan);\r
-                       clustercl = executor.scheduleAtFixedRate(clusterDirCleaner, 1, clusterCleaningRate, TimeUnit.MINUTES);\r
-                       log.info("Cleaning local job directory every " + clusterCleaningRate + " minutes");\r
-               } else {\r
-                       log.info("Cluster job directory cleaner is disabled. ");\r
-               }\r
-\r
-               // configure local cleaner\r
-               String localWorkDir = compbio.engine.client.Util.convertToAbsolute(getLocalJobDir());\r
-               int localDirLiveSpan = PropertyHelperManager.getIntProperty(ph.getProperty("local.jobdir.maxlifespan"));\r
-               int localCleaningRate = PropertyHelperManager.getIntProperty(ph.getProperty("local.jobdir.cleaning.frequency"));\r
-               boolean cleanLocalDir = PropertyHelperManager.getBooleanProperty(ph.getProperty("local.stat.collector.enable"));\r
-\r
-               if (0 < localDirLiveSpan && cleanLocalDir) {\r
-                       DirCleaner localDirCleaner = new DirCleaner(    localWorkDir, localDirLiveSpan);\r
-                       localcl = executor.scheduleAtFixedRate(localDirCleaner, 1, localCleaningRate, TimeUnit.MINUTES);\r
-                       log.info("Cleaning local job directory every " + localCleaningRate + " minutes");\r
-               } else {\r
-                       log.info("Local job directory cleaner is disabled. ");\r
-               }\r
-       }\r
-\r
-       static String getClusterJobDir() {\r
-               String ln = ph.getProperty("cluster.tmp.directory");\r
-               if (null != ln ) {\r
-                 ln = ln.trim();\r
-               }\r
-               return ln;\r
-       }\r
-\r
-       static String getLocalJobDir() {\r
-               String ln = ph.getProperty("local.tmp.directory");\r
-               if (null != ln ) {\r
-                       ln = ln.trim();\r
-               }\r
-               return ln;\r
-       }\r
-}\r