private void SetupPool() { var names = new List <string>(); foreach (var p in _peerManager.GetPeers()) { names.Add(Queues.PeerAppendLog + p.Address); } names.Add(Queues.LogCommit); names.Add(Queues.HeartBeatReceiveAndCandidacy); names.Add(Queues.HeartBeatSend); names.Add(Queues.ProcessCommandQueue); names.Add(Queues.CreateSnapshot); _workers = new WorkerPool(names.ToArray()); _workers.Start(); // LogCommit Func <CancellationToken, Task> logCommit = LogCommit; _workers.Enqueue(Queues.LogCommit, new Job(logCommit, TheTrace.LogPolicy(_meAsAPeer.ShortName).RetryForeverAsync(), _settings.ElectionTimeoutMin.Multiply(0.2))); // receiving heartbeat Func <CancellationToken, Task> hbr = HeartBeatReceive; _workers.Enqueue(Queues.HeartBeatReceiveAndCandidacy, new Job(hbr, TheTrace.LogPolicy(_meAsAPeer.ShortName).RetryForeverAsync(), _settings.ElectionTimeoutMin.Multiply(0.2))); // sending heartbeat Func <CancellationToken, Task> hbs = HeartBeatSend; _workers.Enqueue(Queues.HeartBeatSend, new Job(hbs, TheTrace.LogPolicy(_meAsAPeer.ShortName).RetryForeverAsync(), _settings.ElectionTimeoutMin.Multiply(0.2))); // Applying commands received from the clients Func <CancellationToken, Task> cs = CreateSnapshot; _workers.Enqueue(Queues.CreateSnapshot, new Job(cs, TheTrace.LogPolicy(_meAsAPeer.ShortName).WaitAndRetryAsync(2, (i) => TimeSpan.FromMilliseconds(i * i * 50)), _settings.ElectionTimeoutMin.Multiply(0.2))); TheTrace.TraceInformation($"[{_meAsAPeer.ShortName}] Setup finished."); }