\r
import org.camunda.bpm.BpmPlatform;\r
import org.camunda.bpm.engine.MismatchingMessageCorrelationException;\r
-import org.camunda.bpm.engine.ProcessEngineServices;\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
/**\r
* Abstract base class for callback services.\r
*/\r
-public abstract class AbstractCallbackService {\r
+public abstract class AbstractCallbackService extends ProcessEngineAwareService {\r
public static final long DEFAULT_TIMEOUT_SECONDS = 60;\r
public static final long FAST_POLL_DUR_SECONDS = 5;\r
public static final long FAST_POLL_INT_MS = 100;\r
\r
private static final MsoLogger LOGGER = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL);\r
\r
- protected volatile ProcessEngineServices pes4junit = null;\r
- \r
/**\r
* Parameterized callback handler.\r
*/\r
+ (message == null ? "" : System.lineSeparator()) + message);\r
\r
try {\r
- Map<String, Object> variables = new HashMap<String, Object>();\r
+ Map<String, Object> variables = new HashMap<>();\r
\r
if (injectedVariables != null) {\r
variables.putAll(injectedVariables);\r
\r
int count = waitingProcesses.size();\r
\r
- List<ExecInfo> execInfoList = new ArrayList<ExecInfo>(count);\r
+ List<ExecInfo> execInfoList = new ArrayList<>(count);\r
for (Execution execution : waitingProcesses) {\r
execInfoList.add(new ExecInfo(execution));\r
}\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
+ ":" + execution.getId() + "]";\r
}\r
}\r
- \r
- protected ProcessEngineServices getProcessEngineServices() {\r
- if (pes4junit == null) {\r
- return BpmPlatform.getDefaultProcessEngine();\r
- } else {\r
- return pes4junit;\r
- }\r
- }\r
-\r
- public void setProcessEngineServices4junit(ProcessEngineServices pes) {\r
- pes4junit = pes;\r
- }\r
-}
\ No newline at end of file
+}\r