Source Code Cross Referenced for TurbineNonPersistentSchedulerService.java in  » Web-Framework » TURBINE » org » apache » turbine » services » schedule » 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 » Web Framework » TURBINE » org.apache.turbine.services.schedule 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.apache.turbine.services.schedule;
002:
003:        /*
004:         * Licensed to the Apache Software Foundation (ASF) under one
005:         * or more contributor license agreements.  See the NOTICE file
006:         * distributed with this work for additional information
007:         * regarding copyright ownership.  The ASF licenses this file
008:         * to you under the Apache License, Version 2.0 (the
009:         * "License"); you may not use this file except in compliance
010:         * with the License.  You may obtain a copy of the License at
011:         *
012:         *   http://www.apache.org/licenses/LICENSE-2.0
013:         *
014:         * Unless required by applicable law or agreed to in writing,
015:         * software distributed under the License is distributed on an
016:         * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017:         * KIND, either express or implied.  See the License for the
018:         * specific language governing permissions and limitations
019:         * under the License.
020:         */
021:
022:        import java.util.List;
023:        import java.util.Vector;
024:
025:        import javax.servlet.ServletConfig;
026:
027:        import org.apache.commons.configuration.Configuration;
028:
029:        import org.apache.commons.lang.StringUtils;
030:
031:        import org.apache.commons.logging.Log;
032:        import org.apache.commons.logging.LogFactory;
033:
034:        import org.apache.turbine.services.InitializationException;
035:        import org.apache.turbine.util.TurbineException;
036:
037:        /**
038:         * Service for a cron like scheduler that uses the
039:         * TurbineResources.properties file instead of the database.
040:         * The methods that operate on jobs ( get,add,update,remove )
041:         * only operate on the queue in memory and changes are not reflected
042:         * to the properties file which was used to initilize the jobs.
043:         * An example is given below.  The job names are the class names that
044:         * extend ScheduledJob.
045:         *
046:         * <PRE>
047:         *
048:         * services.SchedulerService.scheduler.jobs=scheduledJobName,scheduledJobName2
049:         *
050:         * services.SchedulerService.scheduler.job.scheduledJobName.ID=1
051:         * services.SchedulerService.scheduler.job.scheduledJobName.SECOND=-1
052:         * services.SchedulerService.scheduler.job.scheduledJobName.MINUTE=-1
053:         * services.SchedulerService.scheduler.job.scheduledJobName.HOUR=7
054:         * services.SchedulerService.scheduler.job.scheduledJobName.WEEKDAY=-1
055:         * services.SchedulerService.scheduler.job.scheduledJobName.DAY_OF_MONTH=-1
056:         *
057:         * services.SchedulerService.scheduler.job.scheduledJobName2.ID=1
058:         * services.SchedulerService.scheduler.job.scheduledJobName2.SECOND=-1
059:         * services.SchedulerService.scheduler.job.scheduledJobName2.MINUTE=-1
060:         * services.SchedulerService.scheduler.job.scheduledJobName2.HOUR=7
061:         * services.SchedulerService.scheduler.job.scheduledJobName2.WEEKDAY=-1
062:         * services.SchedulerService.scheduler.job.scheduledJobName2.DAY_OF_MONTH=-1
063:         *
064:         * </PRE>
065:         *
066:         * Based on TamboraSchedulerService written by John Thorhauer.
067:         *
068:         * @author <a href="mailto:ekkerbj@netscpae.net">Jeff Brekke</a>
069:         * @author <a href="mailto:john@zenplex.com">John Thorhauer</a>
070:         * @author <a href="mailto:quintonm@bellsouth.net">Quinton McCombs</a>
071:         * @version $Id: TurbineNonPersistentSchedulerService.java 534527 2007-05-02 16:10:59Z tv $
072:         */
073:        public class TurbineNonPersistentSchedulerService extends
074:                TurbineSchedulerService {
075:            /** Logging */
076:            private static Log log = LogFactory
077:                    .getLog(ScheduleService.LOGGER_NAME);
078:
079:            /**
080:             * Constructor.
081:             *
082:             * @exception TurbineException a generic exception.
083:             */
084:            public TurbineNonPersistentSchedulerService()
085:                    throws TurbineException {
086:                super ();
087:            }
088:
089:            /**
090:             * Called the first time the Service is used.<br>
091:             *
092:             * Load all the jobs from cold storage.  Add jobs to the queue
093:             * (sorted in ascending order by runtime) and start the scheduler
094:             * thread.
095:             */
096:            public void init() throws InitializationException {
097:                Configuration conf = getConfiguration();
098:
099:                try {
100:                    scheduleQueue = new JobQueue();
101:                    mainLoop = new MainLoop();
102:
103:                    List jobProps = conf.getList("scheduler.jobs");
104:                    List jobs = new Vector();
105:                    // If there are scheduler.jobs defined then set up a job vector
106:                    // for the scheduleQueue
107:                    if (!jobProps.isEmpty()) {
108:                        for (int i = 0; i < jobProps.size(); i++) {
109:                            String jobName = (String) jobProps.get(i);
110:                            String jobPrefix = "scheduler.job." + jobName;
111:
112:                            String jobId = conf.getString(jobPrefix + ".ID",
113:                                    null);
114:                            if (StringUtils.isEmpty(jobId)) {
115:                                throw new Exception(
116:                                        "There is an error in the TurbineResources.properties file. \n"
117:                                                + jobPrefix
118:                                                + ".ID is not found.\n");
119:                            }
120:
121:                            int sec = conf.getInt(jobPrefix + ".SECOND", -1);
122:                            int min = conf.getInt(jobPrefix + ".MINUTE", -1);
123:                            int hr = conf.getInt(jobPrefix + ".HOUR", -1);
124:                            int wkday = conf.getInt(jobPrefix + ".WEEKDAY", -1);
125:                            int dayOfMonth = conf.getInt(jobPrefix
126:                                    + ".DAY_OF_MONTH", -1);
127:
128:                            JobEntry je = new JobEntry(sec, min, hr, wkday,
129:                                    dayOfMonth, jobName);
130:                            je.setJobId(Integer.parseInt(jobId));
131:                            jobs.add(je);
132:
133:                        }
134:                    }
135:
136:                    if (jobs != null && jobs.size() > 0) {
137:                        scheduleQueue.batchLoad(jobs);
138:                    }
139:
140:                    setEnabled(getConfiguration().getBoolean("enabled", true));
141:                    restart();
142:
143:                    setInit(true);
144:                } catch (Exception e) {
145:                    String errorMessage = "Could not initialize the scheduler service";
146:                    log.error(errorMessage, e);
147:                    throw new InitializationException(errorMessage, e);
148:                }
149:            }
150:
151:            /**
152:             * Called the first time the Service is used.<br>
153:             *
154:             * Load all the jobs from cold storage.  Add jobs to the queue
155:             * (sorted in ascending order by runtime) and start the scheduler
156:             * thread.
157:             *
158:             * @param config A ServletConfig.
159:             * @deprecated use init() instead.
160:             */
161:            public void init(ServletConfig config)
162:                    throws InitializationException {
163:                init();
164:            }
165:
166:            /**
167:             * This method returns the job element from the internal queue.
168:             *
169:             * @param oid The int id for the job.
170:             * @return A JobEntry.
171:             * @exception TurbineException could not retrieve job
172:             */
173:            public JobEntry getJob(int oid) throws TurbineException {
174:                JobEntry je = new JobEntry();
175:                je.setJobId(oid);
176:                return scheduleQueue.getJob(je);
177:            }
178:
179:            /**
180:             * Add a new job to the queue.
181:             *
182:             * @param je A JobEntry with the job to add.
183:             * @throws TurbineException job could not be added
184:             */
185:            public void addJob(JobEntry je) throws TurbineException {
186:                updateJob(je);
187:            }
188:
189:            /**
190:             * Remove a job from the queue.
191:             *
192:             * @param je A JobEntry with the job to remove.
193:             */
194:            public void removeJob(JobEntry je) {
195:                // Remove from the queue.
196:                scheduleQueue.remove(je);
197:                restart();
198:            }
199:
200:            /**
201:             * Add/update a job
202:             *
203:             * @param je A JobEntry with the job to modify
204:             * @throws TurbineException job could not be updated
205:             */
206:            public void updateJob(JobEntry je) throws TurbineException {
207:                try {
208:                    je.calcRunTime();
209:
210:                    // Update the queue.
211:                    scheduleQueue.modify(je);
212:                    restart();
213:                } catch (Exception e) {
214:                    String errorMessage = "Problem updating Scheduled Job: "
215:                            + je.getTask();
216:                    log.error(errorMessage, e);
217:                    throw new TurbineException(errorMessage, e);
218:                }
219:            }
220:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.