📄 launchdispatcher.java
字号:
/* * Copyright (c) 2005, John Mettraux, OpenWFE.org * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * . Redistributions of source code must retain the above copyright notice, this * list of conditions and the following disclaimer. * * . Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * * . Neither the name of the "OpenWFE" nor the names of its contributors may be * used to endorse or promote products derived from this software without * specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * * $Id: LaunchDispatcher.java,v 1.9 2005/05/17 16:40:22 jmettraux Exp $ *///// LaunchDispatcher.java//// jmettraux@openwfe.org//// generated with // jtmpl 1.0.04 20.11.2001 John Mettraux (jmettraux@openwfe.org)//package openwfe.org.engine.dispatch;import openwfe.org.AbstractService;import openwfe.org.ServiceException;import openwfe.org.OpenWfeException;import openwfe.org.ApplicationContext;import openwfe.org.engine.Definitions;import openwfe.org.engine.expool.ExpressionPool;import openwfe.org.engine.workitem.Attribute;import openwfe.org.engine.workitem.WorkItem;import openwfe.org.engine.workitem.LaunchItem;import openwfe.org.engine.workitem.InFlowWorkItem;//import openwfe.org.engine.wfibuilder.WorkflowInstanceBuilder;import openwfe.org.engine.expressions.ReplyException;import openwfe.org.engine.expressions.FlowExpressionId;import openwfe.org.engine.participants.ParticipantMap;import openwfe.org.engine.participants.LeafParticipant;/** * It dispatches workitems through sockets * * <p><font size=2>CVS Info : * <br>$Author: jmettraux $ * <br>$Date: 2005/05/17 16:40:22 $ * <br>$Id: LaunchDispatcher.java,v 1.9 2005/05/17 16:40:22 jmettraux Exp $ </font> * * @author jmettraux@openwfe.org */public class LaunchDispatcher extends AbstractService implements WorkItemDispatcher{ private final static org.apache.log4j.Logger log = org.apache.log4j.Logger .getLogger(LaunchDispatcher.class.getName()); // // CONSTANTS (definitions) // // FIELDS private WorkItemDispatcher finalDispatcher = null; private boolean waitForResult = false; // // CONSTRUCTORS public LaunchDispatcher (WorkItemDispatcher finalDispatcher) { this.finalDispatcher = finalDispatcher; } public void init (final String serviceName, final ApplicationContext context, final java.util.Map serviceParams) throws ServiceException { super.init(serviceName, context, serviceParams); this.waitForResult = waitForResult (serviceParams.get(Definitions.WAIT_FOR_RESULT)); } // // METHODS private boolean waitForResult (Object oWaitForResult) { if (oWaitForResult == null) return false; String sWaitForResult = oWaitForResult.toString(); return ("yes".equalsIgnoreCase(sWaitForResult) || "true".equalsIgnoreCase(sWaitForResult)); } /* * When 'shouldWaitForResult' is set to false, * this method allows to directly continue the current flow */ private void continueCurrentFlowDirectly (InFlowWorkItem wi) throws DispatchingException { FlowExpressionId id = wi.getLastExpressionId(); try { Definitions .getExpressionPool(getContext()) .reply(id, wi); } catch (ReplyException re) { throw new DispatchingException ("Failed to continue current flow directly", re); } log.debug ("Continued current flow directly for "+id); } /** * dispatches workitem (launches flow) */ public Object dispatch (WorkItem wi) throws DispatchingException { if (wi == null) { throw new DispatchingException ("Cannot handle null workitem !"); } if ( ! (wi instanceof InFlowWorkItem)) { throw new DispatchingException ("dispatching of LaunchItem instances not supported "+ "by this dispatcher"); } InFlowWorkItem iwi = (InFlowWorkItem)wi; // // determine wf to launch // // precedence : wfd > pmap > wi // from wi String wfdUrl = null; Attribute aWfdUrl = iwi.getAttribute(Definitions.WORKFLOW_DEFINITION_URL); if (aWfdUrl != null) wfdUrl = aWfdUrl.toString(); boolean shouldWaitForResult = waitForResult (wi.getAttribute(Definitions.WAIT_FOR_RESULT)); // from pmap String participantName = (String)getParams().get(LeafParticipant.PARTICIPANT_NAME); if (wfdUrl == null) { final ParticipantMap pMap = Definitions .getParticipantMap(getContext()); LeafParticipant p = (LeafParticipant)pMap.get(participantName); wfdUrl = (String)p.getParams() .get(Definitions.WORKFLOW_DEFINITION_URL); shouldWaitForResult = waitForResult((String)p.getParams() .get(Definitions.WAIT_FOR_RESULT)); } // from wfd if (wfdUrl == null) { wfdUrl = (String)getParams() .get(Definitions.WORKFLOW_DEFINITION_URL); shouldWaitForResult = waitForResult((String)getParams() .get(Definitions.WAIT_FOR_RESULT)); } if (wfdUrl == null) { throw new DispatchingException ("Couldn't determine target flow. "+ "Declare it either in WI, PMAP or WFD."); } // // determine replyTo FlowExpressionId replyTo = null; if (shouldWaitForResult) // // launch subflow (its end will resume the current flow) { replyTo = iwi.getLastExpressionId(); } // // prepare launchItem final LaunchItem li = new LaunchItem (wfdUrl, replyTo, iwi); // // prepare dispatcher // (if there is no 'finalDispatcher' or if it's for the same engine, // dispatch locally) //String engineId = (String)getContext().get(Definitions.ENGINE_ID); final String engineId = getContext().getApplicationName(); /* if (engineId == null) { throw new DispatchingException ("Parameter '"+Definitions.ENGINE_ID+ "' is missing in engine configuration, it should be set "+ "to the engine's participantName. Cannot launch any flow."); } */ if (this.finalDispatcher == null || engineId.equals(participantName)) { String flowInstanceId = null; try { flowInstanceId = Definitions .getLauncher(getContext()) .launch(li); } catch (OpenWfeException owe) { throw new DispatchingException ("Failed to launch subflow", owe); } if ( ! shouldWaitForResult) continueCurrentFlowDirectly(iwi); return flowInstanceId; } // // dispatch ( <=> launch) // instantiate finalDispatcher try { this.finalDispatcher.init (getName()+".finalDispatcher", getContext(), getParams()); } catch (Exception e) { throw new DispatchingException ("Failed to build and init finalDispatcher '"+ this.finalDispatcher.getClass().getName()+ "' for participant '"+getName()+"'", e); } // give launchItem to the finalDispatcher this.finalDispatcher.dispatch(li); continueCurrentFlowDirectly(iwi); return null; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -