Source Code Cross Referenced for ScheduledTimerListener.java in  » J2EE » spring-framework-2.5 » org » springframework » scheduling » commonj » 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 » J2EE » spring framework 2.5 » org.springframework.scheduling.commonj 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2002-2007 the original author or authors.
003:         *
004:         * Licensed under the Apache License, Version 2.0 (the "License");
005:         * you may not use this file except in compliance with the License.
006:         * You may obtain a copy 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,
012:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013:         * See the License for the specific language governing permissions and
014:         * limitations under the License.
015:         */
016:
017:        package org.springframework.scheduling.commonj;
018:
019:        import commonj.timers.TimerListener;
020:
021:        /**
022:         * JavaBean that describes a scheduled TimerListener, consisting of
023:         * the TimerListener itself (or a Runnable to create a TimerListener for)
024:         * and a delay plus period. Period needs to be specified;
025:         * there is no point in a default for it.
026:         *
027:         * <p>The CommonJ TimerManager does not offer more sophisticated scheduling
028:         * options such as cron expressions. Consider using Quartz for such
029:         * advanced needs.
030:         *
031:         * <p>Note that the TimerManager uses a TimerListener instance that is
032:         * shared between repeated executions, in contrast to Quartz which
033:         * instantiates a new Job for each execution.
034:         *
035:         * @author Juergen Hoeller
036:         * @since 2.0
037:         * @see commonj.timers.TimerListener
038:         * @see commonj.timers.TimerManager#schedule(commonj.timers.TimerListener, long, long)
039:         * @see commonj.timers.TimerManager#scheduleAtFixedRate(commonj.timers.TimerListener, long, long)
040:         */
041:        public class ScheduledTimerListener {
042:
043:            private TimerListener timerListener;
044:
045:            private long delay = 0;
046:
047:            private long period = -1;
048:
049:            private boolean fixedRate = false;
050:
051:            /**
052:             * Create a new ScheduledTimerListener,
053:             * to be populated via bean properties.
054:             * @see #setTimerListener
055:             * @see #setDelay
056:             * @see #setPeriod
057:             * @see #setFixedRate
058:             */
059:            public ScheduledTimerListener() {
060:            }
061:
062:            /**
063:             * Create a new ScheduledTimerListener, with default
064:             * one-time execution without delay.
065:             * @param timerListener the TimerListener to schedule
066:             */
067:            public ScheduledTimerListener(TimerListener timerListener) {
068:                this .timerListener = timerListener;
069:            }
070:
071:            /**
072:             * Create a new ScheduledTimerListener, with default
073:             * one-time execution with the given delay.
074:             * @param timerListener the TimerListener to schedule
075:             * @param delay the delay before starting the task for the first time (ms)
076:             */
077:            public ScheduledTimerListener(TimerListener timerListener,
078:                    long delay) {
079:                this .timerListener = timerListener;
080:                this .delay = delay;
081:            }
082:
083:            /**
084:             * Create a new ScheduledTimerListener.
085:             * @param timerListener the TimerListener to schedule
086:             * @param delay the delay before starting the task for the first time (ms)
087:             * @param period the period between repeated task executions (ms)
088:             * @param fixedRate whether to schedule as fixed-rate execution
089:             */
090:            public ScheduledTimerListener(TimerListener timerListener,
091:                    long delay, long period, boolean fixedRate) {
092:                this .timerListener = timerListener;
093:                this .delay = delay;
094:                this .period = period;
095:                this .fixedRate = fixedRate;
096:            }
097:
098:            /**
099:             * Create a new ScheduledTimerListener, with default
100:             * one-time execution without delay.
101:             * @param timerTask the Runnable to schedule as TimerListener
102:             */
103:            public ScheduledTimerListener(Runnable timerTask) {
104:                setRunnable(timerTask);
105:            }
106:
107:            /**
108:             * Create a new ScheduledTimerListener, with default
109:             * one-time execution with the given delay.
110:             * @param timerTask the Runnable to schedule as TimerListener
111:             * @param delay the delay before starting the task for the first time (ms)
112:             */
113:            public ScheduledTimerListener(Runnable timerTask, long delay) {
114:                setRunnable(timerTask);
115:                this .delay = delay;
116:            }
117:
118:            /**
119:             * Create a new ScheduledTimerListener.
120:             * @param timerTask the Runnable to schedule as TimerListener
121:             * @param delay the delay before starting the task for the first time (ms)
122:             * @param period the period between repeated task executions (ms)
123:             * @param fixedRate whether to schedule as fixed-rate execution
124:             */
125:            public ScheduledTimerListener(Runnable timerTask, long delay,
126:                    long period, boolean fixedRate) {
127:                setRunnable(timerTask);
128:                this .delay = delay;
129:                this .period = period;
130:                this .fixedRate = fixedRate;
131:            }
132:
133:            /**
134:             * Set the Runnable to schedule as TimerListener.
135:             * @see DelegatingTimerListener
136:             */
137:            public void setRunnable(Runnable timerTask) {
138:                this .timerListener = new DelegatingTimerListener(timerTask);
139:            }
140:
141:            /**
142:             * Set the TimerListener to schedule.
143:             */
144:            public void setTimerListener(TimerListener timerListener) {
145:                this .timerListener = timerListener;
146:            }
147:
148:            /**
149:             * Return the TimerListener to schedule.
150:             */
151:            public TimerListener getTimerListener() {
152:                return this .timerListener;
153:            }
154:
155:            /**
156:             * Set the delay before starting the task for the first time,
157:             * in milliseconds. Default is 0, immediately starting the
158:             * task after successful scheduling.
159:             * <p>If the "firstTime" property is specified, this property will be ignored.
160:             * Specify one or the other, not both.
161:             */
162:            public void setDelay(long delay) {
163:                this .delay = delay;
164:            }
165:
166:            /**
167:             * Return the delay before starting the job for the first time.
168:             */
169:            public long getDelay() {
170:                return this .delay;
171:            }
172:
173:            /**
174:             * Set the period between repeated task executions, in milliseconds.
175:             * <p>Default is -1, leading to one-time execution. In case of zero or a
176:             * positive value, the task will be executed repeatedly, with the given
177:             * interval inbetween executions.
178:             * <p>Note that the semantics of the period value vary between fixed-rate
179:             * and fixed-delay execution.
180:             * <p><b>Note:</b> A period of 0 (for example as fixed delay) <i>is</i>
181:             * supported, because the CommonJ specification defines this as a legal value.
182:             * Hence a value of 0 will result in immediate re-execution after a job has
183:             * finished (not in one-time execution like with <code>java.util.Timer</code>).
184:             * @see #setFixedRate
185:             * @see #isOneTimeTask()
186:             * @see commonj.timers.TimerManager#schedule(commonj.timers.TimerListener, long, long)
187:             */
188:            public void setPeriod(long period) {
189:                this .period = period;
190:            }
191:
192:            /**
193:             * Return the period between repeated task executions.
194:             */
195:            public long getPeriod() {
196:                return this .period;
197:            }
198:
199:            /**
200:             * Is this task only ever going to execute once?
201:             * @return <code>true</code> if this task is only ever going to execute once
202:             * @see #getPeriod()
203:             */
204:            public boolean isOneTimeTask() {
205:                return (this .period < 0);
206:            }
207:
208:            /**
209:             * Set whether to schedule as fixed-rate execution, rather than
210:             * fixed-delay execution. Default is "false", i.e. fixed delay.
211:             * <p>See TimerManager javadoc for details on those execution modes.
212:             * @see commonj.timers.TimerManager#schedule(commonj.timers.TimerListener, long, long)
213:             * @see commonj.timers.TimerManager#scheduleAtFixedRate(commonj.timers.TimerListener, long, long)
214:             */
215:            public void setFixedRate(boolean fixedRate) {
216:                this .fixedRate = fixedRate;
217:            }
218:
219:            /**
220:             * Return whether to schedule as fixed-rate execution.
221:             */
222:            public boolean isFixedRate() {
223:                return this.fixedRate;
224:            }
225:
226:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.