Source Code Cross Referenced for EasyBeansTimerHandle.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: EasyBeansTimerHandle.java 1970 2007-10-16 11:49:25Z benoitf $
023:         * --------------------------------------------------------------------------
024:         */package org.ow2.easybeans.component.quartz;
025:
026:        import java.util.List;
027:
028:        import javax.ejb.EJBException;
029:        import javax.ejb.NoSuchObjectLocalException;
030:        import javax.ejb.Timer;
031:        import javax.ejb.TimerHandle;
032:
033:        import org.ow2.easybeans.api.EZBServer;
034:        import org.ow2.easybeans.api.EmbeddedManager;
035:        import org.ow2.easybeans.api.components.EZBComponentRegistry;
036:        import org.ow2.easybeans.component.itf.TimerComponent;
037:        import org.quartz.JobDetail;
038:        import org.quartz.Scheduler;
039:        import org.quartz.SchedulerException;
040:        import org.quartz.Trigger;
041:
042:        /**
043:         * Implementation of the Timer handle interface.
044:         * @author Florent Benoit
045:         */
046:        public class EasyBeansTimerHandle implements  TimerHandle {
047:
048:            /**
049:             * Serial version UID for serializable classes.
050:             */
051:            private static final long serialVersionUID = 5391559452078385341L;
052:
053:            /**
054:             * JobDetail used to get parameters.
055:             */
056:            private EasyBeansJobDetail easyBeansJobDetail;
057:
058:            /**
059:             * Constructor. Build an handle for this timer.
060:             * @param easyBeansJobDetail the job detail.
061:             */
062:            public EasyBeansTimerHandle(
063:                    final EasyBeansJobDetail easyBeansJobDetail) {
064:                this .easyBeansJobDetail = easyBeansJobDetail;
065:            }
066:
067:            /**
068:             * Obtain a reference to the timer represented by this handle.
069:             * @return a reference to the timer represented by this handle.
070:             * @throws IllegalStateException If this method is invoked while the
071:             *         instance is in a state that does not allow access to this method.
072:             * @throws NoSuchObjectLocalException If invoked on a handle whose
073:             *         associated timer has expired or has been cancelled.
074:             * @throws EJBException If this method could not complete due to a
075:             *         system-level failure.
076:             */
077:            public Timer getTimer() throws IllegalStateException,
078:                    NoSuchObjectLocalException, EJBException {
079:                Timer timer = null;
080:
081:                // Get data from the Job Detail
082:                String jobName = easyBeansJobDetail.getName();
083:                String groupName = easyBeansJobDetail.getGroup();
084:
085:                // Get data from the jobDetail
086:                EasyBeansJobDetailData easyBeansJobDetailData = easyBeansJobDetail
087:                        .getJobDetailData();
088:                Integer easyBeansServerID = easyBeansJobDetailData
089:                        .getEasyBeansServerID();
090:
091:                // Get the EasyBeans embedded instance
092:                EZBServer embedded = EmbeddedManager
093:                        .getEmbedded(easyBeansServerID);
094:
095:                // Get the components registry
096:                EZBComponentRegistry registry = embedded.getComponentManager()
097:                        .getComponentRegistry();
098:
099:                // Get the timer components
100:                List<TimerComponent> timerComponents = registry
101:                        .getComponents(TimerComponent.class);
102:
103:                // Find the quartz component in this list
104:                if (timerComponents == null || timerComponents.size() == 0) {
105:                    throw new EJBException(
106:                            "Cannot get the timer object as no timer component have been found on the EasyBeans server");
107:                }
108:                // Check the first one
109:                TimerComponent timerComponent = timerComponents.get(0);
110:                QuartzComponent quartzComponent = null;
111:                if (timerComponent instanceof  QuartzComponent) {
112:                    quartzComponent = (QuartzComponent) timerComponent;
113:                } else {
114:                    throw new EJBException(
115:                            "The timer component found is not a Quartz Timer Component ('"
116:                                    + timerComponent + "').");
117:                }
118:
119:                // Get Scheduler on the quartz component
120:                Scheduler scheduler = quartzComponent.getScheduler();
121:
122:                // Get detail
123:                JobDetail jobDetail = null;
124:                try {
125:                    jobDetail = scheduler.getJobDetail(jobName, groupName);
126:                } catch (SchedulerException e) {
127:                    throw new EJBException(
128:                            "Cannot get the jobDetail for the jobName '"
129:                                    + jobName + "'.", e);
130:                }
131:
132:                // Cast to correct object
133:                EasyBeansJobDetail easyBeansJobDetail = null;
134:                if (jobDetail instanceof  EasyBeansJobDetail) {
135:                    easyBeansJobDetail = (EasyBeansJobDetail) jobDetail;
136:                } else {
137:                    throw new EJBException(
138:                            "JobDetail found for the job named '" + jobName
139:                                    + "' is not an EasyBeansJobDetail object");
140:                }
141:
142:                // Get triggers
143:                Trigger[] triggers = null;
144:                try {
145:                    triggers = scheduler.getTriggersOfJob(jobName, groupName);
146:                } catch (SchedulerException e) {
147:                    throw new EJBException(
148:                            "Cannot get triggers for the job named '" + jobName
149:                                    + "'.", e);
150:                }
151:
152:                // Should be only once trigger per job
153:                if (triggers == null || triggers.length > 1) {
154:                    throw new EJBException(
155:                            "Invalid numbers of triggers found for the job named '"
156:                                    + jobName + "'.");
157:                }
158:
159:                // Build a timer object and return it
160:                timer = new EasyBeansTimer(easyBeansJobDetail, triggers[0],
161:                        scheduler);
162:
163:                // Return the timer instance
164:                return timer;
165:            }
166:
167:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.