001: /*
002: * This file is part of the WfMOpen project.
003: * Copyright (C) 2001-2003 Danet GmbH (www.danet.de), GS-AN.
004: * All rights reserved.
005: *
006: * This program is free software; you can redistribute it and/or modify
007: * it under the terms of the GNU General Public License as published by
008: * the Free Software Foundation; either version 2 of the License, or
009: * (at your option) any later version.
010: *
011: * This program 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
014: * GNU General Public License for more details.
015: *
016: * You should have received a copy of the GNU General Public License
017: * along with this program; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
019: *
020: * $Id: DefaultToolInvocationHandler.java,v 1.7 2007/07/08 20:35:01 mlipp Exp $
021: *
022: * $Log: DefaultToolInvocationHandler.java,v $
023: * Revision 1.7 2007/07/08 20:35:01 mlipp
024: * Even more usage of local EJB interfaces.
025: *
026: * Revision 1.6 2007/05/03 21:58:16 mlipp
027: * Internal refactoring for making better use of local EJBs.
028: *
029: * Revision 1.5 2007/03/27 21:59:43 mlipp
030: * Fixed lots of checkstyle warnings.
031: *
032: * Revision 1.4 2006/09/29 12:32:10 drmlipp
033: * Consistently using WfMOpen as projct name now.
034: *
035: * Revision 1.3 2005/08/25 13:24:22 drmlipp
036: * Synchronized with 1.3.1p6.
037: *
038: * Revision 1.2.2.1 2005/08/24 14:14:52 drmlipp
039: * Started implementation of exception mapping.
040: *
041: * Revision 1.2 2005/01/07 14:58:59 drmlipp
042: * Made Queuer EJB a local EJB. Not expecting significant performance
043: * gains from this ;-), but it is somehow makes sense.
044: *
045: * Revision 1.1.1.1 2004/08/18 15:17:38 drmlipp
046: * Update to 1.2
047: *
048: * Revision 1.4 2004/07/13 14:59:12 lipp
049: * Added possibility to get activity's container without involving
050: * activity in current transaction.
051: *
052: * Revision 1.3 2004/07/11 19:58:02 lipp
053: * Fixed problem with getEJBObject not returning a NoSuchObjectException.
054: *
055: * Revision 1.2 2004/04/12 19:33:52 lipp
056: * Clarified application invocation interface.
057: *
058: * Revision 1.1 2004/02/21 21:31:00 lipp
059: * Some more refactoring to resolve cyclic dependencies.
060: *
061: * Revision 1.17 2004/02/20 15:57:06 lipp
062: * Adedd repeating invocation for TransactionRolledbackLocalException.
063: *
064: * Revision 1.16 2003/12/08 14:08:13 lipp
065: * Execute tool termination in own transaction.
066: *
067: * Revision 1.15 2003/11/18 14:32:12 lipp
068: * Removed tool invocation optimization (may be re-introduced later).
069: *
070: * Revision 1.14 2003/10/25 21:00:15 lipp
071: * Made AuditEventQueuer the general queuer.
072: *
073: * Revision 1.13 2003/06/27 08:51:45 lipp
074: * Fixed copyright/license information.
075: *
076: * Revision 1.12 2003/05/06 13:21:30 lipp
077: * Resolved cyclic dependency.
078: *
079: * Revision 1.11 2003/05/02 14:55:58 lipp
080: * Resolved some more package dependencies.
081: *
082: * Revision 1.10 2003/03/31 16:50:28 huaiyang
083: * Logging using common-logging.
084: *
085: * Revision 1.9 2002/12/19 21:37:42 lipp
086: * Reorganized interfaces.
087: *
088: * Revision 1.8 2002/11/26 11:23:29 lipp
089: * Modified RemoteException comment.
090: *
091: * Revision 1.7 2002/10/08 13:52:36 lipp
092: * Merged branch new-state-handling.
093: *
094: * Revision 1.6.2.1 2002/10/08 13:04:35 lipp
095: * Reimplementing state handling, activity start to complete cycle.
096: *
097: * Revision 1.6 2002/10/02 20:54:40 lipp
098: * Event handling partially reorganized.
099: *
100: * Revision 1.5 2002/10/02 10:58:13 lipp
101: * Modifications for tool invocation.
102: *
103: * Revision 1.4 2002/09/26 20:03:36 lipp
104: * Reorganized tool invocation.
105: *
106: * Revision 1.3 2002/09/26 15:26:23 lipp
107: * Temporarily disabled new invocation mode.
108: *
109: * Revision 1.2 2002/09/26 15:11:36 lipp
110: * Extended tool invocation.
111: *
112: * Revision 1.1 2002/09/25 15:16:34 lipp
113: * Reorganized tool invocation layer dependencies.
114: *
115: */
116: package de.danet.an.workflow.ejbs.core;
117:
118: import java.util.HashMap;
119: import java.util.Map;
120:
121: import java.rmi.RemoteException;
122:
123: import javax.ejb.EJBException;
124: import javax.ejb.EJBObject;
125:
126: import de.danet.an.workflow.api.Activity;
127: import de.danet.an.workflow.api.ActivityUniqueKey;
128: import de.danet.an.workflow.apix.ExtActivity;
129: import de.danet.an.workflow.domain.ToolInvocationHandler;
130:
131: import de.danet.an.workflow.ejbs.admin.WorkflowEngineLocal;
132: import de.danet.an.workflow.ejbs.util.ApplInvokerEJB;
133: import de.danet.an.workflow.ejbs.util.QueuerLocal;
134: import de.danet.an.workflow.internalapi.ExtApplication;
135: import de.danet.an.workflow.spis.aii.ApplicationNotStoppedException;
136:
137: /**
138: * This class provides a JMS/EJB based invocation handler that supports
139: * asynchronous invocation and invocation in a separate transaction.
140: *
141: * @author <a href="mailto:lipp@danet.de"></a>
142: * @version $Revision: 1.7 $
143: */
144:
145: public class DefaultToolInvocationHandler implements
146: ToolInvocationHandler {
147:
148: private static final org.apache.commons.logging.Log logger = org.apache.commons.logging.LogFactory
149: .getLog(DefaultToolInvocationHandler.class);
150:
151: private WorkflowEngineLocal engine = null;
152: private QueuerLocal queuer = null;
153:
154: /**
155: * Creates an instance of
156: * <code>DefaultToolInvocationHandler</code>.
157: * @param theEngine the engine to be used
158: * @param theQueuer the queuer to be used
159: */
160: public DefaultToolInvocationHandler(WorkflowEngineLocal theEngine,
161: QueuerLocal theQueuer) {
162: engine = theEngine;
163: queuer = theQueuer;
164: }
165:
166: /**
167: * Invoke the tool.
168: *
169: * @param appl the application description of the tool.
170: * @param auk the activity's unique key.
171: * @param act the <code>WfActivity</code>.
172: * @param params the invocation parameters.
173: */
174: public void invoke(ExtApplication appl, ActivityUniqueKey auk,
175: ExtActivity act, Map params) {
176: if (appl.isDirectInvocable()) {
177: if (logger.isDebugEnabled()) {
178: logger.debug("Invoking " + appl + " directly");
179: }
180: try {
181: ApplInvokerEJB.doInvoke(engine, queuer, act, appl,
182: params, false);
183: } catch (RemoteException e) {
184: throw new EJBException(e);
185: }
186: return;
187: }
188: if (logger.isDebugEnabled()) {
189: logger.debug("Invoking " + appl + " using queue");
190: }
191: Map args = new HashMap();
192: args.put("appl", appl);
193: args.put("params", params);
194: Object ah = null;
195: try {
196: if (act instanceof EJBObject) {
197: ah = ((ActivityProxy) ActivityProxy.wrap(act, true))
198: .getRefInfo();
199: } else if (act instanceof ActivityProxy) {
200: ah = ((ActivityProxy) act).getRefInfo();
201: } else {
202: logger
203: .error("Object of invalid type passed as activity: "
204: + act.getClass());
205: }
206: } catch (RemoteException e) {
207: throw new EJBException(e);
208: }
209: args.put("activity", ah);
210: args.put("activityUniqueKey", auk);
211: queuer.queueToolInvocation(args);
212: }
213:
214: /**
215: * Terminate the tool.
216: *
217: * @param appl the application description of the tool.
218: * @param act the <code>WfActivity</code>.
219: * @throws ApplicationNotStoppedException if termination is not possible.
220: */
221: public void terminate(ExtApplication appl, Activity act)
222: throws ApplicationNotStoppedException {
223: while (true) {
224: try {
225: engine.doTerminateLocal(appl, act);
226: break;
227: } catch (EJBException e) {
228: logger.warn("Error while terminating, repeating: "
229: + e.getMessage());
230: }
231: }
232: }
233: }
|