Source Code Cross Referenced for EasyBeansTimer.java in  » J2EE » ow2-easybeans » org » ow2 » easybeans » component » quartz » 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 » ow2 easybeans » org.ow2.easybeans.component.quartz 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         * EasyBeans
003:         * Copyright (C) 2007 Bull S.A.S.
004:         * Contact: easybeans@ow2.org
005:         *
006:         * This library is free software; you can redistribute it and/or
007:         * modify it under the terms of the GNU Lesser General Public
008:         * License as published by the Free Software Foundation; either
009:         * version 2.1 of the License, or any later version.
010:         *
011:         * This library is distributed in the hope that it will be useful,
012:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
013:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
014:         * Lesser General Public License for more details.
015:         *
016:         * You should have received a copy of the GNU Lesser General Public
017:         * License along with this library; if not, write to the Free Software
018:         * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
019:         * USA
020:         *
021:         * --------------------------------------------------------------------------
022:         * $Id: EasyBeansTimer.java 1970 2007-10-16 11:49:25Z benoitf $
023:         * --------------------------------------------------------------------------
024:         */package org.ow2.easybeans.component.quartz;
025:
026:        import java.io.Serializable;
027:        import java.util.Date;
028:
029:        import javax.ejb.EJBException;
030:        import javax.ejb.NoSuchObjectLocalException;
031:        import javax.ejb.Timer;
032:        import javax.ejb.TimerHandle;
033:
034:        import org.quartz.Scheduler;
035:        import org.quartz.SchedulerException;
036:        import org.quartz.Trigger;
037:
038:        /**
039:         * Implementation of the Timer interface of EJB specification.
040:         * @author Florent Benoit
041:         */
042:        public class EasyBeansTimer implements  Timer {
043:
044:            /**
045:             * Job Detail for this timer.
046:             */
047:            private EasyBeansJobDetail jobDetail = null;
048:
049:            /**
050:             * Trigger used by this timer.
051:             */
052:            private Trigger trigger = null;
053:
054:            /**
055:             * Scheduler used for this timer.
056:             */
057:            private Scheduler scheduler = null;
058:
059:            /**
060:             * Create a new Timer object with the given objects (job, trigger and scheduler).
061:             * @param jobDetail the given job used to cancel the timer or in order to get Serializable info
062:             * @param trigger the trigger used to get the next fire
063:             * @param scheduler for canceling jobs
064:             */
065:            public EasyBeansTimer(final EasyBeansJobDetail jobDetail,
066:                    final Trigger trigger, final Scheduler scheduler) {
067:                this .jobDetail = jobDetail;
068:                this .trigger = trigger;
069:                this .scheduler = scheduler;
070:            }
071:
072:            /**
073:             * Cause the timer and all its associated expiration notifications to be
074:             * cancelled.
075:             * @throws IllegalStateException If this method is invoked while the
076:             *         instance is in a state that does not allow access to this method.
077:             * @throws NoSuchObjectLocalException If invoked on a timer that has expired
078:             *         or has been cancelled.
079:             * @throws EJBException If this method could not complete due to a
080:             *         system-level failure.
081:             */
082:            public void cancel() throws IllegalStateException,
083:                    NoSuchObjectLocalException, EJBException {
084:                // Delete job that has been registered by timer service
085:                try {
086:                    scheduler.deleteJob(jobDetail.getName(), jobDetail
087:                            .getGroup());
088:                } catch (SchedulerException e) {
089:                    throw new EJBException("Cannot cancel job with name '"
090:                            + jobDetail.getName() + "'.", e);
091:                }
092:            }
093:
094:            /**
095:             * Get the number of milliseconds that will elapse before the next scheduled
096:             * timer expiration.
097:             * @return the number of milliseconds that will elapse before the next
098:             *         scheduled timer expiration.
099:             * @throws IllegalStateException If this method is invoked while the
100:             *         instance is in a state that does not allow access to this method.
101:             * @throws NoSuchObjectLocalException If invoked on a timer that has expired
102:             *         or has been cancelled.
103:             * @throws EJBException If this method could not complete due to a
104:             *         system-level failure.
105:             */
106:            public long getTimeRemaining() throws IllegalStateException,
107:                    NoSuchObjectLocalException, EJBException {
108:                // If there is no more next timeout, getNextTimeout() method will throw IllegalStateException
109:                return getNextTimeout().getTime() - System.currentTimeMillis();
110:            }
111:
112:            /**
113:             * Get the point in time at which the next timer expiration is scheduled to
114:             * occur.
115:             * @return the point in time at which the next timer expiration is scheduled
116:             *         to occur.
117:             * @throws IllegalStateException If this method is invoked while the
118:             *         instance is in a state that does not allow access to this method.
119:             * @throws NoSuchObjectLocalException If invoked on a timer that has expired
120:             *         or has been cancelled.
121:             * @throws EJBException If this method could not complete due to a
122:             *         system-level failure.
123:             */
124:            public Date getNextTimeout() throws IllegalStateException,
125:                    NoSuchObjectLocalException, EJBException {
126:
127:                // Get next timeout
128:                Date date = trigger.getNextFireTime();
129:
130:                // May be null (trigger will not fire again)
131:                if (date == null) {
132:                    throw new IllegalStateException(
133:                            "No next timeout for this timer");
134:                }
135:
136:                // return the date
137:                return date;
138:            }
139:
140:            /**
141:             * Get the information associated with the timer at the time of creation.
142:             * @return The Serializable object that was passed in at timer creation, or
143:             *         null if the info argument passed in at timer creation was null.
144:             * @throws IllegalStateException If this method is invoked while the
145:             *         instance is in a state that does not allow access to this method.
146:             * @throws NoSuchObjectLocalException If invoked on a timer that has expired
147:             *         or has been cancelled.
148:             * @throws EJBException If this method could not complete due to a
149:             *         system-level failure.
150:             */
151:            public Serializable getInfo() throws IllegalStateException,
152:                    NoSuchObjectLocalException, EJBException {
153:                // Get info from the data of the job detail
154:                return jobDetail.getJobDetailData().getInfo();
155:            }
156:
157:            /**
158:             * Get a serializable handle to the timer. This handle can be used at a
159:             * later time to re-obtain the timer reference.
160:             * @return a serializable handle to the timer.
161:             * @throws IllegalStateException If this method is invoked while the
162:             *         instance is in a state that does not allow access to this method.
163:             * @throws NoSuchObjectLocalException If invoked on a timer that has expired
164:             *         or has been cancelled.
165:             * @throws EJBException If this method could not complete due to a
166:             *         system-level failure.
167:             */
168:            public TimerHandle getHandle() throws IllegalStateException,
169:                    NoSuchObjectLocalException, EJBException {
170:                return new EasyBeansTimerHandle(jobDetail);
171:            }
172:
173:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.