public AutomaticRetryServerComponentWrapper(
            [NotNull] IServerComponent innerComponent,
            int maxRetryAttempts,
            [NotNull] Func <int, TimeSpan> delayCallback)
        {
            if (innerComponent == null)
            {
                throw new ArgumentNullException("innerComponent");
            }
            if (delayCallback == null)
            {
                throw new ArgumentNullException("delayCallback");
            }
            if (maxRetryAttempts < 0)
            {
                throw new ArgumentOutOfRangeException(
                          "maxRetryAttempts",
                          "MaxRetryAttempts property value must be greater or equal to 0.");
            }

            _innerComponent   = innerComponent;
            _maxRetryAttempts = maxRetryAttempts;
            _delayCallback    = delayCallback;
            _logger           = LogManager.GetLogger(_innerComponent.GetType());
        }
Exemple #2
0
        public ConfigurationModel GetConfiguration(IServerComponent component)
        {
            ConfigurationModel c;

            _configurations.TryGetValue(component.GetId(), out c);
            return(c);
        }
Exemple #3
0
#pragma warning disable CS0618 // Type or member is obsolete
        public static ITaskSource Wrap(this IServerComponent component)
#pragma warning restore CS0618 // Type or member is obsolete
        {
            if (component == null)
            {
                throw new ArgumentNullException(nameof(component));
            }

            return(new ServerComponentWrapper(component));
        }
        public ServerComponentWrapper(IServerComponent component)
#pragma warning restore CS0618 // Type or member is obsolete
        {
            if (component == null)
            {
                throw new ArgumentNullException(nameof(component));
            }

            _component = component;
        }
        public AutomaticRetryServerComponentWrapper([NotNull] IServerComponent innerComponent)
        {
            if (innerComponent == null) throw new ArgumentNullException("innerComponent");

            _innerComponent = innerComponent;
            _logger = LogProvider.GetLogger(_innerComponent.GetType());
            
            MaxRetryAttempts = DefaultMaxRetryAttempts;
            MaxAttemptDelay = DefaultMaxAttemptDelay;
            DelayCallback = GetBackOffMultiplier;
        }
Exemple #6
0
        public bool AddJob(IServerComponent component, IDownloadBatch batch, int maxCapacity)
        {
            var quenue = GetProcessingQueue(component);

            if (quenue.Count > maxCapacity)
            {
                return(false);
            }
            _log.Log(LogLevel.Information, this, component, "add downloadJob");
            quenue.Enqueue(batch);
            return(true);
        }
        public ServerSupervisor(IServerComponent component, ServerSupervisorOptions options)
        {
            if (component == null) throw new ArgumentNullException("component");
            if (options == null) throw new ArgumentNullException("options");

            _component = component;
            _options = options;

            _logger = LogManager.GetLogger(_component.GetType());
            _thread = new Thread(RunComponent) { IsBackground = true, Name = component.ToString() };

            _logger.TraceFormat("Starting a new thread for server component '{0}'...", _component);
            _thread.Start();
        }
Exemple #8
0
        public AutomaticRetryServerComponentWrapper([NotNull] IServerComponent innerComponent)
        {
            if (innerComponent == null)
            {
                throw new ArgumentNullException("innerComponent");
            }

            _innerComponent = innerComponent;
            _logger         = LogProvider.GetLogger(_innerComponent.GetType());

            MaxRetryAttempts = DefaultMaxRetryAttempts;
            MaxAttemptDelay  = DefaultMaxAttemptDelay;
            DelayCallback    = GetBackOffMultiplier;
        }
 public ServerProcessDispatcherBuilder(
     [NotNull] IServerComponent component,
     [NotNull] Func <ThreadStart, IEnumerable <Thread> > threadFactory)
 {
     if (component == null)
     {
         throw new ArgumentNullException(nameof(component));
     }
     if (threadFactory == null)
     {
         throw new ArgumentNullException(nameof(threadFactory));
     }
     _component     = component;
     _threadFactory = threadFactory;
 }
