Source Code Cross Referenced for Dispatcher.java in  » Workflow-Engines » bexee » bexee » core » 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 » bexee » bexee.core 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * $Id: Dispatcher.java,v 1.11 2004/12/09 12:34:18 kowap Exp $
003:         *
004:         * Copyright (c) 2004 Patric Fornasier, Pawel Kowalski
005:         * Berne University of Applied Sciences
006:         * School of Engineering and Information Technology
007:         * All rights reserved.
008:         */
009:        package bexee.core;
010:
011:        import org.apache.commons.logging.Log;
012:        import org.apache.commons.logging.LogFactory;
013:
014:        import bexee.dao.BPELProcessDAO;
015:        import bexee.dao.DAOException;
016:        import bexee.dao.DAOFactory;
017:        import bexee.model.process.BPELProcess;
018:
019:        /**
020:         * This class is used to lookup or create a <code>ProcessInstance</code> given
021:         * an inbound <code>BexeeMessage</code> and dispatch the message to the
022:         * {@link bexee.core.ProcessController}either synchronously or asynchronoulsy.
023:         * <p>
024:         * To do this, create the object and then use its {@link #dispatch()}method.
025:         * <p>
026:         * When the <code>Dispatcher</code> kicks off the
027:         * <code>ProcessController</code> it will know, whether a synchronous or
028:         * asynchronous BPEL process is to be started. Depending on that it will either
029:         * return right away after starting the process for an asynchronous BPEL process
030:         * or it will wait until the result is available for a synchronous BPEL process.
031:         * <p>
032:         * Either way the <code>ProcessController</code>'s
033:         * <code>processMessage()</code> method is started in a new Thread, but in
034:         * case of a synchronous BPEL process the <code>Dispatcher</code> will wait
035:         * until the result is available. This happens by obtaining a lock on the
036:         * <code>ProcessContext</code>, which will notify the <code>Dispatcher</code>
037:         * when the result is available.
038:         * 
039:         * @version $Revision: 1.11 $, $Date: 2004/12/09 12:34:18 $
040:         * @author Patric Fornasier
041:         * @author Pawel Kowalski
042:         */
043:        public class Dispatcher extends Thread {
044:
045:            /**
046:             * Result when processing an asynchronous result. This might change in
047:             * future versions.
048:             */
049:            public static final String ASYNC_RESULT = "Processing request...";
050:
051:            protected ProcessController controller;
052:
053:            protected ProcessInstance instance;
054:
055:            protected BexeeMessage message;
056:
057:            private static Log log = LogFactory.getLog(Dispatcher.class);
058:
059:            /**
060:             * Creates a new <code>Dispatcher</code> object.
061:             * 
062:             * @param message
063:             *            the incoming message
064:             */
065:            public Dispatcher(BexeeMessage message) {
066:                this .message = message;
067:
068:                // get BPELProcess and ProcessContext for incoming message
069:                BPELProcess process = getBPELProcess(message);
070:                ProcessContext ctx = getProcessContext(message);
071:
072:                // create instance from BPELProcess and ProcessContext
073:                instance = new ProcessInstance(process, ctx);
074:
075:                // create process controller
076:                controller = ProcessControllerFactory.createProcessController();
077:            }
078:
079:            /**
080:             * Calls the {@link ProcessController}s
081:             * {@link ProcessController#processMessage(ProcessInstance, BexeeMessage)}
082:             * method either synchronously or asynchronously.
083:             * <p>
084:             * Note that this method may take minutes or hours for long-running
085:             * synchronous processes.
086:             * 
087:             * @return the result
088:             * @throws DispatcherException
089:             *             If something went wrong dispatching the message. This can
090:             *             happen for example if the <code>BPELProcess</code> or the
091:             *             <code>ProcessContext</code> can't be found or created or if
092:             *             something went wrong processing the message in the
093:             *             <code>ProcessController</code>.
094:             */
095:            public Object dispatch() throws DispatcherException {
096:
097:                Object result = null;
098:
099:                // get BPEL process and process context from process instance
100:                ProcessContext ctx = instance.getContext();
101:                BPELProcess process = instance.getProcess();
102:
103:                // check if a context was found or created
104:                if (ctx == null) {
105:                    throw new DispatcherException("No context found");
106:                }
107:
108:                // check if a process was found or created
109:                if (process == null) {
110:                    throw new DispatcherException("No process found");
111:                }
112:
113:                // start processing
114:                start();
115:
116:                // if we have a synchronous process, wait until result is available
117:                if (process.isSynchronous()) {
118:                    synchronized (ctx) {
119:                        try {
120:                            // wait until the process has finished and get the result
121:                            ctx.wait();
122:                            result = ctx.getResult();
123:                        } catch (InterruptedException e) {
124:                            throw new DispatcherException(
125:                                    "Dispatcher interrupted", e);
126:                        }
127:                    }
128:                } else {
129:                    // TODO do we need to give something back here?
130:                    result = ASYNC_RESULT;
131:                }
132:
133:                return result;
134:            }
135:
136:            /**
137:             * Do not use this method directly. Use {@link #dispatch()}instead.
138:             */
139:            public void run() {
140:                controller.processMessage(instance, message);
141:            }
142:
143:            /**
144:             * Gets the <code>ProcessContext</code> belonging to the incoming message.
145:             * 
146:             * @param message
147:             *            the incoming message
148:             * @return a new <code>ProcessContext</code> if there is currently no
149:             *         process running or the <code>ProcessContext</code> instance
150:             *         belonging to the incoming message if there is a process running
151:             *         already.
152:             */
153:            protected ProcessContext getProcessContext(BexeeMessage message) {
154:
155:                ProcessContext ctx = null;
156:
157:                /*
158:                 * TODO Correlation stuff for finding a running process context. Right
159:                 * now this isn't supported, so we create a new instance each time.
160:                 */
161:                ctx = new ProcessContext();
162:
163:                return ctx;
164:            }
165:
166:            /**
167:             * Gets the <code>BPELProcess</code> belonging to the incoming message.
168:             * 
169:             * @param message
170:             *            the incoming message
171:             * @return the <code>BPELProcess</code> that will be identified by the
172:             *         incoming message or null if it can't be found.
173:             */
174:            protected BPELProcess getBPELProcess(BexeeMessage message) {
175:
176:                BPELProcess process = null;
177:                String name = message.getService();
178:
179:                DAOFactory factory = DAOFactory.getInstance();
180:                BPELProcessDAO bpelDAO = factory.createBPELProcessDAO();
181:
182:                try {
183:                    process = bpelDAO.find(name);
184:                } catch (DAOException e) {
185:                    log.info("Error trying to find process", e);
186:                }
187:
188:                return process;
189:            }
190:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.