Merge "Reorder modifiers"
[so.git] / bpmn / MSOCommonBPMN / src / main / java / org / openecomp / mso / bpmn / common / workflow / service / AbstractCallbackService.java
index b1d1085..f61c692 100644 (file)
@@ -27,7 +27,7 @@ import java.util.Map;
 \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
@@ -38,7 +38,7 @@ import org.openecomp.mso.logger.MsoLogger;
 /**\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
@@ -46,8 +46,6 @@ public abstract class AbstractCallbackService {
        \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
@@ -74,7 +72,7 @@ public abstract class AbstractCallbackService {
                        + (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
@@ -196,7 +194,7 @@ public abstract class AbstractCallbackService {
 \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
@@ -245,12 +243,64 @@ public abstract class AbstractCallbackService {
                                .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
@@ -368,16 +418,4 @@ public abstract class AbstractCallbackService {
                                + ":" + 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