Esempio n. 1
0
 void Run()
 {
     //_systemLogger.Trace($"Is ThreadPoolThread {Thread.CurrentThread.IsThreadPoolThread}");
     try
     {
         var res = Parallel.ForEach(_taskContextsQueue.GetConsumingPartitioner(),
                                    new ParallelOptions {
             CancellationToken = _processToken, MaxDegreeOfParallelism = _maxConsumers
         },
                                    ExecuteTask);
         //_systemLogger.Trace($"Is ThreadPool Thread {Thread.CurrentThread.IsThreadPoolThread}");
         _logger.Trace(
             $"Consumer process {_processId} stopped gracefully with completion flag: {res.IsCompleted}");
     }
     catch (TaskCanceledException e)
     {
         var msg =
             $"Consumer canceled for Process: {_processKey} by token {(_processToken.IsCancellationRequested ? "ProcessToken" : (_parentToken.IsCancellationRequested ? "ParentToken" : "NoToken"))} with msg {e.Message}";
         _systemLogger.Info(msg);
     }
     catch (OperationCanceledException e)
     {
         var msg =
             $"Consumer canceled for Process: {_processKey} by token {(_processToken.IsCancellationRequested ? "ProcessToken" : (_parentToken.IsCancellationRequested ? "ParentToken" : "NoToken"))} with msg {e.Message}";
         _systemLogger.Info(msg);
     }
     catch (AggregateException e)
     {
         //probably thread abort exception
         _systemLogger.Warn(
             $"Consumer got exception while processing Process: {_processKey} with message {e.InnerException?.Message ?? string.Empty}",
             e);
         //e.Handle(ex =>
         foreach (var ex in e.InnerExceptions)
         {
             if (ex is ThreadAbortException)
             {
                 Robustness.Instance.SafeCall(Thread.ResetAbort);
             }
             //return true;
         } //);
     }
     catch (ThreadAbortException)
     {
         _systemLogger.Warn(
             $"Consumer got ThreadAbortException while processing Process: {_processKey} with message");
         Robustness.Instance.SafeCall(Thread.ResetAbort);
     }
     catch (Exception e)
     {
         _logger.Error($"Consumer stopped unexpectedly Process: {_processKey} with message {e.Message}", e);
     }
     //finally
     //{
     //    _systemLogger.Trace($"Consumer final for Process: {_processKey}");
     //}
 }
Esempio n. 2
0
        public IDistributedMessageSubscriber GetSubscriber(CancellationToken token, ILogger logger, string channelName = null)
        {
            var ch = channelName ?? PubChannel;


            UdpVirtualSubscriber virtualSubscriber = new UdpVirtualSubscriber((s) =>
            {
                lock (_lock)
                {
                    _activeSubscribers.Remove(s);
                    _systemLogger.Trace("UDP PubSub channel {channel} removed", s.Channel);
                    if (_activeSubscribers.Count == 0)
                    {
                        _portSubscriber?.Dispose();
                        _portSubscriber = null;
                        _systemLogger.Info("UDP PubSub UDP listener closed due to empty subscribers");
                    }
                }
            }, ch);

            lock (_lock)
            {
                _activeSubscribers.Add(virtualSubscriber);

                if (_portSubscriber == null)
                {
                    _portSubscriber = new UdpPortSubscriber(_ip, _port, _systemLogger, OnUdpMessage);
                }
                _portSubscriber.StartIfNot();
            }

            return(virtualSubscriber);
        }
Esempio n. 3
0
        private void SwitchToLocalWatchDog()
        {
            _watchDogSync.EnterWriteLock();
            try
            {
                _logger.Info("Switching to Master node");
                _watchDogCancellationTokenSource?.Cancel();

                if (_cancellationToken.IsCancellationRequested)
                {
                    _logger.Info("Bus stopped, can't switch to slave node");
                    return;
                }

                _watchDogCancellationTokenSource = CancellationTokenSource.CreateLinkedTokenSource(_cancellationToken);

                var volumePipeline = new ProcessVolumePipeline(_watchDogCancellationTokenSource.Token, _logger, _stateManager, _cacheAside, _processRepository, VolumeHandler, _resolver, EventAggregator, _branchEngineSubscriber);//todo move to watchdog class
                var watchDog       = new ProcessWatchDog(_logger, _stateManager, _branchEngineSubscriber, _cacheAside, SerializersFactory.Instance, EntityFactory,
                                                         EventAggregator, _storage, PubSubFactory, _resolver, _batchLoggerFactory, _processRepository, volumePipeline);
                _watchDogPipeline = new Pipeline <IWatchDogMessage>(watchDog);

                _watchDogCancellationTokenSource.Token.Register(() =>
                {
                    _logger.Info("Master node ended");
                    _logger.Debug("Master node ended");
                    watchDog.Dispose();
                });

                watchDog.Start(_watchDogCancellationTokenSource.Token);


                _processRepository.InvokeOnMaster();

                _leaderManager.InitializationComplete();
                _logger.Info("Switching to Master node complete");
                _logger.Debug("Running Master node");
            }
            catch (Exception e)
            {
                _logger.Error("Error switching watchdog to primary node", e);
            }
            finally
            {
                _watchDogSync.ExitWriteLock();
            }
        }
