public async Task StopAgents()
        {
            managerState = RunState.AgentsStopped;
            List <QueueId> queuesToRemove = queuesToAgentsMap.Keys.ToList();

            Log(ErrorCode.PersistentStreamPullingManager_Stopping, "Stopping agents for {0} queues: {1}", queuesToRemove.Count, PrintQueues(queuesToRemove));
            await RemoveQueues(queuesToRemove);

            Log(ErrorCode.PersistentStreamPullingManager_Stopped, "Stopped agents.");
        }
        public async Task StartAgents()
        {
            managerState = RunState.AgentsStarted;
            List <QueueId> myQueues = queueBalancer.GetMyQueues().ToList();

            Log(ErrorCode.PersistentStreamPullingManager_Starting, "Starting agents for {0} queues: {1}", myQueues.Count, PrintQueues(myQueues));
            await AddNewQueues(myQueues, true);

            Log(ErrorCode.PersistentStreamPullingManager_Started, "Started agents.");
        }
        public async Task Initialize(Immutable <IQueueAdapter> qAdapter)
        {
            if (qAdapter.Value == null)
            {
                throw new ArgumentNullException("qAdapter", "Init: queueAdapter should not be null");
            }

            Log(ErrorCode.PersistentStreamPullingManager_02, "Init.");

            // Remove cast once we cleanup
            queueAdapter = qAdapter.Value;
            await this.queueBalancer.Initialize(this.streamProviderName, this.adapterFactory.GetStreamQueueMapper(), this.options.SiloMaturityPeriod);

            queueBalancer.SubscribeToQueueDistributionChangeEvents(this);

            List <QueueId> myQueues = queueBalancer.GetMyQueues().ToList();

            Log(ErrorCode.PersistentStreamPullingManager_03, String.Format("Initialize: I am now responsible for {0} queues: {1}.", myQueues.Count, PrintQueues(myQueues)));

            queuePrintTimer = this.RegisterTimer(AsyncTimerCallback, null, QUEUES_PRINT_PERIOD, QUEUES_PRINT_PERIOD);
            managerState    = RunState.Initialized;
        }