Source Code Cross Referenced for TomcatDeployer.java in  » Net » Coadunation_1.0.1 » com » rift » coad » daemon » tomcat » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Net » Coadunation_1.0.1 » com.rift.coad.daemon.tomcat 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Tomcat: The deployer for the tomcat daemon
003:         * Copyright (C) 2007  Rift IT Contracting
004:         *
005:         * This library is free software; you can redistribute it and/or
006:         * modify it under the terms of the GNU Lesser General Public
007:         * License as published by the Free Software Foundation; either
008:         * version 2.1 of the License, or (at your option) any later version.
009:         *
010:         * This library is distributed in the hope that it will be useful,
011:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
012:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
013:         * Lesser General Public License for more details.
014:         *
015:         * You should have received a copy of the GNU Lesser General Public
016:         * License along with this library; if not, write to the Free Software
017:         * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
018:         *
019:         * Tomcat.java
020:         */
021:
022:        // package path
023:        package com.rift.coad.daemon.tomcat;
024:
025:        // java imports
026:        import java.io.File;
027:        import java.util.Arrays;
028:        import java.util.Map;
029:        import java.util.HashMap;
030:        import java.util.Iterator;
031:        import java.util.Vector;
032:        import com.rift.coad.daemon.tomcat.TomcatWrapper;
033:
034:        // logging import
035:        import org.apache.log4j.Logger;
036:
037:        // coadunation imports
038:        import com.rift.coad.lib.common.FileUtil;
039:        import com.rift.coad.lib.thread.BasicThread;
040:        import com.rift.coad.lib.thread.ThreadStateMonitor;
041:        import com.rift.coad.lib.configuration.ConfigurationFactory;
042:        import com.rift.coad.lib.configuration.Configuration;
043:
044:        /**
045:         * This class is responsible for deploying the tomcat daemon instance.
046:         *
047:         * @author Brett Chaldecott
048:         */
049:        public class TomcatDeployer extends BasicThread {
050:
051:            /**
052:             * This object contains  the deployment information for a given entry.
053:             */
054:            public class DeployEntry {
055:                // private member variables
056:                private String path = null;
057:                private File file = null;
058:                private long lastModified = 0;
059:
060:                /**
061:                 * The constructor of the deploy entry.
062:                 *
063:                 * @param file The reference to the file object.
064:                 */
065:                public DeployEntry(File file) {
066:                    path = file.getPath();
067:                    this .file = file;
068:                    lastModified = file.lastModified();
069:                }
070:
071:                /**
072:                 * The reference to the path entries.
073:                 *
074:                 * @return The reference to the path value.
075:                 */
076:                public String getPath() {
077:                    return path;
078:                }
079:
080:                /**
081:                 * This method returns a reference to h
082:                 */
083:                public File getFile() {
084:                    return file;
085:                }
086:
087:                /**
088:                 * This method returns the last modified date.
089:                 *
090:                 * @return The long containing the last modified date.
091:                 */
092:                public long getLastModified() {
093:                    return lastModified;
094:                }
095:            }
096:
097:            // the logger reference
098:            protected Logger log = Logger.getLogger(TomcatDeployer.class
099:                    .getName());
100:
101:            // private member variables
102:            private ThreadStateMonitor state = null;
103:            private TomcatWrapper tomcatWrapper = null;
104:            private Map deployedEntries = new HashMap();
105:            private File deploymentDir = null;
106:
107:            /**
108:             * Creates a new instance of TomcatDeployer
109:             */
110:            public TomcatDeployer() throws Exception {
111:                try {
112:                    Configuration configuration = ConfigurationFactory
113:                            .getInstance().getConfig(this .getClass());
114:                    state = new ThreadStateMonitor(configuration.getLong(
115:                            "DeployCheckInterval", 1000));
116:                    Configuration deployConfig = ConfigurationFactory
117:                            .getInstance()
118:                            .getConfig(
119:                                    com.rift.coad.lib.deployment.DeploymentManager.class);
120:                    deploymentDir = new File(deployConfig
121:                            .getString("directory"));
122:                    tomcatWrapper = new TomcatWrapper();
123:
124:                } catch (Exception ex) {
125:                    log.error(
126:                            "Failed to initialize the configuration because : "
127:                                    + ex.getMessage(), ex);
128:                    throw new TomcatException(
129:                            "Failed to initialize the configuration because : "
130:                                    + ex.getMessage(), ex);
131:                }
132:            }
133:
134:            /**
135:             * This method will be called to perform the processing. This method
136:             * replaces the traditional run method.
137:             */
138:            public void process() throws Exception {
139:                log.info("The processor is running");
140:                while (!state.isTerminated()) {
141:                    // retrieve a list of files
142:                    File[] files = FileUtil.filter(deploymentDir.listFiles(),
143:                            ".war");
144:                    Arrays.sort(files);
145:
146:                    // loop through the existing entry
147:                    Vector oldEntries = new Vector();
148:                    for (Iterator iter = deployedEntries.keySet().iterator(); iter
149:                            .hasNext();) {
150:                        DeployEntry entry = (DeployEntry) deployedEntries
151:                                .get(iter.next());
152:                        boolean found = false;
153:                        for (int index = 0; index < files.length; index++) {
154:                            if (files[index].getPath().equals(entry.getPath())) {
155:                                if (files[index].lastModified() == entry
156:                                        .getLastModified()) {
157:                                    found = true;
158:                                }
159:                                break;
160:                            }
161:                        }
162:                        if (!found) {
163:                            oldEntries.add(entry.getPath());
164:                            tomcatWrapper.unloadWar(entry.getFile());
165:                        }
166:                    }
167:                    for (Iterator iter = oldEntries.iterator(); iter.hasNext();) {
168:                        deployedEntries.remove(iter.next());
169:                    }
170:
171:                    // attempt to load
172:                    for (int index = 0; index < files.length; index++) {
173:                        if (!deployedEntries
174:                                .containsKey(files[index].getPath())) {
175:                            deployedEntries.put(files[index].getPath(),
176:                                    new DeployEntry(files[index]));
177:                            tomcatWrapper.loadWar(files[index]);
178:                        }
179:                    }
180:
181:                    // check the state
182:                    state.monitor();
183:                }
184:
185:                log.info("Stopping the engine");
186:                try {
187:                    tomcatWrapper.stop();
188:                } catch (Exception ex) {
189:                    log.error("Failed to stop the tomcat instance : "
190:                            + ex.getMessage(), ex);
191:                }
192:
193:            }
194:
195:            /**
196:             * This method is called to soft terminate the processing thread.
197:             */
198:            public void terminate() {
199:                state.terminate(true);
200:                try {
201:                    this .join();
202:                } catch (Exception ex) {
203:                    log.error("Failed to wait for tomcat :" + ex.getMessage(),
204:                            ex);
205:                }
206:                log.info("Finished waiting for tomcat to shut down.");
207:            }
208:
209:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.