private (SubmissionProcessor <TSubmission> submissionProcessor, Thread thread) CreateRemoteWorker(
            int index,
            string endpoint,
            ConcurrentQueue <TSubmission> submissionsForProcessing,
            object sharedLockObject,
            IFormatterServiceFactory formatterServiceFactory,
            ISubmissionsFilteringService submissionsFilteringService)
        {
            var worker = new RemoteSubmissionsWorker(
                endpoint,
                formatterServiceFactory,
                this.Logger);

            var submissionProcessor = new SubmissionProcessor <TSubmission>(
                name: $"RSP #{index}",
                dependencyContainer: this.DependencyContainer,
                submissionsForProcessing: submissionsForProcessing,
                sharedLockObject: sharedLockObject,
                submissionsFilteringService: submissionsFilteringService,
                submissionWorker: worker);

            var thread = new Thread(submissionProcessor.Start)
            {
                Name = $"{nameof(Thread)} #{index}"
            };

            return(submissionProcessor, thread);
        }
        private IEnumerable <(SubmissionProcessor <TSubmission> submissionProcessor, Thread thread)> GetRemoteWorkers(
            IEnumerable <string> remoteWorkerEndpoints,
            ConcurrentQueue <TSubmission> submissionsForProcessing,
            object sharedLockObject,
            IFormatterServiceFactory formatterServiceFactory,
            ISubmissionsFilteringService submissionsFilteringService)
        {
            var remoteWorkerEndpointsList = remoteWorkerEndpoints.ToList();

            return(Enumerable.Range(0, remoteWorkerEndpointsList.Count)
                   .Select(index => this.CreateRemoteWorker(
                               index + 1,
                               remoteWorkerEndpointsList[index],
                               submissionsForProcessing,
                               sharedLockObject,
                               formatterServiceFactory,
                               submissionsFilteringService)));
        }
        public SubmissionProcessor(
            string name,
            IDependencyContainer dependencyContainer,
            ConcurrentQueue <TSubmission> submissionsForProcessing,
            object sharedLockObject,
            ISubmissionsFilteringService submissionsFilteringService,
            ISubmissionWorker submissionWorker)
        {
            this.Name = name;

            this.Logger = LogManager.GetLogger(typeof(SubmissionProcessor <TSubmission>));
            this.Logger.Info($"{nameof(SubmissionProcessor<TSubmission>)} initializing...");

            this.stopping = false;

            this.dependencyContainer         = dependencyContainer;
            this.submissionsForProcessing    = submissionsForProcessing;
            this.sharedLockObject            = sharedLockObject;
            this.submissionsFilteringService = submissionsFilteringService;
            this.SubmissionWorker            = submissionWorker;

            this.Logger.Info($"{nameof(SubmissionProcessor<TSubmission>)} initialized.");
        }
        private (SubmissionProcessor <TSubmission> submissionProcessor, Thread thread) CreateLocalWorker(int index,
                                                                                                         ConcurrentQueue <TSubmission> submissionsForProcessing,
                                                                                                         object sharedLockObject,
                                                                                                         ISubmissionsFilteringService submissionsFilteringService)
        {
            var worker = new LocalSubmissionWorker(Settings.GanacheCliDefaultPortNumber + index);
            var submissionProcessor = new SubmissionProcessor <TSubmission>(
                name: $"LSP #{index}",
                dependencyContainer: this.DependencyContainer,
                submissionsForProcessing: submissionsForProcessing,
                sharedLockObject: sharedLockObject,
                submissionsFilteringService: submissionsFilteringService,
                submissionWorker: worker);

            var thread = new Thread(submissionProcessor.Start)
            {
                Name = $"{nameof(Thread)} #{index}"
            };

            return(submissionProcessor, thread);
        }
 private IEnumerable <(SubmissionProcessor <TSubmission> submissionProcessor, Thread thread)> GetLocalWorkers(
     int count,
     ConcurrentQueue <TSubmission> submissionsForProcessing,
     object sharedLockObject,
     ISubmissionsFilteringService submissionsFilteringService)
 => Enumerable.Range(0, count)