Esempio n. 4
0
        private void OnProcessVolumeError(VolumeErrorMessage msg)
        {
            var state  = msg.Content.WritableProcessState;
            var config = msg.Content.Configuration;

            if (config.ErrorThreshold.HasValue && config.ErrorThreshold.Value > 0)
            //if (_runningGroups.TryGetValue(state.GroupId, out SubmittedGroup grp))
            {
                var message = $"Process QId {state.Id}, PId {state.ProcessId} volume generation failed. Going to stop group.";
                msg.Content.Logger.Error(message);
                try
                {
                    _groupsHandler.StopGroup(msg.Content.GroupEntity, message);
                }
                catch (Exception e)
                {
                    _systemLogger.Fatal("Failed to stop group with error {error}", e);
                }
            }
            else
            {
                _systemLogger.Info("VolumeError: Process ErrorThreshold not configured.");
            }
        }
Esempio n. 5
0
        /// <summary>
        ///     원본 프로바이더인 <paramref name="sourceProvider"/> 를 대상 프로바이더인 <paramref name="targetProvider"/> 로 매핑을 수행합니다.
        /// </summary>
        /// <param name="sourceProvider">	<see cref="IMappingProvider"/> 를 구현하는 원본 프로바이더 객체입니다. </param>
        /// <param name="targetProvider">	<see cref="IMappingProvider"/> 를 구현하는 원본 프로바이더 객체입니다.	</param>
        protected void Assign(IMappingProvider sourceProvider, IMappingProvider targetProvider)
        {
            var sourceKeys = sourceProvider.MappingKeys;

            //while( sourceProvider.MoveNext() && targetProvider.CanCreateNewInstance)
            //{
            //    sourceProvider.MoveNext();

            var sbDebug = new StringBuilder(2048);

            sbDebug.AppendLine("Assign");
            sbDebug.AppendLine(string.Format("sourceProvider:{0}, targetProvider:{1}", sourceProvider.GetObject().GetType(), targetProvider.GetObject().GetType()));

            targetProvider.StartOfAssign(sourceProvider, targetProvider);
            foreach (var key in sourceKeys)
            {
                if (sourceProvider.CanGetter(key) != true)
                {
                    continue;
                }

                var sourceValue = sourceProvider.Getter(key);
                if (sourceValue is DBNull || sourceValue == DBNull.Value)
                {
                    continue;
                }

                if (targetProvider.CanSetter(key) != true)
                {
                    continue;
                }
                if (this.Mapper.ContainsKey((TInput)key))
                {
                    this.GetMappingValue((TInput)key);
                }
                else
                {
                    if (sourceProvider is IMappingCollectionProvider && targetProvider is IMappingCollectionProvider)
                    {
                        this.Map((TInput)key).Return(o => ((IMappingCollectionProvider)targetProvider).SetValues(targetProvider.CreateNewInstance(), ((IMappingCollectionProvider)sourceProvider).GetValues(sourceValue)));
                        this.GetMappingValue((TInput)key);
                        continue;
                    }

                    this.Map((TInput)key).Return(o => targetProvider.Setter(o, sourceValue));
                    this.GetMappingValue((TInput)key);

                    if (sourceValue != null && sourceValue.GetType() == typeof(byte[]))
                    {
                        sourceValue = "byte[] { " + BitConverter.ToString((byte[])sourceValue) + " }";
                    }

                    sbDebug.AppendLine(string.Format("\t{0}.{1} => {2}.{3} = {4}", sourceProvider.GetObject().GetType().Name, key,
                                                     targetProvider.GetObject().GetType().Name, key,
                                                     sourceValue));
                }
            }

            targetProvider.EndOfAssign(sourceProvider, targetProvider);

            logger.Info(sbDebug);
            //}
        }