You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ode.apache.org by ms...@apache.org on 2006/08/14 17:42:05 UTC
svn commit: r431370 [2/4] - in /incubator/ode/trunk:
axis2/src/main/java/org/apache/ode/axis2/ bpel-api/
bpel-api/src/main/java/org/apache/ode/bpel/dao/
bpel-api/src/main/java/org/apache/ode/bpel/iapi/ bpel-dd/
bpel-dd/src/main/xsd/ bpel-runtime/ bpel-...
Modified: incubator/ode/trunk/bpel-runtime/src/main/java/org/apache/ode/bpel/engine/BpelEngineImpl.java
URL: http://svn.apache.org/viewvc/incubator/ode/trunk/bpel-runtime/src/main/java/org/apache/ode/bpel/engine/BpelEngineImpl.java?rev=431370&r1=431369&r2=431370&view=diff
==============================================================================
--- incubator/ode/trunk/bpel-runtime/src/main/java/org/apache/ode/bpel/engine/BpelEngineImpl.java (original)
+++ incubator/ode/trunk/bpel-runtime/src/main/java/org/apache/ode/bpel/engine/BpelEngineImpl.java Mon Aug 14 08:42:03 2006
@@ -19,6 +19,15 @@
package org.apache.ode.bpel.engine;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.wsdl.Operation;
+import javax.wsdl.PortType;
+import javax.xml.namespace.QName;
+
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.ode.bpel.dao.MessageExchangeDAO;
@@ -26,257 +35,210 @@
import org.apache.ode.bpel.dao.ProcessInstanceDAO;
import org.apache.ode.bpel.iapi.BpelEngine;
import org.apache.ode.bpel.iapi.BpelEngineException;
-import org.apache.ode.bpel.iapi.EndpointReference;
+import org.apache.ode.bpel.iapi.Endpoint;
import org.apache.ode.bpel.iapi.Message;
import org.apache.ode.bpel.iapi.MessageExchange;
-import org.apache.ode.bpel.iapi.MessageExchange.MessageExchangePattern;
-import org.apache.ode.bpel.iapi.MessageExchange.Status;
import org.apache.ode.bpel.iapi.MessageExchangeInterceptor;
import org.apache.ode.bpel.iapi.MyRoleMessageExchange;
+import org.apache.ode.bpel.iapi.MessageExchange.MessageExchangePattern;
+import org.apache.ode.bpel.iapi.MessageExchange.Status;
import org.apache.ode.bpel.iapi.MyRoleMessageExchange.CorrelationStatus;
import org.apache.ode.bpel.o.OPartnerLink;
import org.apache.ode.bpel.o.OProcess;
-import org.apache.ode.bpel.runtime.ExpressionLanguageRuntimeRegistry;
import org.apache.ode.utils.msg.MessageBundle;
-import org.w3c.dom.Element;
-
-import javax.wsdl.Operation;
-import javax.wsdl.PortType;
-import javax.xml.namespace.QName;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
/**
* Implementation of the {@link BpelEngine} interface: provides the server
* methods that should be invoked in the context of a transaction.
+ *
* @author mszefler
- *
+ *
*/
public class BpelEngineImpl implements BpelEngine {
- private static final Log __log = LogFactory.getLog(BpelEngineImpl.class);
+ private static final Log __log = LogFactory.getLog(BpelEngineImpl.class);
+
+ private static final Messages __msgs = MessageBundle.getMessages(Messages.class);
+
+ /** Active processes, keyed by process id. */
+ final HashMap<QName, BpelProcess> _activeProcesses = new HashMap<QName, BpelProcess>();
- private static final Messages __msgs = MessageBundle
- .getMessages(Messages.class);
+ /** Mapping from myrole endpoint name to active process. */
+ private final HashMap<Endpoint, BpelProcess> _serviceMap = new HashMap<Endpoint, BpelProcess>();
+
+ final Contexts _contexts;
+
+ public BpelEngineImpl(Contexts contexts) {
+ _contexts = contexts;
+ }
- /**
- * Active processes, keyed by process id.
- */
- final HashMap<QName, BpelProcess> _activeProcesses = new HashMap<QName, BpelProcess>();
-
- /**
- * Active processes, keyed by myRole endpoint. NOTE: this is not being used at
- * this point.
- */
- final HashMap<EndpointReference, BpelProcess> _eprToProcessMap = new HashMap<EndpointReference, BpelProcess>();
-
- /** Mapping from service name to active process. */
- private final HashMap<QName, BpelProcess> _serviceMap = new HashMap<QName,BpelProcess>();
-
- final Contexts _contexts;
-
-
-
- public BpelEngineImpl(Contexts contexts) {
- _contexts = contexts;
- }
-
- public boolean isMyRoleEndpoint(EndpointReference epr)
- throws BpelEngineException {
- return _eprToProcessMap.containsKey(epr);
- }
-
- public MyRoleMessageExchange createMessageExchange(
- String clientKey,
- QName targetService,
- EndpointReference epr,
- String operation) throws BpelEngineException {
-
- MessageExchangeDAO dao = _contexts.dao.getConnection()
- .createMessageExchange(MessageExchangeDAO.DIR_PARTNER_INVOKES_MYROLE);
- dao.setCorrelationId(clientKey);
- dao.setCorrelationStatus(CorrelationStatus.UKNOWN_ENDPOINT.toString());
- dao.setPattern(MessageExchangePattern.UNKNOWN.toString());
- dao.setCallee(targetService);
- dao.setStatus(Status.NEW.toString());
- dao.setOperation(operation);
- dao.setEPR(epr == null ? null : epr.toXML().getDocumentElement());
- MyRoleMessageExchangeImpl mex = new MyRoleMessageExchangeImpl(this, dao);
-
- BpelProcess target = route(targetService, null);
- if (target != null)
- target.initMyRoleMex(mex);
-
- return mex;
- }
-
- public MessageExchange getMessageExchange(String mexId)
- throws BpelEngineException {
- MessageExchangeDAO mexdao = _contexts.dao.getConnection()
- .getMessageExchange(mexId);
- if (mexdao == null)
- return null;
-
- ProcessDAO pdao = mexdao.getProcess();
- BpelProcess process = pdao == null ? null : _activeProcesses.get(pdao
- .getProcessId());
-
- MessageExchangeImpl mex;
- switch (mexdao.getDirection()) {
- case MessageExchangeDAO.DIR_BPEL_INVOKES_PARTNERROLE:
- if (process == null) {
- String errmsg = __msgs.msgProcessNotActive(pdao.getProcessId());
- __log.error(errmsg);
- // TODO: Perhaps we should define a checked exception for this
- // condition.
- throw new BpelEngineException(errmsg);
- } else {
- OPartnerLink plink = (OPartnerLink) process._oprocess.getChild(mexdao
- .getPartnerLinkModelId());
- PortType ptype = plink.partnerRolePortType;
- Operation op = plink.getPartnerRoleOperation(mexdao.getOperation());
- mex = new PartnerRoleMessageExchangeImpl(this, mexdao, ptype, op, null);
- }
- break;
- case MessageExchangeDAO.DIR_PARTNER_INVOKES_MYROLE:
- mex = new MyRoleMessageExchangeImpl(this, mexdao);
- if (process != null) {
- OPartnerLink plink = (OPartnerLink) process._oprocess.getChild(mexdao
- .getPartnerLinkModelId());
- PortType ptype = plink.myRolePortType;
- Operation op = plink.getMyRoleOperation(mexdao.getOperation());
- mex.setPortOp(ptype, op);
- }
- break;
- default:
- String errmsg = "BpelEngineImpl: internal error, invalid MexDAO direction: "
- + mexId;
- __log.fatal(errmsg);
- throw new BpelEngineException(errmsg);
- }
-
- if (process != null)
- mex.setProcess(process._oprocess);
-
- return mex;
- }
-
- boolean unregisterProcess(QName process) {
- BpelProcess p = _activeProcesses.remove(process);
- if (p != null) {
- p.deactivate();
- _eprToProcessMap.values().remove(p);
- _serviceMap.values().remove(p);
- }
- return p != null;
- }
-
- boolean isProcessRegistered(QName pid) {
- return _activeProcesses.containsKey(pid);
- }
-
- void registerProcess(QName pid,
- OProcess compiledProcess,
- Map<Integer,QName> serviceNames,
- Map<Integer,Element> myEprs,
- ExpressionLanguageRuntimeRegistry elangRegistry) {
- BpelProcess process = new BpelProcess(this, pid, compiledProcess,
- serviceNames,
- myEprs,
- null,
- elangRegistry);
- _activeProcesses.put(pid, process);
- for (QName sn : serviceNames.values()) {
- __log.debug( "Register process: serviceId=" + sn + ", process=" + process );
- _serviceMap.put(sn,process);
- }
-
- process.activate();
- }
-
- void addRoute(EndpointReference epr, QName pid) {
- BpelProcess target = _activeProcesses.get(pid);
- if (target == null)
- throw new IllegalArgumentException("Process " + pid + " is not active.");
- _eprToProcessMap.put(epr, target);
- }
-
- void delRoute(EndpointReference epr) {
- _eprToProcessMap.remove(epr);
-
- }
-
- /**
- * Route to a process using the service id. Note, that we do not need the
- * endpoint name here, we are assuming that two processes would not be
- * registered under the same service qname but different endpoint.
- *
- * @param service target service id
- * @param request request message
- * @return process corresponding to the targetted service, or <code>null</code>
- * if service identifier is not recognized.
- */
- BpelProcess route(QName service, Message request) {
- // TODO: use the message to route to the correct service if more than one
- // service is listening on the same endpoint.
-
- BpelProcess routed = _serviceMap.get(service);
- if (__log.isDebugEnabled())
- __log.debug("Routed: svcQname " +service + " --> " + routed);
- return routed;
-
- }
-
-
- OProcess getOProcess(QName processId) {
- return _activeProcesses.get(processId)._oprocess;
- }
-
- public void onScheduledJob(String jobId, Map<String, Object> jobDetail) {
-
- WorkEvent we = new WorkEvent(jobDetail);
-
- ProcessInstanceDAO instance = _contexts.dao.getConnection().getInstance(
- we.getIID());
- if (instance == null) {
- __log.error(__msgs.msgScheduledJobReferencesUnknownInstance(we.getIID()));
- // nothing we can do, this instance is not in the database, it will always
- // fail.
- return;
- }
-
- ProcessDAO processDao = instance.getProcess();
- BpelProcess process = _activeProcesses.get(processDao.getProcessId());
- if (process == null) {
- // If the process is not active, it means that we should not be doing
- // any work on its behalf, therefore we will reschedule the events
- // for some time in the future (1 minute).
- Date future = new Date(System.currentTimeMillis() + (60 * 1000));
- __log.info(__msgs.msgReschedulingJobForInactiveProcess(processDao
- .getProcessId(), jobId, future));
- _contexts.scheduler.schedulePersistedJob(jobDetail, future);
- }
-
- assert process != null;
- process.handleWorkEvent(jobDetail);
- }
-
-
- public MessageExchange getMessageExchangeByClientKey(String clientKey) {
- // TODO Auto-generated method stub
- return null;
- }
-
- /**
- * Get the list of globally-registered message-exchange interceptors.
- * @return
- */
- List<MessageExchangeInterceptor> getGlobalInterceptors() {
- return _contexts.globalIntereceptors;
- }
+ public MyRoleMessageExchange createMessageExchange(String clientKey, QName targetService, String operation)
+ throws BpelEngineException {
+ MessageExchangeDAO dao = _contexts.dao.getConnection().createMessageExchange(
+ MessageExchangeDAO.DIR_PARTNER_INVOKES_MYROLE);
+ dao.setCorrelationId(clientKey);
+ dao.setCorrelationStatus(CorrelationStatus.UKNOWN_ENDPOINT.toString());
+ dao.setPattern(MessageExchangePattern.UNKNOWN.toString());
+ dao.setCallee(targetService);
+ dao.setStatus(Status.NEW.toString());
+ dao.setOperation(operation);
+ MyRoleMessageExchangeImpl mex = new MyRoleMessageExchangeImpl(this, dao);
+
+ BpelProcess target = route(targetService, null);
+ if (target != null)
+ target.initMyRoleMex(mex);
+
+ return mex;
+ }
+
+ public MessageExchange getMessageExchange(String mexId) throws BpelEngineException {
+ MessageExchangeDAO mexdao = _contexts.dao.getConnection().getMessageExchange(mexId);
+ if (mexdao == null)
+ return null;
+
+ ProcessDAO pdao = mexdao.getProcess();
+ BpelProcess process = pdao == null ? null : _activeProcesses.get(pdao.getProcessId());
+
+ MessageExchangeImpl mex;
+ switch (mexdao.getDirection()) {
+ case MessageExchangeDAO.DIR_BPEL_INVOKES_PARTNERROLE:
+ if (process == null) {
+ String errmsg = __msgs.msgProcessNotActive(pdao.getProcessId());
+ __log.error(errmsg);
+ // TODO: Perhaps we should define a checked exception for this
+ // condition.
+ throw new BpelEngineException(errmsg);
+ } else {
+ OPartnerLink plink = (OPartnerLink) process._oprocess.getChild(mexdao.getPartnerLinkModelId());
+ PortType ptype = plink.partnerRolePortType;
+ Operation op = plink.getPartnerRoleOperation(mexdao.getOperation());
+ mex = new PartnerRoleMessageExchangeImpl(this, mexdao, ptype, op, null);
+ }
+ break;
+ case MessageExchangeDAO.DIR_PARTNER_INVOKES_MYROLE:
+ mex = new MyRoleMessageExchangeImpl(this, mexdao);
+ if (process != null) {
+ OPartnerLink plink = (OPartnerLink) process._oprocess.getChild(mexdao.getPartnerLinkModelId());
+ PortType ptype = plink.myRolePortType;
+ Operation op = plink.getMyRoleOperation(mexdao.getOperation());
+ mex.setPortOp(ptype, op);
+ }
+ break;
+ default:
+ String errmsg = "BpelEngineImpl: internal error, invalid MexDAO direction: " + mexId;
+ __log.fatal(errmsg);
+ throw new BpelEngineException(errmsg);
+ }
+
+ if (process != null)
+ mex.setProcess(process._oprocess);
+
+ return mex;
+ }
+
+ boolean unregisterProcess(QName process) {
+ BpelProcess p = _activeProcesses.remove(process);
+ if (p != null) {
+ p.deactivate();
+ while (_serviceMap.values().remove(p))
+ ;
+ }
+ return p != null;
+ }
+
+ boolean isProcessRegistered(QName pid) {
+ return _activeProcesses.containsKey(pid);
+ }
+
+ /**
+ * Register a process with the engine.
+ *
+ * @param process
+ * the process to register
+ */
+ void registerProcess(BpelProcess process) {
+
+ process._engine = this;
+
+ _activeProcesses.put(process.getPID(), process);
+ for (Endpoint e : process.getServiceNames()) {
+ __log.debug("Register process: serviceId=" + e + ", process=" + process);
+ _serviceMap.put(e, process);
+ }
+ process.activate();
+ }
+
+ /**
+ * Route to a process using the service id. Note, that we do not need the
+ * endpoint name here, we are assuming that two processes would not be
+ * registered under the same service qname but different endpoint.
+ *
+ * @param service
+ * target service id
+ * @param request
+ * request message
+ * @return process corresponding to the targetted service, or
+ * <code>null</code> if service identifier is not recognized.
+ */
+ BpelProcess route(QName service, Message request) {
+ // TODO: use the message to route to the correct service if more than
+ // one
+ // service is listening on the same endpoint.
+
+ BpelProcess routed = _serviceMap.get(service);
+ if (__log.isDebugEnabled())
+ __log.debug("Routed: svcQname " + service + " --> " + routed);
+ return routed;
+
+ }
+
+ OProcess getOProcess(QName processId) {
+ // TODO Auto-generated method stub
+ throw new UnsupportedOperationException("todo");
+ }
+
+ public void onScheduledJob(String jobId, Map<String, Object> jobDetail) {
+
+ WorkEvent we = new WorkEvent(jobDetail);
+
+ ProcessInstanceDAO instance = _contexts.dao.getConnection().getInstance(we.getIID());
+ if (instance == null) {
+ __log.error(__msgs.msgScheduledJobReferencesUnknownInstance(we.getIID()));
+ // nothing we can do, this instance is not in the database, it will
+ // always
+ // fail.
+ return;
+ }
+
+ ProcessDAO processDao = instance.getProcess();
+ BpelProcess process = _activeProcesses.get(processDao.getProcessId());
+ if (process == null) {
+ // If the process is not active, it means that we should not be
+ // doing
+ // any work on its behalf, therefore we will reschedule the events
+ // for some time in the future (1 minute).
+ Date future = new Date(System.currentTimeMillis() + (60 * 1000));
+ __log.info(__msgs.msgReschedulingJobForInactiveProcess(processDao.getProcessId(), jobId, future));
+ _contexts.scheduler.schedulePersistedJob(jobDetail, future);
+ }
+
+ assert process != null;
+ process.handleWorkEvent(jobDetail);
+ }
+
+ public MessageExchange getMessageExchangeByClientKey(String clientKey) {
+ // TODO: implement me.
+ throw new UnsupportedOperationException("Todo: implementme");
+ }
+
+ /**
+ * Get the list of globally-registered message-exchange interceptors.
+ *
+ * @return
+ */
+ List<MessageExchangeInterceptor> getGlobalInterceptors() {
+ return _contexts.globalIntereceptors;
+ }
}
Modified: incubator/ode/trunk/bpel-runtime/src/main/java/org/apache/ode/bpel/engine/BpelProcess.java
URL: http://svn.apache.org/viewvc/incubator/ode/trunk/bpel-runtime/src/main/java/org/apache/ode/bpel/engine/BpelProcess.java?rev=431370&r1=431369&r2=431370&view=diff
==============================================================================
--- incubator/ode/trunk/bpel-runtime/src/main/java/org/apache/ode/bpel/engine/BpelProcess.java (original)
+++ incubator/ode/trunk/bpel-runtime/src/main/java/org/apache/ode/bpel/engine/BpelProcess.java Mon Aug 14 08:42:03 2006
@@ -36,12 +36,6 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.w3c.dom.Element;
-import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
-import org.w3c.dom.Text;
-
-import org.apache.ode.jacob.soup.ReplacementMap;
import org.apache.ode.bpel.common.CorrelationKey;
import org.apache.ode.bpel.common.FaultException;
import org.apache.ode.bpel.common.InvalidMessageException;
@@ -49,13 +43,18 @@
import org.apache.ode.bpel.dao.MessageRouteDAO;
import org.apache.ode.bpel.dao.ProcessDAO;
import org.apache.ode.bpel.dao.ProcessInstanceDAO;
+import org.apache.ode.bpel.epr.WSAEndpoint;
import org.apache.ode.bpel.evt.CorrelationMatchEvent;
import org.apache.ode.bpel.evt.CorrelationNoMatchEvent;
import org.apache.ode.bpel.evt.NewProcessInstanceEvent;
import org.apache.ode.bpel.explang.EvaluationException;
import org.apache.ode.bpel.iapi.BpelEngineException;
+import org.apache.ode.bpel.iapi.DeploymentUnit;
+import org.apache.ode.bpel.iapi.Endpoint;
import org.apache.ode.bpel.iapi.EndpointReference;
import org.apache.ode.bpel.iapi.MessageExchange;
+import org.apache.ode.bpel.iapi.MessageExchangeInterceptor;
+import org.apache.ode.bpel.iapi.PartnerRoleChannel;
import org.apache.ode.bpel.iapi.MessageExchange.FailureType;
import org.apache.ode.bpel.iapi.MessageExchange.MessageExchangePattern;
import org.apache.ode.bpel.iapi.MessageExchange.Status;
@@ -70,621 +69,679 @@
import org.apache.ode.bpel.runtime.InvalidProcessException;
import org.apache.ode.bpel.runtime.PROCESS;
import org.apache.ode.bpel.runtime.PropertyAliasEvaluationContext;
-import org.apache.ode.bpel.runtime.msgs.Messages;
-import org.apache.ode.bpel.epr.WSAEndpoint;
+import org.apache.ode.jacob.soup.ReplacementMap;
import org.apache.ode.utils.ArrayUtils;
import org.apache.ode.utils.ObjectPrinter;
import org.apache.ode.utils.msg.MessageBundle;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+import org.w3c.dom.Text;
/**
- * Implementation of a BPEL process.
+ * Entry point into the runtime of a BPEL process.
+ *
+ * @author mszefler
*/
public class BpelProcess {
- static final Log __log = LogFactory.getLog(BpelProcess.class);
+ static final Log __log = LogFactory.getLog(BpelProcess.class);
+
+ private static final Messages __msgs = MessageBundle.getMessages(Messages.class);
+
+ private final Map<OPartnerLink, PartnerLinkPartnerRoleImpl> _partnerRoles = new HashMap<OPartnerLink, PartnerLinkPartnerRoleImpl>();
- private static final Messages __msgs = MessageBundle
- .getMessages(Messages.class);
+ private Map<OPartnerLink, PartnerLinkMyRoleImpl> _myRoles = new HashMap<OPartnerLink, PartnerLinkMyRoleImpl>();
- private final Map<OPartnerLink, PartnerLinkPartnerRoleImpl> _partnerRoles = new HashMap<OPartnerLink, PartnerLinkPartnerRoleImpl>();
+ final DebuggerSupport _debugger;
- private Map<OPartnerLink, PartnerLinkMyRoleImpl> _myRoles = new HashMap<OPartnerLink, PartnerLinkMyRoleImpl>();
+ final OProcess _oprocess;
- /**
- * MyRole Endpoint reference to partner link map.
- */
- private final Map<EndpointReference, PartnerLinkMyRoleImpl> _eprToMyRole = new HashMap<EndpointReference, PartnerLinkMyRoleImpl>();
-
- final DebuggerSupport _debugger;
-
- final OProcess _oprocess;
-
- final ExpressionLanguageRuntimeRegistry _expLangRuntimeRegistry;
-
- final ReplacementMap _replacementMap;
-
- final BpelEngineImpl _engine;
-
- final QName _pid;
-
- /** Mapping from "Service Name" (QNAME) to a myrole. */
- private Map<QName, PartnerLinkMyRoleImpl> _serviceMap =
- new HashMap<QName,PartnerLinkMyRoleImpl>();
-
- private Map<Integer,Element> _myEprs;
-
-
- private Set<EndpointReference> _myEndpoints = new HashSet<EndpointReference>();
-
- public BpelProcess(BpelEngineImpl engine, QName pid,
- OProcess oprocess,
- Map<Integer,QName> serviceNames,
- Map<Integer,Element> myEprs,
- BpelEventListener debugger,
- ExpressionLanguageRuntimeRegistry expLangRuntimeRegistry) {
- _pid = pid;
- _engine = engine;
- _replacementMap = new ReplacementMapImpl(oprocess);
- _oprocess = oprocess;
- _myEprs = myEprs;
- _expLangRuntimeRegistry = expLangRuntimeRegistry;
-
- for (OPartnerLink pl : _oprocess.getAllPartnerLinks()) {
- if (pl.hasMyRole()) {
- PartnerLinkMyRoleImpl myRole = new PartnerLinkMyRoleImpl(pl);
- _myRoles.put(pl, myRole);
- // TODO: We will need to allow this naming to be user-selected
- // in order to support versioned processes.
- QName serviceName = serviceNames.get(pl.getId());
- if (serviceName == null)
- throw new NullPointerException("No service names for plink " + pl);
- _serviceMap.put(serviceName, myRole);
- }
-
- if (pl.hasPartnerRole()) {
- PartnerLinkPartnerRoleImpl partnerRole = new PartnerLinkPartnerRoleImpl(
- pl);
- _partnerRoles.put(pl, partnerRole);
- }
- }
- _debugger = new DebuggerSupport(this);
- }
-
- public void registerEPR(EndpointReference epr, OPartnerLink myrolePartnerLink) {
- PartnerLinkMyRoleImpl mrpl = _myRoles.get(myrolePartnerLink);
- if (mrpl == null)
- throw new IllegalArgumentException("No myrole for partner link: "
- + myrolePartnerLink);
- _eprToMyRole.put(epr, mrpl);
- __log.debug(this + " mapped EPR " + epr + " --> " + myrolePartnerLink);
- }
-
- static String generateMessageExchangeIdentifier(String partnerlinkName,
- String operationName) {
- StringBuffer sb = new StringBuffer(partnerlinkName);
- sb.append('.');
- sb.append(operationName);
- return sb.toString();
- }
-
-
- void invokeProcess(QName serviceName, EndpointReference epr, MyRoleMessageExchangeImpl mex) {
- PartnerLinkMyRoleImpl target = _serviceMap.get(serviceName);
- if (target == null) {
- String errmsg = __msgs.msgMyRoleRoutingFailure(mex.getMessageExchangeId());
- __log.error(errmsg);
- mex.setFailure(MessageExchange.FailureType.UNKNOWN_ENDPOINT,
- errmsg, epr.toXML().getDocumentElement());
- return;
- }
-
- mex.getDAO().setProcess(getProcessDAO());
- mex.setProcess(_oprocess);
- target.invokeProcess(mex);
- }
-
- void initMyRoleMex(MyRoleMessageExchangeImpl mex) {
- PartnerLinkMyRoleImpl target = _serviceMap.get(mex.getServiceName());
- if (target != null) {
- mex.setPortOp(target._plinkDef.myRolePortType,target._plinkDef.getMyRoleOperation(mex.getOperationName()));
- }
- }
-
- /**
- * Extract the value of a BPEL property from a BPEL messsage variable.
- *
- * @param msgData
- * message variable data
- * @param alias
- * alias to apply
- * @param target
- * description of the data (for error logging only)
- * @return value of the property
- * @throws FaultException
- */
- String extractProperty(Element msgData, OProcess.OPropertyAlias alias,
- String target) throws FaultException {
-
- PropertyAliasEvaluationContext ectx = new PropertyAliasEvaluationContext(
- msgData, alias);
- Node lValue = ectx.getRootNode();
-
- if (alias.location != null)
- try {
- lValue = _expLangRuntimeRegistry.evaluateNode(alias.location, ectx);
- } catch (EvaluationException ec) {
- throw new FaultException(_oprocess.constants.qnSelectionFailure, alias
- .getDescription());
- }
-
- if (lValue == null) {
- String errmsg = __msgs.msgPropertyAliasReturnedNullSet(alias
- .getDescription(), target);
- if (__log.isErrorEnabled()) {
- __log.error(errmsg);
- }
- throw new FaultException(_oprocess.constants.qnSelectionFailure, errmsg);
- }
-
- if (lValue.getNodeType() == Node.ELEMENT_NODE) {
- // This is a bit hokey, we concatenate all the children's values; we
- // really should be checking to make sure that we are only dealing with
- // text and attribute nodes.
- StringBuffer val = new StringBuffer();
- NodeList nl = lValue.getChildNodes();
- for (int i = 0; i < nl.getLength(); ++i) {
- Node n = nl.item(i);
- val.append(n.getNodeValue());
- }
- return val.toString();
- } else if (lValue.getNodeType() == Node.TEXT_NODE) {
- return ((Text) lValue).getWholeText();
- } else
- return null;
- }
-
- /**
- * Get the element name for a given WSDL part. If the part is an
- * <em>element</em> part, the name of that element is returned. If the part
- * is an XML schema typed part, then the name of the part is returned in the
- * null namespace.
- *
- * @param part
- * WSDL {@link javax.wsdl.Part}
- * @return name of element containing said part
- */
- static QName getElementNameForPart(OMessageVarType.Part part) {
- return (part.type instanceof OElementVarType) ? ((OElementVarType) part.type).elementType
- : new QName(null, part.name);
- }
-
- /** Create a version-appropriate runtime context. */
- private BpelRuntimeContextImpl createRuntimeContext(ProcessInstanceDAO dao,
- PROCESS template, MyRoleMessageExchangeImpl instantiatingMessageExchange) {
- return new BpelRuntimeContextImpl(this, dao, template,
- instantiatingMessageExchange);
- }
-
- /**
- * Replacement object for serializtation of the {@link OBase} (compiled BPEL)
- * objects in the JACOB VPU.
- */
- public static final class OBaseReplacementImpl implements Externalizable {
- private static final long serialVersionUID = 1L;
-
- int _id;
-
- public OBaseReplacementImpl() {
- }
-
- public OBaseReplacementImpl(int id) {
- _id = id;
- }
-
- public void readExternal(ObjectInput in) throws IOException {
- _id = in.readInt();
- }
-
- public void writeExternal(ObjectOutput out) throws IOException {
- out.writeInt(_id);
- }
-
- }
-
- private abstract class PartnerLinkRoleImpl {
- protected OPartnerLink _plinkDef;
-
- PartnerLinkRoleImpl(OPartnerLink plink) {
- _plinkDef = plink;
- }
-
- String getPartnerLinkName() {
- return _plinkDef.name;
- }
- }
-
- class PartnerLinkMyRoleImpl extends PartnerLinkRoleImpl {
-
- PartnerLinkMyRoleImpl(OPartnerLink plink) {
- super(plink);
- }
-
- public String toString() {
- StringBuffer buf = new StringBuffer("PartnerLinkRole-");
- buf.append(_plinkDef.name);
- buf.append('.');
- buf.append(_plinkDef.myRoleName);
- return buf.toString();
+ final ExpressionLanguageRuntimeRegistry _expLangRuntimeRegistry;
+
+ final ReplacementMap _replacementMap;
+
+ final QName _pid;
+
+ BpelEngineImpl _engine;
+
+ /** Mapping from {"Service Name" (QNAME) / port} to a myrole. */
+ private Map<Endpoint, PartnerLinkMyRoleImpl> _endpointToMyRoleMap = new HashMap<Endpoint, PartnerLinkMyRoleImpl>();
+
+ /** {@link MessageExchangeInterceptor}s registered for this process. */
+ private final List<MessageExchangeInterceptor> _mexInterceptors = new ArrayList<MessageExchangeInterceptor>();
+
+ private DeploymentUnit _du;
+
+ public BpelProcess(
+ QName pid,
+ DeploymentUnit du,
+ OProcess oprocess,
+ Map<OPartnerLink, Endpoint> myRoleEndpointNames,
+ Map<OPartnerLink, Endpoint> initialPartners,
+ BpelEventListener debugger,
+ ExpressionLanguageRuntimeRegistry expLangRuntimeRegistry,
+ List<MessageExchangeInterceptor> localMexInterceptors) {
+ _pid = pid;
+ _du = du;
+ _replacementMap = new ReplacementMapImpl(oprocess);
+ _oprocess = oprocess;
+ _expLangRuntimeRegistry = expLangRuntimeRegistry;
+ _mexInterceptors.addAll(localMexInterceptors);
+
+ for (OPartnerLink pl : _oprocess.getAllPartnerLinks()) {
+ if (pl.hasMyRole()) {
+ Endpoint endpoint = myRoleEndpointNames.get(pl);
+ if (endpoint == null)
+ throw new NullPointerException("No service name for plink " + pl);
+ PartnerLinkMyRoleImpl myRole = new PartnerLinkMyRoleImpl(pl,endpoint);
+ _myRoles.put(pl, myRole);
+ _endpointToMyRoleMap.put(endpoint, myRole);
+ }
+
+ if (pl.hasPartnerRole()) {
+ PartnerLinkPartnerRoleImpl partnerRole = new PartnerLinkPartnerRoleImpl(pl, initialPartners.get(pl));
+ _partnerRoles.put(pl, partnerRole);
+ }
+ }
+ _debugger = new DebuggerSupport(this);
+ }
+
+ static String generateMessageExchangeIdentifier(String partnerlinkName, String operationName) {
+ StringBuffer sb = new StringBuffer(partnerlinkName);
+ sb.append('.');
+ sb.append(operationName);
+ return sb.toString();
}
/**
- * Called when an input message has been received.
+ * Entry point for message exchanges aimed at the my role.
*
* @param mex
- * exchange to which the message is related
*/
- public void invokeProcess(MyRoleMessageExchangeImpl mex) {
- if (__log.isTraceEnabled()) {
- __log.trace(ObjectPrinter.stringifyMethodEnter(this + ":inputMsgRcvd",
- new Object[] { "messageExchange", mex }));
- }
-
- Operation operation = getMyRoleOperation(mex
- .getOperationName());
- if (operation == null) {
- __log.error(__msgs.msgUnknownOperation(mex
- .getOperationName(), _plinkDef.myRolePortType.getQName()));
- mex.setFailure(FailureType.UNKNOWN_OPERATION,
- mex.getOperationName(), null);
- return;
- }
-
- mex.getDAO().setPartnerLinkModelId(_plinkDef.getId());
- mex.setPortOp(_plinkDef.myRolePortType, operation);
- mex.setPattern(operation.getOutput() == null
- ? MessageExchangePattern.REQUEST_ONLY
- : MessageExchangePattern.REQUEST_RESPONSE);
-
- // Is this a /possible/ createInstance Operation?
- boolean isCreateInstnace = _plinkDef.isCreateInstanceOperation(operation);
-
- // now, the tricks begin: when a message arrives we have to see if there
- // is anyone waiting for it.
- // Get the correlator, a persisted communnication-reduction data structure
- // supporting correlation correlationKey matching!
- String correlatorId = genCorrelatorId(_plinkDef, operation.getName());
-
- CorrelatorDAO correlator = getProcessDAO().getCorrelator(correlatorId);
-
- CorrelationKey[] keys;
- MessageRouteDAO messageRoute = null;
-
- // We need to compute the correlation keys (based on the operation we can
- // infer which correlation keys to compute - this is merely a set
- // consisting of each correlationKey used in each correlation sets that is
- // ever
- // referenced in an <receive>/<onMessage> on this partnerlink/operation.
- keys = computeCorrelationKeys(mex);
-
- if (__log.isDebugEnabled()) {
- __log.debug("INPUTMSG: " + correlatorId + ": MSG RCVD keys="
- + ArrayUtils.makeCollection(HashSet.class, keys));
- }
-
- CorrelationKey matchedKey = null;
-
- // Try to find a route for one of our keys.
- for (CorrelationKey key : keys) {
- messageRoute = correlator.findRoute(key);
- if (messageRoute != null) {
- if (__log.isDebugEnabled()) {
- __log.debug("INPUTMSG: " + correlatorId + ": ckey " + key
- + " route is to " + messageRoute);
- }
- matchedKey = key;
- break;
- }
- }
- // Handling the "opaque correlation case": correlation is done on a
- // session identifier associated with my epr
- if (messageRoute == null) {
- EndpointReference ref = mex.getEndpointReference();
- // Stateful interactions are only supported with WSA endpoints
- if (ref != null && ref instanceof WSAEndpoint) {
- String sessionId = ((WSAEndpoint)ref).getSessionId();
- CorrelationKey key = new CorrelationKey(-1,
- new String[] { sessionId });
- messageRoute = correlator.findRoute(key);
+ void invokeProcess(MyRoleMessageExchangeImpl mex) {
+ PartnerLinkMyRoleImpl target = _endpointToMyRoleMap.get(mex.getServiceName());
+ if (target == null) {
+ String errmsg = __msgs.msgMyRoleRoutingFailure(mex.getMessageExchangeId());
+ __log.error(errmsg);
+ mex.setFailure(MessageExchange.FailureType.UNKNOWN_ENDPOINT, errmsg, null);
+ return;
}
- }
- // TODO - ODE-58
+ mex.getDAO().setProcess(getProcessDAO());
+ mex.setProcess(_oprocess);
- // If no luck try to find a default route.
- if (messageRoute == null) {
- if (__log.isDebugEnabled()) {
- __log.debug("INPUTMSG: " + correlatorId
- + ": CorrelationKey routing failed; checking default route.");
+ if (!processInterceptors(mex)) {
+ __log.debug("Aborting processing of mex " + mex + " due to interceptors.");
+ return;
}
- messageRoute = correlator.findRoute(null);
+ target.invokeMyRole(mex);
+ }
- if (__log.isDebugEnabled()) {
- __log.debug("INPUTMSG: " + correlatorId + ": default route is to "
- + messageRoute);
+ void initMyRoleMex(MyRoleMessageExchangeImpl mex) {
+ PartnerLinkMyRoleImpl target = _endpointToMyRoleMap.get(mex.getServiceName());
+ if (target != null) {
+ mex.setPortOp(target._plinkDef.myRolePortType, target._plinkDef.getMyRoleOperation(mex.getOperationName()));
}
- }
+ }
- // If still no luck, and this operation qualifies for create-instance
- // treatment,
- // then create a new process instance.
- if (messageRoute == null && isCreateInstnace) {
- if (__log.isDebugEnabled()) {
- __log.debug("INPUTMSG: " + correlatorId
- + ": default routing failed, CREATING NEW INSTANCE");
+ /**
+ * Extract the value of a BPEL property from a BPEL messsage variable.
+ *
+ * @param msgData
+ * message variable data
+ * @param alias
+ * alias to apply
+ * @param target
+ * description of the data (for error logging only)
+ * @return value of the property
+ * @throws FaultException
+ */
+ String extractProperty(Element msgData, OProcess.OPropertyAlias alias, String target) throws FaultException {
+
+ PropertyAliasEvaluationContext ectx = new PropertyAliasEvaluationContext(msgData, alias);
+ Node lValue = ectx.getRootNode();
+
+ if (alias.location != null)
+ try {
+ lValue = _expLangRuntimeRegistry.evaluateNode(alias.location, ectx);
+ } catch (EvaluationException ec) {
+ throw new FaultException(_oprocess.constants.qnSelectionFailure, alias.getDescription());
+ }
+
+ if (lValue == null) {
+ String errmsg = __msgs.msgPropertyAliasReturnedNullSet(alias.getDescription(), target);
+ if (__log.isErrorEnabled()) {
+ __log.error(errmsg);
+ }
+ throw new FaultException(_oprocess.constants.qnSelectionFailure, errmsg);
+ }
+
+ if (lValue.getNodeType() == Node.ELEMENT_NODE) {
+ // This is a bit hokey, we concatenate all the children's values; we
+ // really should be checking to make sure that we are only dealing
+ // with
+ // text and attribute nodes.
+ StringBuffer val = new StringBuffer();
+ NodeList nl = lValue.getChildNodes();
+ for (int i = 0; i < nl.getLength(); ++i) {
+ Node n = nl.item(i);
+ val.append(n.getNodeValue());
+ }
+ return val.toString();
+ } else if (lValue.getNodeType() == Node.TEXT_NODE) {
+ return ((Text) lValue).getWholeText();
+ } else
+ return null;
+ }
+
+ /**
+ * Get the element name for a given WSDL part. If the part is an
+ * <em>element</em> part, the name of that element is returned. If the
+ * part is an XML schema typed part, then the name of the part is returned
+ * in the null namespace.
+ *
+ * @param part
+ * WSDL {@link javax.wsdl.Part}
+ * @return name of element containing said part
+ */
+ static QName getElementNameForPart(OMessageVarType.Part part) {
+ return (part.type instanceof OElementVarType) ? ((OElementVarType) part.type).elementType : new QName(null,
+ part.name);
+ }
+
+ /** Create a version-appropriate runtime context. */
+ private BpelRuntimeContextImpl createRuntimeContext(ProcessInstanceDAO dao, PROCESS template,
+ MyRoleMessageExchangeImpl instantiatingMessageExchange) {
+ return new BpelRuntimeContextImpl(this, dao, template, instantiatingMessageExchange);
+ }
+
+ /**
+ * Process the message-exchange interceptors.
+ *
+ * @param mex
+ * message exchange
+ * @return <code>true</code> if execution should continue,
+ * <code>false</code> otherwise
+ */
+ private boolean processInterceptors(MyRoleMessageExchangeImpl mex) {
+ ArrayList<MessageExchangeInterceptor> interceptors = new ArrayList<MessageExchangeInterceptor>(_mexInterceptors
+ .size()
+ + _engine.getGlobalInterceptors().size());
+ interceptors.addAll(_mexInterceptors);
+ interceptors.addAll(_engine.getGlobalInterceptors());
+
+ for (MessageExchangeInterceptor i : _mexInterceptors) {
+ __log.debug("onBpelServerInvoked --> interceptor " + i);
+ boolean cont = i.onProcessInvoked(mex);
+ if (!cont) {
+ __log.debug("interceptor " + i + " caused invoke on " + this + "to be aborted");
+ if (mex.getStatus() == Status.REQUEST) {
+ __log.debug("aborting interceptor " + i + " did not set message exchange status, assuming failure");
+ mex.setFailure(MessageExchange.FailureType.ABORTED, __msgs.msgInterceptorAborted(mex
+ .getMessageExchangeId(), i.toString()), null);
+ }
+ return false;
+ }
+ }
+ return true;
+ }
+
+ /**
+ * Replacement object for serializtation of the {@link OBase} (compiled
+ * BPEL) objects in the JACOB VPU.
+ */
+ public static final class OBaseReplacementImpl implements Externalizable {
+ private static final long serialVersionUID = 1L;
+
+ int _id;
+
+ public OBaseReplacementImpl() {
+ }
+
+ public OBaseReplacementImpl(int id) {
+ _id = id;
+ }
+
+ public void readExternal(ObjectInput in) throws IOException {
+ _id = in.readInt();
+ }
+
+ public void writeExternal(ObjectOutput out) throws IOException {
+ out.writeInt(_id);
}
- ProcessDAO processDAO = getProcessDAO();
- if (processDAO.isRetired()) {
- throw new InvalidProcessException("Process is retired.",
- InvalidProcessException.RETIRED_CAUSE_CODE);
- }
- ProcessInstanceDAO newInstance = processDAO.createInstance(correlator);
- BpelRuntimeContextImpl instance = createRuntimeContext(newInstance,
- new PROCESS(_oprocess), mex);
-
- // send process instance event
- NewProcessInstanceEvent evt = new NewProcessInstanceEvent(new QName(
- _oprocess.targetNamespace, _oprocess.getName()), getProcessDAO()
- .getProcessId(), newInstance.getInstanceId());
- evt.setPortType(mex.getPortType().getQName());
- evt.setOperation(operation.getName());
- evt.setMexId(mex.getMessageExchangeId());
- _debugger.onEvent(evt);
- newInstance.insertBpelEvent(evt);
- mex.setCorrelationStatus(CorrelationStatus.CREATE_INSTANCE);
- mex.getDAO().setInstance(newInstance);
+
+ }
+
+ private abstract class PartnerLinkRoleImpl {
+ protected OPartnerLink _plinkDef;
+ protected Element _initialEPR;
- instance.execute();
- } else if (messageRoute != null) {
- if (__log.isDebugEnabled()) {
- __log.debug("INPUTMSG: " + correlatorId + ": ROUTING to instance "
- + messageRoute.getTargetInstance().getInstanceId());
+ PartnerLinkRoleImpl(OPartnerLink plink) {
+ _plinkDef = plink;
+ }
+
+
+ String getPartnerLinkName() {
+ return _plinkDef.name;
+ }
+
+ /**
+ * Get the initial value of this role's EPR. This value is obtained from
+ * the integration layer when the process is enabled on the server.
+ * @return
+ */
+ Element getInitialEPR() {
+ return _initialEPR;
+ }
+
+ }
+
+ class PartnerLinkMyRoleImpl extends PartnerLinkRoleImpl {
+
+ /** The local endpoint for this "myrole". */
+ public Endpoint _endpoint;
+
+ PartnerLinkMyRoleImpl(OPartnerLink plink, Endpoint endpoint) {
+ super(plink);
+ _endpoint = endpoint;
+ }
+
+
+ public String toString() {
+ StringBuffer buf = new StringBuffer("{PartnerLinkRole-");
+ buf.append(_plinkDef.name);
+ buf.append('.');
+ buf.append(_plinkDef.myRoleName);
+ buf.append(" on ");
+ buf.append(_endpoint);
+ buf.append('}');
+
+ return buf.toString();
+ }
+
+ /**
+ * Called when an input message has been received.
+ *
+ * @param mex
+ * exchange to which the message is related
+ */
+ public void invokeMyRole(MyRoleMessageExchangeImpl mex) {
+ if (__log.isTraceEnabled()) {
+ __log.trace(ObjectPrinter.stringifyMethodEnter(this + ":inputMsgRcvd", new Object[] {
+ "messageExchange", mex }));
+ }
+
+ Operation operation = getMyRoleOperation(mex.getOperationName());
+ if (operation == null) {
+ __log.error(__msgs.msgUnknownOperation(mex.getOperationName(), _plinkDef.myRolePortType.getQName()));
+ mex.setFailure(FailureType.UNKNOWN_OPERATION, mex.getOperationName(), null);
+ return;
+ }
+
+ mex.getDAO().setPartnerLinkModelId(_plinkDef.getId());
+ mex.setPortOp(_plinkDef.myRolePortType, operation);
+ mex.setPattern(operation.getOutput() == null ? MessageExchangePattern.REQUEST_ONLY
+ : MessageExchangePattern.REQUEST_RESPONSE);
+
+ // Is this a /possible/ createInstance Operation?
+ boolean isCreateInstnace = _plinkDef.isCreateInstanceOperation(operation);
+
+ // now, the tricks begin: when a message arrives we have to see if
+ // there
+ // is anyone waiting for it.
+ // Get the correlator, a persisted communnication-reduction data
+ // structure
+ // supporting correlation correlationKey matching!
+ String correlatorId = genCorrelatorId(_plinkDef, operation.getName());
+
+ CorrelatorDAO correlator = getProcessDAO().getCorrelator(correlatorId);
+
+ CorrelationKey[] keys;
+ MessageRouteDAO messageRoute = null;
+
+ // We need to compute the correlation keys (based on the operation
+ // we can
+ // infer which correlation keys to compute - this is merely a set
+ // consisting of each correlationKey used in each correlation sets
+ // that is
+ // ever
+ // referenced in an <receive>/<onMessage> on this
+ // partnerlink/operation.
+ keys = computeCorrelationKeys(mex);
+
+ if (__log.isDebugEnabled()) {
+ __log.debug("INPUTMSG: " + correlatorId + ": MSG RCVD keys="
+ + ArrayUtils.makeCollection(HashSet.class, keys));
+ }
+
+ CorrelationKey matchedKey = null;
+
+ // Try to find a route for one of our keys.
+ for (CorrelationKey key : keys) {
+ messageRoute = correlator.findRoute(key);
+ if (messageRoute != null) {
+ if (__log.isDebugEnabled()) {
+ __log.debug("INPUTMSG: " + correlatorId + ": ckey " + key + " route is to " + messageRoute);
+ }
+ matchedKey = key;
+ break;
+ }
+ }
+ // Handling the "opaque correlation case": correlation is done on a
+ // session identifier associated with my epr
+ if (messageRoute == null) {
+ EndpointReference ref = mex.getEndpointReference();
+ // Stateful interactions are only supported with WSA endpoints
+ if (ref != null && ref instanceof WSAEndpoint) {
+ String sessionId = ((WSAEndpoint) ref).getSessionId();
+ CorrelationKey key = new CorrelationKey(-1, new String[] { sessionId });
+ messageRoute = correlator.findRoute(key);
+ }
+ }
+
+ // TODO - ODE-58
+
+ // If no luck try to find a default route.
+ if (messageRoute == null) {
+ if (__log.isDebugEnabled()) {
+ __log.debug("INPUTMSG: " + correlatorId
+ + ": CorrelationKey routing failed; checking default route.");
+ }
+
+ messageRoute = correlator.findRoute(null);
+
+ if (__log.isDebugEnabled()) {
+ __log.debug("INPUTMSG: " + correlatorId + ": default route is to " + messageRoute);
+ }
+ }
+
+ // If still no luck, and this operation qualifies for
+ // create-instance
+ // treatment,
+ // then create a new process instance.
+ if (messageRoute == null && isCreateInstnace) {
+ if (__log.isDebugEnabled()) {
+ __log.debug("INPUTMSG: " + correlatorId + ": default routing failed, CREATING NEW INSTANCE");
+ }
+ ProcessDAO processDAO = getProcessDAO();
+ if (processDAO.isRetired()) {
+ throw new InvalidProcessException("Process is retired.", InvalidProcessException.RETIRED_CAUSE_CODE);
+ }
+ ProcessInstanceDAO newInstance = processDAO.createInstance(correlator);
+ BpelRuntimeContextImpl instance = createRuntimeContext(newInstance, new PROCESS(_oprocess), mex);
+
+ // send process instance event
+ NewProcessInstanceEvent evt = new NewProcessInstanceEvent(new QName(_oprocess.targetNamespace,
+ _oprocess.getName()), getProcessDAO().getProcessId(), newInstance.getInstanceId());
+ evt.setPortType(mex.getPortType().getQName());
+ evt.setOperation(operation.getName());
+ evt.setMexId(mex.getMessageExchangeId());
+ _debugger.onEvent(evt);
+ newInstance.insertBpelEvent(evt);
+ mex.setCorrelationStatus(CorrelationStatus.CREATE_INSTANCE);
+ mex.getDAO().setInstance(newInstance);
+
+ instance.execute();
+ } else if (messageRoute != null) {
+ if (__log.isDebugEnabled()) {
+ __log.debug("INPUTMSG: " + correlatorId + ": ROUTING to instance "
+ + messageRoute.getTargetInstance().getInstanceId());
+ }
+
+ // Reload process instance for DAO.
+ BpelRuntimeContextImpl instance = createRuntimeContext(messageRoute.getTargetInstance(), null, null);
+ instance.inputMsgMatch(messageRoute.getGroupId(), messageRoute.getIndex(), mex);
+
+ // Kill the route so some new message does not get routed to
+ // same
+ // process
+ // instance.
+ correlator.removeRoutes(messageRoute.getGroupId(), messageRoute.getTargetInstance());
+
+ Long iid = messageRoute.getTargetInstance().getInstanceId();
+
+ // send process instance event
+ CorrelationMatchEvent evt = new CorrelationMatchEvent(new QName(_oprocess.targetNamespace, _oprocess
+ .getName()), getProcessDAO().getProcessId(), iid, matchedKey);
+ evt.setPortType(mex.getPortType().getQName());
+ evt.setOperation(operation.getName());
+ evt.setMexId(mex.getMessageExchangeId());
+
+ _debugger.onEvent(evt);
+ // store event
+ getProcessDAO().getInstance(iid).insertBpelEvent(evt);
+
+ mex.setCorrelationStatus(CorrelationStatus.MATCHED);
+ mex.getDAO().setInstance(messageRoute.getTargetInstance());
+
+ // run the vpu
+ instance.execute();
+ } else {
+ if (__log.isDebugEnabled()) {
+ __log.debug("INPUTMSG: " + correlatorId + ": SAVING to DB (no match) ");
+ }
+
+ // send event
+ CorrelationNoMatchEvent evt = new CorrelationNoMatchEvent(mex.getPortType().getQName(), mex
+ .getOperation().getName(), mex.getMessageExchangeId(), keys);
+
+ evt.setProcessId(getProcessDAO().getProcessId());
+ evt.setProcessName(new QName(_oprocess.targetNamespace, _oprocess.getName()));
+ _debugger.onEvent(evt);
+
+ mex.setCorrelationStatus(CorrelationStatus.QUEUED);
+
+ // No match, means we add message exchange to the queue.
+ correlator.enqueueMessage(mex.getDAO(), keys);
+
+ }
+
+ // Now we have to update our message exchange status. If the <reply>
+ // was
+ // not hit during the invocation, then we will be in the "REQUEST"
+ // phase
+ // which means that either this was a one-way or a two-way that
+ // needs to
+ // delivery the reply asynchronously.
+ if (mex.getStatus() == Status.REQUEST) {
+ switch (mex.getPattern()) {
+ case REQUEST_ONLY:
+ mex.setStatus(Status.ONE_WAY);
+ break;
+ case REQUEST_RESPONSE:
+ mex.setStatus(Status.ASYNC);
+ break;
+ default:
+ String errmsg = "BpelProcess: internal error, message exchange pattern not set";
+ __log.fatal(errmsg);
+ throw new BpelEngineException(errmsg);
+ }
+ }
+
+ }
+
+ @SuppressWarnings("unchecked")
+ private Operation getMyRoleOperation(String operationName) {
+ Operation op = _plinkDef.getMyRoleOperation(operationName);
+ return op;
+ }
+
+ private CorrelationKey[] computeCorrelationKeys(MyRoleMessageExchangeImpl mex) {
+ Operation operation = mex.getOperation();
+ Element msg = mex.getRequest().getMessage();
+ Message msgDescription = operation.getInput().getMessage();
+ List<CorrelationKey> keys = new ArrayList<CorrelationKey>();
+
+ Set<OScope.CorrelationSet> csets = _plinkDef.getCorrelationSetsForOperation(operation);
+
+ for (Iterator<OScope.CorrelationSet> i = csets.iterator(); i.hasNext();) {
+ OScope.CorrelationSet cset = i.next();
+ CorrelationKey key = computeCorrelationKey(cset, _oprocess.messageTypes.get(msgDescription.getQName()),
+ msg);
+ keys.add(key);
+ }
+
+ return keys.toArray(new CorrelationKey[keys.size()]);
+ }
+
+ private CorrelationKey computeCorrelationKey(OScope.CorrelationSet cset, OMessageVarType messagetype,
+ Element msg) {
+ String[] values = new String[cset.properties.size()];
+
+ int jIdx = 0;
+ for (Iterator j = cset.properties.iterator(); j.hasNext(); ++jIdx) {
+ OProcess.OProperty property = (OProcess.OProperty) j.next();
+ OProcess.OPropertyAlias alias = property.getAlias(messagetype);
+
+ if (alias == null) {
+ // TODO: Throw a real exception! And catch this at compile
+ // time.
+ throw new IllegalArgumentException("No alias matching property '" + property.name
+ + "' with message type '" + messagetype + "'");
+ }
+
+ String value;
+ try {
+ value = extractProperty(msg, alias, msg.toString());
+ } catch (FaultException fe) {
+ String emsg = __msgs.msgPropertyAliasDerefFailedOnMessage(alias.getDescription(), fe.getMessage());
+ __log.error(emsg, fe);
+ throw new InvalidMessageException(emsg, fe);
+ }
+ values[jIdx] = value;
+ }
+
+ CorrelationKey key = new CorrelationKey(cset.getId(), values);
+ return key;
+ }
+
+ }
+
+ private class PartnerLinkPartnerRoleImpl extends PartnerLinkRoleImpl {
+ Endpoint _initialPartner;
+ public PartnerRoleChannel _channel;
+
+ private PartnerLinkPartnerRoleImpl(OPartnerLink plink, Endpoint initialPartner) {
+ super(plink);
+ _initialPartner = initialPartner;
}
- // Reload process instance for DAO.
- BpelRuntimeContextImpl instance = createRuntimeContext(messageRoute
- .getTargetInstance(), null, null);
- instance.inputMsgMatch(messageRoute.getGroupId(), messageRoute
- .getIndex(), mex);
-
- // Kill the route so some new message does not get routed to same
- // process
- // instance.
- correlator.removeRoutes(messageRoute.getGroupId(), messageRoute
- .getTargetInstance());
-
- Long iid = messageRoute.getTargetInstance().getInstanceId();
-
- // send process instance event
- CorrelationMatchEvent evt = new CorrelationMatchEvent(new QName(
- _oprocess.targetNamespace, _oprocess.getName()), getProcessDAO()
- .getProcessId(), iid, matchedKey);
- evt.setPortType(mex.getPortType().getQName());
- evt.setOperation(operation.getName());
- evt.setMexId(mex.getMessageExchangeId());
-
- _debugger.onEvent(evt);
- // store event
- getProcessDAO().getInstance(iid).insertBpelEvent(evt);
-
- mex.setCorrelationStatus(CorrelationStatus.MATCHED);
- mex.getDAO().setInstance(messageRoute.getTargetInstance());
-
- // run the vpu
- instance.execute();
- } else {
+ public void processPartnerResponse(PartnerRoleMessageExchangeImpl messageExchange) {
+ if (__log.isDebugEnabled()) {
+ __log.debug("Processing partner's response for partnerLink: " + messageExchange);
+ }
+
+ BpelRuntimeContextImpl processInstance = createRuntimeContext(messageExchange.getDAO().getInstance(), null,
+ null);
+ processInstance.invocationResponse(messageExchange);
+ processInstance.execute();
+ }
+
+ }
+
+ /**
+ * @see org.apache.ode.bpel.engine.BpelProcess#handleWorkEvent(java.io.Serializable)
+ */
+ public void handleWorkEvent(Map<String, Object> jobData) {
+ ProcessInstanceDAO procInstance;
+
if (__log.isDebugEnabled()) {
- __log.debug("INPUTMSG: " + correlatorId
- + ": SAVING to DB (no match) ");
+ __log.debug(ObjectPrinter.stringifyMethodEnter("handleWorkEvent", new Object[] { "jobData", jobData }));
+ }
+
+ WorkEvent we = new WorkEvent(jobData);
+ procInstance = getProcessDAO().getInstance(we.getIID());
+ if (procInstance == null) {
+ if (__log.isDebugEnabled()) {
+ __log.debug("handleWorkEvent: no ProcessInstance found with iid " + we.getIID() + "; ignoring.");
+ }
+ return;
+ }
+
+ BpelRuntimeContextImpl processInstance = createRuntimeContext(procInstance, null, null);
+ switch (we.getType()) {
+ case TIMER:
+ if (__log.isDebugEnabled()) {
+ __log.debug("handleWorkEvent: TimerWork event for process instance " + processInstance);
+ }
+
+ processInstance.timerEvent(we.getChannel());
+ break;
+ case RESUME:
+ if (__log.isDebugEnabled()) {
+ __log.debug("handleWorkEvent: ResumeWork event for iid " + we.getIID());
+ }
+
+ processInstance.execute();
+
+ break;
+ case INVOKE_RESPONSE:
+ if (__log.isDebugEnabled()) {
+ __log.debug("InvokeResponse event for iid " + we.getIID());
+ }
+
+ processInstance.invocationResponse(we.getMexId(), we.getChannel());
+ processInstance.execute();
+ break;
+ }
+ }
+
+ ProcessDAO getProcessDAO() {
+ return _engine._contexts.dao.getConnection().getProcess(_pid);
+ }
+
+ static String genCorrelatorId(OPartnerLink plink, String opName) {
+ return plink.getId() + "." + opName;
+ }
+
+ /**
+ * Get all the services that are implemented by this process.
+ *
+ * @return list of qualified names corresponding to the myroles.
+ */
+ public Set<Endpoint> getServiceNames() {
+ return _endpointToMyRoleMap.keySet();
+ }
+
+ void activate() {
+ // Activate all the my-role endpoints.
+ for (PartnerLinkMyRoleImpl myrole : _myRoles.values()) {
+ myrole._initialEPR = _engine._contexts.bindingContext.activateMyRoleEndpoint(_pid, _du, myrole._endpoint, myrole._plinkDef.myRolePortType);
}
+
+ for (PartnerLinkPartnerRoleImpl prole : _partnerRoles.values()) {
+ PartnerRoleChannel channel = _engine._contexts.bindingContext.createPartnerRoleChannel(_pid, _du, prole._plinkDef.partnerRolePortType,prole._initialPartner);
+ prole._channel = channel;
+ prole._initialEPR = channel.getInitialEndpointReference().toXML().getDocumentElement();
+ }
+ }
+
+ void deactivate() {
+ // Deactivate all the my-role endpoints.
+ for (Endpoint endpoint : _endpointToMyRoleMap.keySet())
+ _engine._contexts.bindingContext.deactivateMyRoleEndpoint(endpoint);
- // send event
- CorrelationNoMatchEvent evt = new CorrelationNoMatchEvent(
- mex.getPortType().getQName(), mex
- .getOperation().getName(), mex
- .getMessageExchangeId(), keys);
-
- evt.setProcessId(getProcessDAO().getProcessId());
- evt.setProcessName(new QName(_oprocess.targetNamespace, _oprocess
- .getName()));
- _debugger.onEvent(evt);
-
- mex.setCorrelationStatus(CorrelationStatus.QUEUED);
-
- // No match, means we add message exchange to the queue.
- correlator.enqueueMessage(mex.getDAO(), keys);
-
- }
-
-
- // Now we have to update our message exchange status. If the <reply> was
- // not hit during the invocation, then we will be in the "REQUEST" phase
- // which means that either this was a one-way or a two-way that needs to
- // delivery the reply asynchronously.
- if (mex.getStatus() == Status.REQUEST) {
- switch (mex.getPattern()) {
- case REQUEST_ONLY:
- mex.setStatus(Status.ONE_WAY);
- break;
- case REQUEST_RESPONSE:
- mex.setStatus(Status.ASYNC);
- break;
- default:
- String errmsg = "BpelProcess: internal error, message exchange pattern not set";
- __log.fatal(errmsg);
- throw new BpelEngineException(errmsg);
- }
- }
-
- }
-
- @SuppressWarnings("unchecked")
- private Operation getMyRoleOperation(String operationName) {
- Operation op = _plinkDef.getMyRoleOperation(operationName);
- return op;
- }
-
- private CorrelationKey[] computeCorrelationKeys(
- MyRoleMessageExchangeImpl mex) {
- Operation operation = mex.getOperation();
- Element msg = mex.getRequest().getMessage();
- Message msgDescription = operation.getInput().getMessage();
- List<CorrelationKey> keys = new ArrayList<CorrelationKey>();
-
- Set<OScope.CorrelationSet> csets = _plinkDef
- .getCorrelationSetsForOperation(operation);
-
- for (Iterator<OScope.CorrelationSet> i = csets.iterator(); i.hasNext();) {
- OScope.CorrelationSet cset = i.next();
- CorrelationKey key = computeCorrelationKey(cset, _oprocess.messageTypes
- .get(msgDescription.getQName()), msg);
- keys.add(key);
- }
-
- return keys.toArray(new CorrelationKey[keys.size()]);
- }
-
- private CorrelationKey computeCorrelationKey(OScope.CorrelationSet cset,
- OMessageVarType messagetype, Element msg) {
- String[] values = new String[cset.properties.size()];
-
- int jIdx = 0;
- for (Iterator j = cset.properties.iterator(); j.hasNext(); ++jIdx) {
- OProcess.OProperty property = (OProcess.OProperty) j.next();
- OProcess.OPropertyAlias alias = property.getAlias(messagetype);
-
- if (alias == null) {
- // TODO: Throw a real exception! And catch this at compile time.
- throw new IllegalArgumentException("No alias matching property '"
- + property.name + "' with message type '" + messagetype + "'");
- }
-
- String value;
- try {
- value = extractProperty(msg, alias, msg.toString());
- } catch (FaultException fe) {
- String emsg = __msgs.msgPropertyAliasDerefFailedOnMessage(alias
- .getDescription(), fe.getMessage());
- __log.error(emsg, fe);
- throw new InvalidMessageException(emsg, fe);
- }
- values[jIdx] = value;
- }
-
- CorrelationKey key = new CorrelationKey(cset.getId(), values);
- return key;
- }
-
- }
-
- private class PartnerLinkPartnerRoleImpl extends PartnerLinkRoleImpl {
- private PartnerLinkPartnerRoleImpl(OPartnerLink plink) {
- super(plink);
- }
-
- public void processPartnerResponse(
- PartnerRoleMessageExchangeImpl messageExchange) {
- if (__log.isDebugEnabled()) {
- __log.debug("Processing partner's response for partnerLink: "
- + messageExchange);
- }
-
- BpelRuntimeContextImpl processInstance = createRuntimeContext(
- messageExchange.getDAO().getInstance(), null, null);
- processInstance.invocationResponse(messageExchange);
- processInstance.execute();
- }
- }
-
- /**
- * @see org.apache.ode.bpel.engine.BpelProcess#handleWorkEvent(java.io.Serializable)
- */
- public void handleWorkEvent(Map<String, Object> jobData) {
- ProcessInstanceDAO procInstance;
-
- if (__log.isDebugEnabled()) {
- __log.debug(ObjectPrinter.stringifyMethodEnter("handleWorkEvent",
- new Object[] { "jobData", jobData }));
- }
-
- WorkEvent we = new WorkEvent(jobData);
- procInstance = getProcessDAO().getInstance(we.getIID());
- if (procInstance == null) {
- if (__log.isDebugEnabled()) {
- __log.debug("handleWorkEvent: no ProcessInstance found with iid "
- + we.getIID() + "; ignoring.");
- }
- return;
- }
-
- BpelRuntimeContextImpl processInstance = createRuntimeContext(procInstance,
- null, null);
- switch (we.getType()) {
- case TIMER:
- if (__log.isDebugEnabled()) {
- __log.debug("handleWorkEvent: TimerWork event for process instance "
- + processInstance);
- }
-
- processInstance.timerEvent(we.getChannel());
- break;
- case RESUME:
- if (__log.isDebugEnabled()) {
- __log.debug("handleWorkEvent: ResumeWork event for iid " + we.getIID());
- }
-
-
- processInstance.execute();
-
- break;
- case INVOKE_RESPONSE:
- if (__log.isDebugEnabled()) {
- __log.debug("InvokeResponse event for iid " + we.getIID());
- }
-
- processInstance.invocationResponse(we.getMexId(), we.getChannel());
- processInstance.execute();
- break;
- }
- }
-
- ProcessDAO getProcessDAO() {
- return _engine._contexts.dao.getConnection().getProcess(_pid);
- }
-
- static String genCorrelatorId(OPartnerLink plink, String opName) {
- return plink.getId() + "." + opName;
- }
-
- /**
- * Get all the services that are implemented by this process.
- * @return list of qualified names corresponding to the myroles.
- */
- public Set<QName> getServiceNames() {
- return _serviceMap.keySet();
- }
-
- void activate() {
- for (QName svc : _serviceMap.keySet()) {
- PartnerLinkMyRoleImpl pm = _serviceMap.get(svc);
- _myEndpoints.add(_engine._contexts.eprContext.activateEndpoint(_pid,svc,_myEprs.get(pm._plinkDef.getId())));
- }
- }
-
- void deactivate() {
- for (EndpointReference ref : _myEndpoints)
- _engine._contexts.eprContext.deactivateEndpoint(ref);
- }
+ // TODO Deactivate all the partner-role channels
+ }
+
+ Element getInitialPartnerRoleEPR(OPartnerLink link) {
+ PartnerLinkPartnerRoleImpl prole = _partnerRoles.get(link);
+ if (prole == null)
+ throw new IllegalStateException("Unknown partner link " + link);
+ return prole.getInitialEPR();
+ }
+
+ Element getInitialMyRoleEPR(OPartnerLink link) {
+ PartnerLinkMyRoleImpl myRole = _myRoles.get(link);
+ if (myRole == null)
+ throw new IllegalStateException("Unknown partner link " + link);
+ return myRole.getInitialEPR();
+ }
+
+ QName getPID() {
+ return _pid;
+ }
-
}
Modified: incubator/ode/trunk/bpel-runtime/src/main/java/org/apache/ode/bpel/engine/BpelRuntimeContextImpl.java
URL: http://svn.apache.org/viewvc/incubator/ode/trunk/bpel-runtime/src/main/java/org/apache/ode/bpel/engine/BpelRuntimeContextImpl.java?rev=431370&r1=431369&r2=431370&view=diff
==============================================================================
--- incubator/ode/trunk/bpel-runtime/src/main/java/org/apache/ode/bpel/engine/BpelRuntimeContextImpl.java (original)
+++ incubator/ode/trunk/bpel-runtime/src/main/java/org/apache/ode/bpel/engine/BpelRuntimeContextImpl.java Mon Aug 14 08:42:03 2006
@@ -170,14 +170,12 @@
public boolean isEndpointReferenceInitialized(PartnerLinkInstance pLink,
boolean isMyEpr) {
- ScopeDAO scopeDAO = _dao.getScope(pLink.scopeInstanceId);
- PartnerLinkDAO spl = scopeDAO.getPartnerLink(pLink.partnerLink.getId());
- PartnerLinkDAO ppl = scopeDAO.getProcessInstance().getProcess()
- .getDeployedEndpointReference(pLink.partnerLink.getId());
+ PartnerLinkDAO spl = fetchPartnerLinkDAO(pLink);
+
if (isMyEpr) {
- return spl.getMyEPR() != null || ppl.getMyEPR() != null;
+ return spl.getMyEPR() != null || _bpelProcess.getInitialMyRoleEPR(pLink.partnerLink) != null;
} else
- return spl.getPartnerEPR() != null || ppl.getPartnerEPR() != null;
+ return spl.getPartnerEPR() != null ||_bpelProcess.getInitialPartnerRoleEPR(pLink.partnerLink) != null;
}
/**
@@ -425,7 +423,7 @@
public Element fetchEndpointReferenceData(PartnerLinkInstance pLink,
boolean isMyEPR) throws FaultException {
- PartnerLinkDAO pl = fetchEndpointReference(pLink, isMyEPR);
+ PartnerLinkDAO pl = fetchPartnerLinkDAO(pLink);
Element epr = (isMyEPR ? pl.getMyEPR() : pl.getPartnerEPR());
if (epr == null) {
@@ -435,20 +433,9 @@
return epr;
}
- private PartnerLinkDAO fetchEndpointReference(PartnerLinkInstance pLink,
- boolean isMyEPR) throws FaultException {
+ private PartnerLinkDAO fetchPartnerLinkDAO(PartnerLinkInstance pLink) {
ScopeDAO scopeDAO = _dao.getScope(pLink.scopeInstanceId);
- PartnerLinkDAO spl = scopeDAO.getPartnerLink(pLink.partnerLink.getId());
- PartnerLinkDAO ppl = scopeDAO.getProcessInstance().getProcess()
- .getDeployedEndpointReference(pLink.partnerLink.getId());
-
- PartnerLinkDAO rightpl;
- if (isMyEPR)
- rightpl = spl.getMyEPR() != null ? spl : ppl;
- else
- rightpl = spl.getPartnerEPR() != null ? spl : ppl;
-
- return rightpl;
+ return scopeDAO.getPartnerLink(pLink.partnerLink.getId());
}
/**
@@ -483,6 +470,7 @@
public Node initializeVariable(VariableInstance variable, Node initData) {
ScopeDAO scopeDAO = _dao.getScope(variable.scopeInstance);
XmlDataDAO dataDAO = scopeDAO.getVariable(variable.declaration.name);
+
dataDAO.set(initData);
writeProperties(variable, initData, dataDAO);
@@ -492,7 +480,7 @@
public Element writeEndpointReference(PartnerLinkInstance variable,
Element data) throws FaultException {
- PartnerLinkDAO eprDAO = fetchEndpointReference(variable, false);
+ PartnerLinkDAO eprDAO = fetchPartnerLinkDAO(variable);
Element originalEprElmt = eprDAO.getPartnerEPR();
if (__log.isDebugEnabled()) {
@@ -529,7 +517,7 @@
private EndpointReference fetchMyRoleSessionEndpoint(PartnerLinkInstance pLink)
throws FaultException {
- PartnerLinkDAO pl = fetchEndpointReference(pLink, true);
+ PartnerLinkDAO pl = fetchPartnerLinkDAO(pLink);
Element myRoleEpr = pl.getMyEPR();
if (myRoleEpr == null) throw new FaultException(
_bpelProcess._oprocess.constants.qnUninitializedPartnerRole,
@@ -956,7 +944,6 @@
MessageExchange.Status status = MessageExchange.Status.valueOf(mex
.getStatus());
- sendEvent(evt);
switch (status) {
case FAULT:
@@ -971,6 +958,8 @@
responseChannel.onFailure();
break;
}
+ sendEvent(evt);
+
}
/**
@@ -1159,6 +1148,11 @@
public Node getPartData(Element message, Part part) {
Element partEl = DOMUtils.findChildByName((Element) message, new QName(
null, part.name), false);
+
+ // This could occur if the message does not contain the required part.
+ if (partEl == null)
+ return null;
+
Node container = DOMUtils.getFirstChildElement(partEl);
if (container == null)
container = partEl.getFirstChild(); // either a text node / element /