Source Code Cross Referenced for TimerServiceBean.java in  » Workflow-Engines » jbpm-jpdl-3.2.2 » org » jbpm » scheduler » ejbtimer » 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 » Workflow Engines » jbpm jpdl 3.2.2 » org.jbpm.scheduler.ejbtimer 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.jbpm.scheduler.ejbtimer;
002:
003:        import java.io.Serializable;
004:        import java.rmi.RemoteException;
005:        import java.util.Iterator;
006:
007:        import javax.ejb.EJBException;
008:        import javax.ejb.SessionBean;
009:        import javax.ejb.SessionContext;
010:        import javax.ejb.TimedObject;
011:        import javax.ejb.TimerService;
012:        import javax.naming.Context;
013:        import javax.naming.InitialContext;
014:
015:        import org.apache.commons.logging.Log;
016:        import org.apache.commons.logging.LogFactory;
017:        import org.jbpm.JbpmException;
018:        import org.jbpm.ejb.LocalCommandService;
019:        import org.jbpm.ejb.LocalCommandServiceHome;
020:        import org.jbpm.graph.exe.ProcessInstance;
021:        import org.jbpm.graph.exe.Token;
022:        import org.jbpm.job.Timer;
023:
024:        public class TimerServiceBean implements  SessionBean, TimedObject {
025:
026:            private static final long serialVersionUID = 1L;
027:
028:            SessionContext sessionContext;
029:
030:            public void ejbCreate() {
031:            }
032:
033:            public void createTimer(Timer timer) {
034:                TimerService timerService = sessionContext.getTimerService();
035:                log.debug("creating timer " + timer
036:                        + " in the ejb timer service");
037:                timerService.createTimer(timer.getDueDate(), new TimerInfo(
038:                        timer));
039:            }
040:
041:            public void cancelTimersByName(String timerName, Token token) {
042:
043:                // TODO make the scanning of timers for cancellation optional by only deleting the timerjobs in the db.
044:                // of course, the corresponding ejb timer notifications have to be ignored. 
045:
046:                log.debug("cancelling timers with name " + timerName
047:                        + " from the ejb timer service");
048:
049:                TimerService timerService = sessionContext.getTimerService();
050:                Iterator iter = timerService.getTimers().iterator();
051:                while (iter.hasNext()) {
052:                    javax.ejb.Timer ejbTimer = (javax.ejb.Timer) iter.next();
053:                    if (ejbTimer.getInfo() instanceof  TimerInfo) {
054:                        TimerInfo timerInfo = (TimerInfo) ejbTimer.getInfo();
055:                        if (timerInfo.matchesName(timerName, token)) {
056:                            ejbTimer.cancel();
057:                        }
058:                    }
059:                }
060:            }
061:
062:            public void deleteTimersForProcessInstance(
063:                    ProcessInstance processInstance) {
064:
065:                // TODO make the scanning of timers for cancellation optional by only deleting the timerjobs in the db.
066:                // of course, the corresponding ejb timer notifications have to be ignored. 
067:
068:                log.debug("deleting timers for process instance "
069:                        + processInstance + " from the ejb timer service");
070:
071:                TimerService timerService = sessionContext.getTimerService();
072:                Iterator iter = timerService.getTimers().iterator();
073:                while (iter.hasNext()) {
074:                    javax.ejb.Timer ejbTimer = (javax.ejb.Timer) iter.next();
075:                    if (ejbTimer.getInfo() instanceof  TimerInfo) {
076:                        TimerInfo timerInfo = (TimerInfo) ejbTimer.getInfo();
077:                        if (timerInfo.matchesProcessInstance(processInstance)) {
078:                            ejbTimer.cancel();
079:                        }
080:                    }
081:                }
082:            }
083:
084:            public void ejbTimeout(javax.ejb.Timer ejbTimer) {
085:                log.debug("ejb timer " + ejbTimer + " fires");
086:                String localCommandServiceJndiName = "java:comp/env/ejb/LocalCommandServiceBean";
087:                try {
088:                    Context initial = new InitialContext();
089:                    LocalCommandServiceHome localCommandServiceHome = (LocalCommandServiceHome) initial
090:                            .lookup(localCommandServiceJndiName);
091:                    LocalCommandService localCommandService = localCommandServiceHome
092:                            .create();
093:                    Serializable info = ejbTimer.getInfo();
094:                    if (!(info instanceof  TimerInfo)) {
095:                        if (info == null) {
096:                            throw new NullPointerException("timer info is null");
097:                        } else {
098:                            throw new ClassCastException("timer info ("
099:                                    + info.getClass().getName()
100:                                    + ") is not of the expected class "
101:                                    + TimerInfo.class.getName());
102:                        }
103:                    }
104:                    TimerInfo timerInfo = (TimerInfo) info;
105:                    Timer timer = (Timer) localCommandService
106:                            .execute(new ExecuteTimerCommand(timerInfo
107:                                    .getTimerId()));
108:                    // if the timer has repeat
109:                    if ((timer != null) && (timer.getRepeat() != null)) {
110:                        // create a new timer
111:                        log.debug("scheduling timer for repeat at "
112:                                + timer.getDueDate());
113:                        createTimer(timer);
114:                    }
115:                } catch (Exception e) {
116:                    JbpmException jbpmException = new JbpmException(
117:                            "couldn't execute timer", e);
118:                    log.error(jbpmException);
119:                    throw jbpmException;
120:                }
121:            }
122:
123:            public void setSessionContext(SessionContext sessionContext)
124:                    throws EJBException, RemoteException {
125:                this .sessionContext = sessionContext;
126:            }
127:
128:            public void ejbActivate() throws EJBException, RemoteException {
129:            }
130:
131:            public void ejbPassivate() throws EJBException, RemoteException {
132:            }
133:
134:            public void ejbRemove() throws EJBException, RemoteException {
135:            }
136:
137:            private static Log log = LogFactory.getLog(TimerServiceBean.class);
138:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.