Beispiel #1
0
 public static void OnTimeoutNotificationReceived(Action_OperationTimeout _Notification)
 {
     lock (InterruptableWebServiceProcessors)
     {
         foreach (var ProcessorWeakPtr in InterruptableWebServiceProcessors)
         {
             if (ProcessorWeakPtr.TryGetTarget(out WebServiceBaseTimeoutableProcessor Processor))
             {
                 foreach (var TimeoutStructure in Processor.RelevantTimeoutStructures)
                 {
                     if (TimeoutStructure.Equals(_Notification))
                     {
                         Processor.TimeoutOccurred();
                         break;
                     }
                 }
             }
         }
     }
 }
Beispiel #2
0
        //In case of false return, operation shall be cancelled with an internal error.
        public bool GetClearanceForDBOperation(WebServiceBaseTimeoutableProcessor _ServiceProcessor, string _DBTableName, string _Identifier, Action <string> _ErrorMessageAction = null)
        {
            if (!_ServiceProcessor.IsDoNotGetDBClearanceSet())
            {
                return(true);
            }

            var CreatedAction = new Action_OperationTimeout(_DBTableName, _Identifier);

            lock (_ServiceProcessor.RelevantTimeoutStructures)
            {
                bool bFound = false;
                foreach (var CTS in _ServiceProcessor.RelevantTimeoutStructures)
                {
                    if (CTS.Equals(CreatedAction))
                    {
                        CreatedAction = CTS;
                        bFound        = true;
                        break;
                    }
                }
                if (!bFound)
                {
                    _ServiceProcessor.RelevantTimeoutStructures.Add(CreatedAction);
                }
            }

            var MemoryEntryValue = ATOMIC_DB_OP_CTRL_MEM_PREFIX + _DBTableName + "-" + _Identifier;

            if (_ServiceProcessor.IsUseQueueSetClearanceActionsSet() &&
                _ServiceProcessor.TryRemoveSetClearanceAwaitItem(MemoryEntryValue))
            {
                return(true);
            }

            int TrialCounter = 0;

            bool bResult;

            do
            {
                bResult = MemoryService.SetKeyValueConditionally(
                    QueryParameters,
                    new Tuple <string, BPrimitiveType>(MemoryEntryValue, new BPrimitiveType("busy")),
                    _ErrorMessageAction);

                if (!bResult)
                {
                    Thread.Sleep(1000);
                }
            }while (!bResult && TrialCounter++ < TIMEOUT_TRIAL_SECONDS);

            if (TrialCounter >= TIMEOUT_TRIAL_SECONDS)
            {
                _ErrorMessageAction?.Invoke("Atomic DB Operation Controller->GetClearanceForDBOperation: A timeout has occured for operation type " + _DBTableName + ", for ID " + _Identifier + ", existing operation has been overriden by the new request.");

                Manager_PubSubService.Get().PublishAction(Actions.EAction.ACTION_OPERATION_TIMEOUT, JsonConvert.SerializeObject(new Action_OperationTimeout()
                {
                    TableName = _DBTableName,
                    EntryKey  = _Identifier
                }),
                                                          _ErrorMessageAction);

                //Timeout for other operation has occured.
                return(MemoryService.SetKeyValue(QueryParameters, new Tuple <string, BPrimitiveType>[]
                {
                    new Tuple <string, BPrimitiveType>(MemoryEntryValue, new BPrimitiveType("busy"))
                },
                                                 _ErrorMessageAction));
            }

            return(true);
        }