import java.util.List;\r
import java.util.Map;\r
\r
+import org.camunda.bpm.BpmPlatform;\r
import org.camunda.bpm.engine.MismatchingMessageCorrelationException;\r
+import org.camunda.bpm.engine.OptimisticLockingException;\r
import org.camunda.bpm.engine.RuntimeService;\r
import org.camunda.bpm.engine.runtime.Execution;\r
import org.camunda.bpm.engine.runtime.MessageCorrelationResult;\r
.setVariables(variables)\r
.processInstanceVariableEquals(correlationVariable, correlationValue)\r
.correlateWithResult();\r
-\r
+ \r
} catch (MismatchingMessageCorrelationException e) {\r
// A correlation exception occurred even after we identified\r
// one waiting process. Throw it back to the client.\r
throw e;\r
- } catch (Exception e) {\r
+ } catch (OptimisticLockingException ole) {\r
+ \r
+ String msg = "Caught " + ole.getClass().getSimpleName() + " after receiving " + messageEventName\r
+ + " with " + correlationVariable + " = '" + correlationValue\r
+ + "': " + ole;\r
+ LOGGER.debug(msg);\r
+ LOGGER.error(MessageEnum.BPMN_GENERAL_EXCEPTION, "BPMN CORRELATION ERROR -", MsoLogger.getServiceName(),\r
+ MsoLogger.ErrorCode.UnknownError, msg, ole);\r
+ \r
+ //Retry for OptimisticLocking Exceptions\r
+ int retryCount = 0;\r
+ String retryStr = properties.get("mso.bpmn.optimisticlockingexception.retrycount");\r
+ if (retryStr != null) {\r
+ try {\r
+ retryCount = Integer.parseInt(retryStr);\r
+ } catch (NumberFormatException e) {\r
+ // Ignore\r
+ }\r
+ }\r
+ \r
+ LOGGER.debug("Retry correlate for OptimisticLockingException, retryCount:" + retryCount);\r
+ \r
+ for (; retryCount >0 ; retryCount--) {\r
+ \r
+ try{\r
+ Thread.sleep(SLOW_POLL_INT_MS);\r
+ \r
+ @SuppressWarnings("unused")\r
+ MessageCorrelationResult result = runtimeService\r
+ .createMessageCorrelation(messageEventName)\r
+ .setVariables(variables)\r
+ .processInstanceVariableEquals(correlationVariable, correlationValue)\r
+ .correlateWithResult();\r
+ retryCount = 0;\r
+ LOGGER.debug("OptimisticLockingException retry was successful, seting retryCount: " + retryCount);\r
+ } catch (OptimisticLockingException olex) {\r
+ //oleFlag = ex instanceof org.camunda.bpm.engine.OptimisticLockingException;\r
+ String strMsg = "Received exception, OptimisticLockingException retry failed, retryCount:" + retryCount + " | exception returned: " + olex;\r
+ LOGGER.debug(strMsg);\r
+ LOGGER.error(MessageEnum.BPMN_GENERAL_EXCEPTION, "BPMN", MsoLogger.getServiceName(),\r
+ MsoLogger.ErrorCode.UnknownError, strMsg, olex);\r
+ } catch (Exception excep) {\r
+ retryCount = 0;\r
+ //oleFlag = ex instanceof org.camunda.bpm.engine.OptimisticLockingException;\r
+ String strMsg = "Received exception, OptimisticLockingException retry failed, retryCount:" + retryCount + " | exception returned: " + excep;\r
+ LOGGER.debug(strMsg);\r
+ LOGGER.error(MessageEnum.BPMN_GENERAL_EXCEPTION, "BPMN", MsoLogger.getServiceName(),\r
+ MsoLogger.ErrorCode.UnknownError, strMsg, excep);\r
+ }\r
+ \r
+ }\r
+ \r
+ }catch (Exception e) {\r
// This must be an exception from the flow itself. Log it, but don't\r
// report it back to the client.\r
String msg = "Caught " + e.getClass().getSimpleName() + " running "\r