// Is this a /possible/ createInstance Operation?
boolean isCreateInstance = _plinkDef.isCreateInstanceOperation(operation);
String correlatorId = ODEProcess.genCorrelatorId(_plinkDef, operation.getName());
CorrelatorDAO correlator = _process.getProcessDAO().getCorrelator(correlatorId);
MessageRouteDAO messageRoute = null;
// 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!
CorrelationKey[] processKeys, uniqueKeys;
// 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.
try {
processKeys = computeCorrelationKeys(mex, operation);
uniqueKeys = computeUniqueCorrelationKeys(mex, operation);
} catch (InvalidMessageException ime) {
// We'd like to do a graceful exit here, no sense in rolling back due to a
// a message format problem.
__log.debug("Unable to evaluate correlation keys, invalid message format. ", ime);
MexDaoUtil.setFailed(mex, FailureType.FORMAT_ERROR, ime.getMessage());
return null;
}
String mySessionId = mex.getProperty(MessageExchange.PROPERTY_SEP_MYROLE_SESSIONID);
String partnerSessionId = mex.getProperty(MessageExchange.PROPERTY_SEP_PARTNERROLE_SESSIONID);
if (__log.isDebugEnabled()) {
__log.debug("INPUTMSG: " + correlatorId + ": MSG RCVD keys=" + CollectionUtils.makeCollection(HashSet.class, processKeys)
+ " mySessionId=" + mySessionId + " partnerSessionId=" + partnerSessionId);
}
CorrelationKey matchedKey = null;
// Try to find a route for one of our keys.
for (CorrelationKey key : processKeys) {
messageRoute = correlator.findRoute(key);
if (messageRoute != null) {
if (__log.isDebugEnabled()) {
__log.debug("INPUTMSG: " + correlatorId + ": ckey " + key + " ROUTED TO (grp,index,iid) = (" + messageRoute.getGroupId() + "," + messageRoute.getIndex() + ", " + messageRoute.getTargetInstance().getInstanceId() + ")");
}
matchedKey = key;
break;
}
}
// TODO - ODE-58
// If no luck, and this operation qualifies for create-instance
// treatment, then create a new process
// instance.
if (messageRoute == null && isCreateInstance) {
invokeMyRoleCreateInstance(mex, operation, correlatorId, correlator, uniqueKeys);
} else if (messageRoute != null) {
if (__log.isDebugEnabled()) {
__log.debug("INPUTMSG: " + correlatorId + ": ROUTING to instance "
+ messageRoute.getTargetInstance().getInstanceId());
}
ProcessInstanceDAO instanceDAO = messageRoute.getTargetInstance();
ProcessDAO processDAO = instanceDAO.getProcess();
enforceUniqueConstraint(processDAO, uniqueKeys);
// Reload process instance for DAO.
// Kill the route so some new message does not get routed to
// same process instance.
correlator.removeRoutes(messageRoute.getGroupId(), instanceDAO);
// send process instance event
CorrelationMatchEvent evt = new CorrelationMatchEvent(_process.getProcessModel().getQName(),
_process.getProcessDAO().getProcessId(), instanceDAO.getInstanceId(), matchedKey);
evt.setPortType(mex.getPortType());
evt.setOperation(operation.getName());
evt.setMexId(mex.getMessageExchangeId());
_process._debugger.onEvent(evt);
// store event
_process.saveEvent(evt, instanceDAO);
mex.setCorrelationStatus(MyRoleMessageExchange.CorrelationStatus.MATCHED.toString());
mex.setInstance(messageRoute.getTargetInstance());
// We're overloading the channel here to be the PICK response channel + index
mex.setChannel(messageRoute.getGroupId() + "&" + messageRoute.getIndex());
} else {
if (__log.isDebugEnabled()) {
__log.debug("INPUTMSG: " + correlatorId + ": SAVING to DB (no match) ");
}