Source Code Cross Referenced for DeadlineEjbTimerSessionBean.java in  » Workflow-Engines » bonita-v3.1 » hero » session » 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 » bonita v3.1 » hero.session 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package hero.session;
002:
003:        /*
004:         * 02/01/2002 - 15:24:07
005:         *
006:         * AllProjectsSessionEJB.java -
007:         * Copyright (C) 2002 Ecoo Team
008:         * valdes@loria.fr
009:         *
010:         *
011:         * This program is free software; you can redistribute it and/or
012:         * modify it under the terms of the GNU Lesser General Public License
013:         * as published by the Free Software Foundation; either version 2
014:         * of the License, or (at your option) any later version.
015:         *
016:         * This program is distributed in the hope that it will be useful,
017:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
018:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
019:         * GNU Lesser General Public License for more details.
020:         *
021:         * You should have received a copy of the GNU Lesser General Public License
022:         * along with this program; if not, write to the Free Software
023:         * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
024:         */
025:
026:        import hero.interfaces.BnNodeLocal;
027:        import hero.interfaces.BnNodeLocalHome;
028:        import hero.interfaces.BnNodeUtil;
029:        import hero.interfaces.DeadlineSessionLocal;
030:        import hero.interfaces.DeadlineSessionLocalHome;
031:        import hero.interfaces.DeadlineSessionUtil;
032:        import hero.util.TimerData;
033:
034:        import hero.util.HeroException;
035:        import java.util.Date;
036:        import java.io.Serializable;
037:        import java.sql.Timestamp;
038:        import java.util.ArrayList;
039:        import java.util.Collection;
040:        import java.util.Iterator;
041:
042:        import javax.ejb.CreateException;
043:        import javax.ejb.SessionBean;
044:        import javax.ejb.SessionContext;
045:        import javax.ejb.TimedObject;
046:        import javax.ejb.Timer;
047:        import javax.ejb.TimerService;
048:
049:        /**
050:         * Session Bean Template
051:         *
052:         * @ejb:bean name="DeadlineEjbTimerSession"
053:         *           display-name="DeadlineEjbTimerSession Bean"
054:         *           type="Stateless"
055:         *           transaction-type="Container"
056:         *           jndi-name="ejb/hero/DeadlineEjbTimerSession"
057:         *           local-jndi-name="ejb/hero/DeadlineEjbTimerSession_L"
058:         *
059:         * @ejb:transaction type="Supports"
060:         * @ejb.permission unchecked="yes"
061:         * @ejb.security-identity run-as="SuperAdmin"
062:         * @jonas.bean
063:         *      ejb-name="DeadlineEjbTimerSession"
064:         *      jndi-name="ejb/hero/DeadlineEjbTimerSession"
065:         *
066:         * @jboss.container-configuration name="Standard Stateless SessionBean for Bonita"
067:         **/
068:
069:        public class DeadlineEjbTimerSessionBean implements  SessionBean,
070:                TimedObject {
071:
072:            private SessionContext mContext;
073:
074:            /**
075:             * Start the EJB timers for node deadlines .
076:             *
077:             * @param name the name of the node
078:             * @param p_id id of the project
079:             * @ejb:interface-method view-type="both"
080:             * @ejb:transaction type="Required"
081:             * @throws HeroException
082:             *
083:             **/
084:            public void startDeadlineEjbTimers(String nodeName, String p_id)
085:                    throws HeroException {
086:
087:                try {
088:                    BnNodeLocalHome lh = BnNodeUtil.getLocalHome();
089:                    BnNodeLocal node = lh.findByName(nodeName, p_id);
090:
091:                    String type = null;
092:                    Timestamp lNext = null;
093:
094:                    // For absolute deadline
095:                    if (node.getDeadlines().size() != 0) {
096:                        //debug
097:                        //System.out.println("startDeadlines : 	Nb of absolute deadlines = " + 	node.getDeadlines().size());
098:                        Collection co = node.getDeadlines();
099:                        Iterator it = co.iterator();
100:
101:                        while (it.hasNext()) {
102:                            // the co contains Date elements
103:                            Timestamp date = (java.sql.Timestamp) it.next();
104:                            type = node.getName() + ":"
105:                                    + node.getBnProject().getName() + ":"
106:                                    + date.getTime();
107:                            lNext = date;
108:                            // add notification for each deadline in the collection
109:
110:                            TimerService ts = mContext.getTimerService();
111:                            // addNotification(lNext, type, node);
112:                            // Create the timer with the date
113:                            TimerData info = new TimerData(type, lNext
114:                                    .getTime());
115:                            Timer timer = ts.createTimer(date, info);
116:                            //info.onStart(timer);
117:                            //debug
118:                            //System.out.println("startDeadlines for absolute deadlines: lnext = " + lNext.toString() + " type = " + type + " node = " + node.getName());
119:                        }
120:                    }
121:                    // For relative deadline
122:                    if (node.getRelativeDeadlines().size() != 0) {
123:                        //debug
124:                        //System.out.println("startDeadlines : 	Nb of relative deadlines = " + 	node.getRelativeDeadlines().size());
125:                        Collection co = node.getRelativeDeadlines();
126:                        Iterator it = co.iterator();
127:
128:                        while (it.hasNext()) {
129:                            // the co contains Date elements
130:                            java.sql.Timestamp date = (java.sql.Timestamp) it
131:                                    .next();
132:                            type = node.getName() + ":"
133:                                    + node.getBnProject().getName() + ":"
134:                                    + date.getTime();
135:                            //create EJB timers
136:                            lNext = new Timestamp(new Date().getTime()
137:                                    + date.getTime());
138:                            TimerService ts = mContext.getTimerService();
139:                            TimerData info = new TimerData(type, lNext
140:                                    .getTime());
141:                            Timer timer = ts.createTimer(lNext, info);
142:                            //call method onStart:    not used !
143:                            //info.onStart(timer);
144:                            //debug
145:                            //System.out.println("startDeadlines for relative deadlines: lnext = " + lNext.toString() + " type = " + type + " node = " + node.getName());
146:                        }
147:                    }
148:
149:                } catch (Exception e) {
150:                    throw new HeroException(
151:                            "ProjectSessionBean.startDeadlinesEjbTimers: "
152:                                    + e.getMessage());
153:                }
154:            }
155:
156:            /**
157:             * Stop the EJB timer for node deadline .
158:             *
159:             * @param  projectName the name of the project
160:             * @param  nodeName the name of the node
161:             * @param date date
162:             * @ejb:interface-method view-type="both"
163:             * @ejb:transaction type="Required"
164:             * @throws HeroException
165:             *
166:             **/
167:            public void stopDeadlineEjbTimer(String projectName,
168:                    String nodeName, long date) throws HeroException {
169:                try {
170:                    TimerService ts = mContext.getTimerService();
171:                    Collection timers = ts.getTimers();
172:                    Iterator it = timers.iterator();
173:                    String type = nodeName + ":" + projectName + ":" + date;
174:                    while (it.hasNext()) {
175:                        Timer t = (Timer) it.next();
176:
177:                        if (isCalled(t, type)) {
178:                            TimerData td = (TimerData) t.getInfo();
179:                            td.onStop(t);
180:                        }
181:                    }
182:                } catch (Exception e) {
183:                    throw new HeroException(
184:                            "ProjectSessionBean.stopDeadlineEjbTimer: "
185:                                    + e.getMessage());
186:                }
187:            }
188:
189:            /**
190:             * timeout is called after time duration within timer
191:             *
192:             * @param  Timer timer from the EJB container-managed timer service
193:             * @ejb:interface-method view-type="both"
194:             * @ejb:transaction type="Required"
195:             * @throws HeroException
196:             *
197:             **/
198:            public void ejbTimeout(Timer timer) {
199:                DeadlineSessionLocalHome dlHome = null;
200:                DeadlineSessionLocal dlSession = null;
201:                try {
202:                    dlHome = DeadlineSessionUtil.getLocalHome();
203:                } catch (javax.naming.NamingException ne) {
204:                    System.out
205:                            .println("Error: DeadlineEjbTimerSessionBean: getting DeadlineSessionLocalHome");
206:                }
207:                try {
208:                    dlSession = dlHome.create();
209:                } catch (CreateException he) {
210:                    System.out
211:                            .println("Error: DeadlineEjbTimerSessionBean: creating DeadlineSessionLocal");
212:                }
213:                Object info = timer.getInfo();
214:                //debug
215:                //System.out.println("====> timeoutDeadlineEjbTimer:    has been called !!!!");
216:                if (info != null && info instanceof  TimerData) {
217:                    TimerData td = (TimerData) info;
218:                    /*
219:                    try {
220:                    td.onTimeout(timer);
221:                    } catch (HeroException e) {
222:                    e.printStackTrace();
223:                    }
224:                     */
225:                    try {
226:                        String type = (String) td.getType();
227:                        String projectName = type
228:                                .substring(type.indexOf(":") + 1);
229:                        projectName = projectName.substring(0, projectName
230:                                .indexOf(":"));
231:                        String nodeName = type.substring(0, type.indexOf(":"));
232:                        dlSession.executeHookDeadline(type, projectName,
233:                                nodeName);
234:                    } catch (Exception hh) {
235:                        hh.printStackTrace();
236:                    }
237:                }
238:            }
239:
240:            protected boolean isCalled(Timer t, String timerType)
241:                    throws HeroException {
242:                try {
243:                    Object info = t.getInfo();
244:                    if (info != null && info instanceof  TimerData) {
245:                        TimerData td = (TimerData) info;
246:                        if (td.getType().equals(timerType)) {
247:                            return true;
248:                        }
249:                    }
250:                } catch (Exception e) {
251:                    throw new HeroException(
252:                            "DeadlineEjbTimerSession: Error in isCalled: "
253:                                    + e.getMessage());
254:                }
255:                return false;
256:            }
257:
258:            /**
259:             * Retrieves current timers
260:             *
261:             * @return Collection of <tt>TimerData</tt> objects
262:             * @ejb:interface-method view-type="both"
263:             **/
264:            public Collection getTimers() {
265:                Collection ret = new ArrayList();
266:
267:                // Iterates through all timers
268:                Collection timers = mContext.getTimerService().getTimers();
269:                for (Iterator iterator = timers.iterator(); iterator.hasNext();) {
270:                    Serializable info = ((Timer) iterator.next()).getInfo();
271:
272:                    // Check the Timer info data to increase robustness
273:                    if (info instanceof  TimerData) {
274:                        ret.add(info);
275:                    }
276:                }
277:
278:                return ret;
279:            }
280:
281:            /**
282:             * Remove on going timers for a particular process
283:             *
284:             * @ejb:interface-method view-type="both"
285:             **/
286:            public void removeProjectTimers(String projectName)
287:                    throws HeroException {
288:                Collection timers = mContext.getTimerService().getTimers();
289:                for (Iterator iterator = timers.iterator(); iterator.hasNext();) {
290:                    Timer t = (Timer) iterator.next();
291:                    TimerData td = (TimerData) t.getInfo();
292:                    // Check the Timer info data to increase robustness
293:                    if (td.getType().matches(
294:                            ".*" + ":" + projectName + ":" + ".*")) {
295:                        td.onStop(t);
296:                    }
297:                }
298:            }
299:
300:            public void ejbCreate() throws CreateException {
301:            }
302:
303:            public void setSessionContext(final javax.ejb.SessionContext context) {
304:                mContext = context;
305:            }
306:
307:            public void ejbRemove() {
308:            }
309:
310:            public void ejbActivate() {
311:            }
312:
313:            public void ejbPassivate() {
314:            }
315:
316:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.