Exemple #10
0
        public void Arrange()
        {
            var serverMock = new Mock <IServerInstance>();

            serverMock.Setup(s => s.GetServerInstance()).Returns("New Server For Tests");

            _server = serverMock.Object;

            var serverComponentMock = new Mock <ServerComponent>(_server)
            {
                CallBase = true
            };

            serverComponentMock.Setup(s => s.Execute(It.IsAny <int>()));

            _serverComponent = serverComponentMock.Object;
        }
        public AutomaticRetryServerComponentWrapper(
            [NotNull] IServerComponent innerComponent,
            int maxRetryAttempts, 
            [NotNull] Func<int, TimeSpan> delayCallback)
        {
            if (innerComponent == null) throw new ArgumentNullException("innerComponent");
            if (delayCallback == null) throw new ArgumentNullException("delayCallback");
            if (maxRetryAttempts < 0)
            {
                throw new ArgumentOutOfRangeException(
                    "maxRetryAttempts",
                    "MaxRetryAttempts property value must be greater or equal to 0.");
            }

            _innerComponent = innerComponent;
            _maxRetryAttempts = maxRetryAttempts;
            _delayCallback = delayCallback;
            _logger = LogManager.GetLogger(_innerComponent.GetType());
        }
Exemple #12
0
        public ServerSupervisor(IServerComponent component, ServerSupervisorOptions options)
        {
            if (component == null)
            {
                throw new ArgumentNullException("component");
            }
            if (options == null)
            {
                throw new ArgumentNullException("options");
            }

            _component = component;
            _options   = options;

            _logger = LogProvider.GetLogger(_component.GetType());
            _thread = new Thread(RunComponent)
            {
                IsBackground = true, Name = component.ToString()
            };

            _logger.TraceFormat("Starting a new thread for server component '{0}'...", _component);
            _thread.Start();
        }
 private static ServerSupervisor CreateSupervisor(IServerComponent component)
 {
     return new ServerSupervisor(new AutomaticRetryServerComponentWrapper(component));
 }
Exemple #14
0
 public void RegisterComponent(IServerComponent component)
 {
     component.Configure(_serviceProvider);
     _components.Enqueue(new ComponentContainer(component));
     _log.Log(LogLevel.Information, this, component, $"registred component:{component.GetName()}:{component.GetId()}");
 }
Exemple #15
0
 public ServerSupervisor(IServerComponent component)
     : this(component, new ServerSupervisorOptions())
 {
 }
 private static ServerSupervisor CreateSupervisor(IServerComponent component, ServerSupervisorOptions options)
 {
     return new ServerSupervisor(new AutomaticRetryServerComponentWrapper(component), options);
 }
Exemple #17
0
 private static ServerSupervisor CreateSupervisor(IServerComponent component)
 {
     return(new ServerSupervisor(new AutomaticRetryServerComponentWrapper(component)));
 }
Exemple #18
0
 private static ServerSupervisor CreateSupervisor(IServerComponent component)
 {
     return(CreateSupervisor(component, new ServerSupervisorOptions()));
 }
 private static ServerSupervisor CreateSupervisor(IServerComponent component)
 {
     return CreateSupervisor(component, new ServerSupervisorOptions());
 }
 public ComponentContainer(IServerComponent component)
 {
     Component = component;
     Reset();
 }
Exemple #21
0
 public bool GetCompleted(IServerComponent component, out IDownloadBatch batch)
 {
     return(GetCompleteQueue(component).TryDequeue(out batch));
 }
Exemple #22
0
 private ConcurrentQueue <IDownloadBatch> GetProcessingQueue(IServerComponent component)
 {
     return(_processing.GetOrAdd(component, new ConcurrentQueue <IDownloadBatch>()));
 }
Exemple #23
0
 private ConcurrentQueue <IDownloadBatch> GetCompleteQueue(IServerComponent component)
 {
     return(_complete.GetOrAdd(component, new ConcurrentQueue <IDownloadBatch>()));
 }
Exemple #24
0
 public static bool Add(this IServerComponent isc, int a, int b, int c)
 {
     return(isc.Add(a, b) && isc.Add(b, c) && isc.Add(c, a));
 }
 public AutomaticRetryServerComponentWrapper([NotNull] IServerComponent innerComponent)
     : this(innerComponent, DefaultMaxRetryAttempts)
 {
 }
 public AutomaticRetryServerComponentWrapper(
     [NotNull] IServerComponent innerComponent,
     int maxRetryAttempts)
     : this(innerComponent, maxRetryAttempts, GetBackOffMultiplier)
 {
 }
 public ServerSupervisor(IServerComponent component)
     : this(component, new ServerSupervisorOptions())
 {
 }
Exemple #28
0
 private static void StartLegacyServerAndExecuteFunctions(IServerComponent serverComponent)
 {
     Console.WriteLine(serverComponent.ExecuteSomeFunction(DefaultTimeout));
     Console.WriteLine(serverComponent.ExecuteAnotherFunction(DefaultTimeout));
 }