Source Code Cross Referenced for QuartzInitializerListener.java in  » Project-Management » quartz » org » quartz » ee » servlet » 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 » Project Management » quartz » org.quartz.ee.servlet 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2004-2005 OpenSymphony
003:         *
004:         * Licensed under the Apache License, Version 2.0 (the "License"); you may not
005:         * use this file except in compliance with the License. You may obtain a copy
006:         * of the License at
007:         *
008:         *   http://www.apache.org/licenses/LICENSE-2.0
009:         *
010:         * Unless required by applicable law or agreed to in writing, software
011:         * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
012:         * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
013:         * License for the specific language governing permissions and limitations
014:         * under the License.
015:         *
016:         */
017:
018:        /*
019:         * Previously Copyright (c) 2001-2004 James House
020:         */
021:        package org.quartz.ee.servlet;
022:
023:        import javax.servlet.ServletContext;
024:        import javax.servlet.ServletContextEvent;
025:        import javax.servlet.ServletContextListener;
026:
027:        import org.quartz.Scheduler;
028:        import org.quartz.impl.StdSchedulerFactory;
029:
030:        /**
031:         * <p>
032:         * A ServletContextListner that can be used to initialize Quartz.
033:         * </p>
034:         *
035:         * <p>
036:         * You'll want to add something like this to your WEB-INF/web.xml file:
037:         *
038:         * <pre>
039:         *     &lt;context-param&gt;
040:         *         &lt;param-name&gt;config-file&lt;/param-name&gt;
041:         *         &lt;param-value&gt;/some/path/my_quartz.properties&lt;/param-value&gt;
042:         *     &lt;/context-param&gt;
043:         *     &lt;context-param&gt;
044:         *         &lt;param-name&gt;shutdown-on-unload&lt;/param-name&gt;
045:         *         &lt;param-value&gt;true&lt;/param-value&gt;
046:         *     &lt;/context-param&gt;
047:         *     &lt;context-param&gt;
048:         *         &lt;param-name&gt;start-scheduler-on-load&lt;/param-name&gt;
049:         *         &lt;param-value&gt;true&lt;/param-value&gt;
050:         *     &lt;/context-param&gt;
051:         *     
052:         *     &lt;listener&gt;
053:         *         &lt;listener-class&gt;
054:         *             org.quartz.ee.servlet.QuartzInitializerServletListener
055:         *         &lt;/listener-class&gt;
056:         *     &lt;/listener&gt;
057:         * </pre>
058:         *
059:         * </p>
060:         * <p>
061:         * The init parameter 'config-file' can be used to specify the path (and
062:         * filename) of your Quartz properties file. If you leave out this parameter,
063:         * the default ("quartz.properties") will be used.
064:         * </p>
065:         *
066:         * <p>
067:         * The init parameter 'shutdown-on-unload' can be used to specify whether you
068:         * want scheduler.shutdown() called when the servlet is unloaded (usually when
069:         * the application server is being shutdown). Possible values are "true" or
070:         * "false". The default is "true".
071:         * </p>
072:         *
073:         * <p>
074:         * The init parameter 'start-scheduler-on-load' can be used to specify whether
075:         * you want the scheduler.start() method called when the servlet is first loaded.
076:         * If set to false, your application will need to call the start() method before
077:         * the scheduler begins to run and process jobs. Possible values are "true" or
078:         * "false". The default is "true", which means the scheduler is started.
079:         * </p>
080:         *
081:         * A StdSchedulerFactory instance is stored into the ServletContext. You can gain access
082:         * to the factory from a ServletContext instance like this:
083:         * <br>
084:         * <pre>
085:         * StdSchedulerFactory factory = (StdSchedulerFactory) ctx
086:         *                .getAttribute(QuartzInitializerListener.QUARTZ_FACTORY_KEY);</pre>
087:         * <p>
088:         * The init parameter 'servlet-context-factory-key' can be used to override the
089:         * name under which the StdSchedulerFactory is stored into the ServletContext, in 
090:         * which case you will want to use this name rather than 
091:         * <code>QuartzInitializerListener.QUARTZ_FACTORY_KEY</code> in the above example.
092:         * </p>
093:         * 
094:         * Once you have the factory instance, you can retrieve the Scheduler instance by calling
095:         * <code>getScheduler()</code> on the factory.
096:         *
097:         * @author James House
098:         * @author Chuck Cavaness
099:         * @author John Petrocik
100:         */
101:        public class QuartzInitializerListener implements 
102:                ServletContextListener {
103:
104:            public static final String QUARTZ_FACTORY_KEY = "org.quartz.impl.StdSchedulerFactory.KEY";
105:
106:            private boolean performShutdown = true;
107:
108:            private Scheduler scheduler = null;
109:
110:            /*
111:             * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
112:             *
113:             * Interface.
114:             *
115:             * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
116:             */
117:
118:            public void contextInitialized(ServletContextEvent sce) {
119:
120:                System.out
121:                        .println("Quartz Initializer Servlet loaded, initializing Scheduler...");
122:
123:                ServletContext servletContext = sce.getServletContext();
124:                StdSchedulerFactory factory;
125:                try {
126:
127:                    String configFile = servletContext
128:                            .getInitParameter("config-file");
129:                    String shutdownPref = servletContext
130:                            .getInitParameter("shutdown-on-unload");
131:
132:                    if (shutdownPref != null) {
133:                        performShutdown = Boolean.valueOf(shutdownPref)
134:                                .booleanValue();
135:                    }
136:
137:                    // get Properties
138:                    if (configFile != null) {
139:                        factory = new StdSchedulerFactory(configFile);
140:                    } else {
141:                        factory = new StdSchedulerFactory();
142:                    }
143:
144:                    // Always want to get the scheduler, even if it isn't starting, 
145:                    // to make sure it is both initialized and registered.
146:                    scheduler = factory.getScheduler();
147:
148:                    // Should the Scheduler being started now or later
149:                    String startOnLoad = servletContext
150:                            .getInitParameter("start-scheduler-on-load");
151:                    /*
152:                     * If the "start-scheduler-on-load" init-parameter is not specified,
153:                     * the scheduler will be started. This is to maintain backwards
154:                     * compatability.
155:                     */
156:                    if (startOnLoad == null
157:                            || (Boolean.valueOf(startOnLoad).booleanValue())) {
158:                        // Start now
159:                        scheduler.start();
160:                        System.out.println("Scheduler has been started...");
161:                    } else {
162:                        System.out
163:                                .println("Scheduler has not been started. Use scheduler.start()");
164:                    }
165:
166:                    String factoryKey = servletContext
167:                            .getInitParameter("servlet-context-factory-key");
168:                    if (factoryKey == null) {
169:                        factoryKey = QUARTZ_FACTORY_KEY;
170:                    }
171:
172:                    System.out
173:                            .println("Storing the Quartz Scheduler Factory in the servlet context at key: "
174:                                    + factoryKey);
175:                    servletContext.setAttribute(factoryKey, factory);
176:
177:                } catch (Exception e) {
178:                    System.out
179:                            .println("Quartz Scheduler failed to initialize: "
180:                                    + e.toString());
181:                    e.printStackTrace();
182:                }
183:            }
184:
185:            public void contextDestroyed(ServletContextEvent sce) {
186:
187:                if (!performShutdown) {
188:                    return;
189:                }
190:
191:                try {
192:                    if (scheduler != null) {
193:                        scheduler.shutdown();
194:                    }
195:                } catch (Exception e) {
196:                    System.out
197:                            .println("Quartz Scheduler failed to shutdown cleanly: "
198:                                    + e.toString());
199:                    e.printStackTrace();
200:                }
201:
202:                System.out.println("Quartz Scheduler successful shutdown.");
203:            }
204:
205:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.