e5a6d6632a920f00a91661d83d5fb67baf57b198
[jabaws.git] / webservices / compbio / ws / server / ShutdownEngines.java
1 /* Copyright (c) 2010 Peter Troshin\r
2  *  \r
3  *  JAva Bioinformatics Analysis Web Services (JABAWS) @version: 1.0\r
4  * \r
5  *  This library is free software; you can redistribute it and/or modify it under the terms of the\r
6  *  Apache License version 2 as published by the Apache Software Foundation\r
7  * \r
8  *  This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without\r
9  *  even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the Apache \r
10  *  License for more details.\r
11  * \r
12  *  A copy of the license is in apache_license.txt. It is also available here:\r
13  * @see: http://www.apache.org/licenses/LICENSE-2.0.txt\r
14  * \r
15  * Any republication or derived work distributed in source code form\r
16  * must include this copyright and license notice.\r
17  */\r
18 package compbio.ws.server;\r
19 \r
20 import javax.servlet.ServletContextEvent;\r
21 import javax.servlet.ServletContextListener;\r
22 \r
23 import org.apache.log4j.Logger;\r
24 \r
25 import compbio.engine.local.ExecutableWrapper;\r
26 import compbio.engine.local.LocalExecutorService;\r
27 \r
28 /**\r
29  * Switch off engines if JABAWS web application is undeployed, or web server is\r
30  * shutdown\r
31  * \r
32  * @author Peter Troshin\r
33  * @version 1.0\r
34  */\r
35 public class ShutdownEngines implements ServletContextListener {\r
36 \r
37         private final Logger log = Logger.getLogger(ShutdownEngines.class);\r
38 \r
39         @Override\r
40         public void contextDestroyed(ServletContextEvent ignored) {\r
41                 // Shutdown local engine\r
42                 log.info("JABAWS context is destroyed. Shutting down engines...");\r
43                 LocalExecutorService.shutDown();\r
44                 log.info("Local engine is shutdown OK");\r
45                 ExecutableWrapper.shutdownService();\r
46                 log.info("Individual executables stream engine is shutdown OK");\r
47         }\r
48 \r
49         @Override\r
50         public void contextInitialized(ServletContextEvent arg0) {\r
51                 // Do nothing\r
52         }\r
53 \r
54 }\r