Source Code Cross Referenced for AprLifecycleListener.java in  » Sevlet-Container » apache-tomcat-6.0.14 » org » apache » catalina » core » 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 » Sevlet Container » apache tomcat 6.0.14 » org.apache.catalina.core 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Licensed to the Apache Software Foundation (ASF) under one or more
003:         * contributor license agreements.  See the NOTICE file distributed with
004:         * this work for additional information regarding copyright ownership.
005:         * The ASF licenses this file to You under the Apache License, Version 2.0
006:         * (the "License"); you may not use this file except in compliance with
007:         * the License.  You may obtain a copy of the License at
008:         *
009:         *      http://www.apache.org/licenses/LICENSE-2.0
010:         *
011:         * Unless required by applicable law or agreed to in writing, software
012:         * distributed under the License is distributed on an "AS IS" BASIS,
013:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         * See the License for the specific language governing permissions and
015:         * limitations under the License.
016:         */
017:
018:        package org.apache.catalina.core;
019:
020:        import java.lang.reflect.InvocationTargetException;
021:        import java.lang.reflect.Method;
022:
023:        import org.apache.catalina.Lifecycle;
024:        import org.apache.catalina.LifecycleEvent;
025:        import org.apache.catalina.LifecycleListener;
026:        import org.apache.catalina.util.StringManager;
027:        import org.apache.juli.logging.Log;
028:        import org.apache.juli.logging.LogFactory;
029:        import org.apache.tomcat.jni.Library;
030:
031:        /**
032:         * Implementation of <code>LifecycleListener</code> that will init and
033:         * and destroy APR.
034:         *
035:         * @author Remy Maucherat
036:         * @author Filip Hanik
037:         * @version $Revision: 534930 $ $Date: 2007-05-03 18:43:35 +0200 (jeu., 03 mai 2007) $
038:         * @since 4.1
039:         */
040:
041:        public class AprLifecycleListener implements  LifecycleListener {
042:
043:            private static Log log = LogFactory
044:                    .getLog(AprLifecycleListener.class);
045:
046:            /**
047:             * The string manager for this package.
048:             */
049:            protected StringManager sm = StringManager
050:                    .getManager(Constants.Package);
051:
052:            // ---------------------------------------------- Constants
053:
054:            protected static final int TCN_REQUIRED_MAJOR = 1;
055:            protected static final int TCN_REQUIRED_MINOR = 1;
056:            protected static final int TCN_REQUIRED_PATCH = 8;
057:            protected static final int TCN_RECOMMENDED_PV = 10;
058:
059:            // ---------------------------------------------- Properties
060:            protected static String SSLEngine = "on"; //default on
061:            protected static boolean sslInitialized = false;
062:            protected static boolean aprInitialized = false;
063:
064:            // ---------------------------------------------- LifecycleListener Methods
065:
066:            /**
067:             * Primary entry point for startup and shutdown events.
068:             *
069:             * @param event The event that has occurred
070:             */
071:            public void lifecycleEvent(LifecycleEvent event) {
072:
073:                if (Lifecycle.INIT_EVENT.equals(event.getType())) {
074:                    aprInitialized = init();
075:                    if (aprInitialized) {
076:                        try {
077:                            initializeSSL();
078:                        } catch (Throwable t) {
079:                            if (!log.isDebugEnabled()) {
080:                                log.info(sm.getString("aprListener.sslInit"));
081:                            } else {
082:                                log.debug(sm.getString("aprListener.sslInit"));
083:                            }
084:                        }
085:                    }
086:                } else if (Lifecycle.AFTER_STOP_EVENT.equals(event.getType())) {
087:                    if (!aprInitialized) {
088:                        return;
089:                    }
090:                    try {
091:                        terminateAPR();
092:                    } catch (Throwable t) {
093:                        if (!log.isDebugEnabled()) {
094:                            log.info(sm.getString("aprListener.aprDestroy"));
095:                        } else {
096:                            log
097:                                    .debug(
098:                                            sm
099:                                                    .getString("aprListener.aprDestroy"),
100:                                            t);
101:                        }
102:                    }
103:                }
104:
105:            }
106:
107:            private static synchronized void terminateAPR()
108:                    throws ClassNotFoundException, NoSuchMethodException,
109:                    IllegalAccessException, InvocationTargetException {
110:                String methodName = "terminate";
111:                Method method = Class.forName("org.apache.tomcat.jni.Library")
112:                        .getMethod(methodName, (Class[]) null);
113:                method.invoke(null, (Object[]) null);
114:            }
115:
116:            private boolean init() {
117:                int major = 0;
118:                int minor = 0;
119:                int patch = 0;
120:                if (aprInitialized) {
121:                    return true;
122:                }
123:                try {
124:                    String methodName = "initialize";
125:                    Class paramTypes[] = new Class[1];
126:                    paramTypes[0] = String.class;
127:                    Object paramValues[] = new Object[1];
128:                    paramValues[0] = null;
129:                    Class clazz = Class
130:                            .forName("org.apache.tomcat.jni.Library");
131:                    Method method = clazz.getMethod(methodName, paramTypes);
132:                    method.invoke(null, paramValues);
133:                    major = clazz.getField("TCN_MAJOR_VERSION").getInt(null);
134:                    minor = clazz.getField("TCN_MINOR_VERSION").getInt(null);
135:                    patch = clazz.getField("TCN_PATCH_VERSION").getInt(null);
136:                } catch (Throwable t) {
137:                    if (!log.isDebugEnabled()) {
138:                        log.info(sm.getString("aprListener.aprInit", System
139:                                .getProperty("java.library.path")));
140:                    } else {
141:                        log.debug(sm.getString("aprListener.aprInit", System
142:                                .getProperty("java.library.path")), t);
143:                    }
144:                    return false;
145:                }
146:                if ((major != TCN_REQUIRED_MAJOR)
147:                        || (minor != TCN_REQUIRED_MINOR)
148:                        || (patch < TCN_REQUIRED_PATCH)) {
149:                    log.error(sm.getString("aprListener.tcnInvalid", major
150:                            + "." + minor + "." + patch, TCN_REQUIRED_MAJOR
151:                            + "." + TCN_REQUIRED_MINOR + "."
152:                            + TCN_REQUIRED_PATCH));
153:                    try {
154:                        // Terminate the APR in case the version
155:                        // is below required.                
156:                        terminateAPR();
157:                    } catch (Throwable t) {
158:                        // Ignore
159:                    }
160:                    return false;
161:                }
162:                if (patch < TCN_RECOMMENDED_PV) {
163:                    if (!log.isDebugEnabled()) {
164:                        log.info(sm.getString("aprListener.tcnVersion", major
165:                                + "." + minor + "." + patch, TCN_REQUIRED_MAJOR
166:                                + "." + TCN_REQUIRED_MINOR + "."
167:                                + TCN_RECOMMENDED_PV));
168:                    } else {
169:                        log.debug(sm.getString("aprListener.tcnVersion", major
170:                                + "." + minor + "." + patch, TCN_REQUIRED_MAJOR
171:                                + "." + TCN_REQUIRED_MINOR + "."
172:                                + TCN_RECOMMENDED_PV));
173:                    }
174:                }
175:                if (!log.isDebugEnabled()) {
176:                    log.info(sm.getString("aprListener.tcnValid", major + "."
177:                            + minor + "." + patch));
178:                } else {
179:                    log.debug(sm.getString("aprListener.tcnValid", major + "."
180:                            + minor + "." + patch));
181:                }
182:                // Log APR flags
183:                log.info(sm
184:                        .getString("aprListener.flags", Library.APR_HAVE_IPV6,
185:                                Library.APR_HAS_SENDFILE,
186:                                Library.APR_HAS_SO_ACCEPTFILTER,
187:                                Library.APR_HAS_RANDOM));
188:                return true;
189:            }
190:
191:            private static synchronized void initializeSSL()
192:                    throws ClassNotFoundException, NoSuchMethodException,
193:                    IllegalAccessException, InvocationTargetException {
194:
195:                if ("off".equalsIgnoreCase(SSLEngine)) {
196:                    return;
197:                }
198:                if (sslInitialized) {
199:                    //only once per VM
200:                    return;
201:                }
202:                String methodName = "initialize";
203:                Class paramTypes[] = new Class[1];
204:                paramTypes[0] = String.class;
205:                Object paramValues[] = new Object[1];
206:                paramValues[0] = "on".equalsIgnoreCase(SSLEngine) ? null
207:                        : SSLEngine;
208:                Class clazz = Class.forName("org.apache.tomcat.jni.SSL");
209:                Method method = clazz.getMethod(methodName, paramTypes);
210:                method.invoke(null, paramValues);
211:                sslInitialized = true;
212:            }
213:
214:            public String getSSLEngine() {
215:                return SSLEngine;
216:            }
217:
218:            public void setSSLEngine(String SSLEngine) {
219:                this.SSLEngine = SSLEngine;
220:            }
221:
222:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.