/// <summary>
 /// Constructor
 /// </summary>
 public LeaseBasedQueueBalancer(string name, LeaseBasedQueueBalancerOptions options, ILeaseProvider leaseProvider, ITimerRegistry timerRegistry, IServiceProvider services, ILoggerFactory loggerFactory)
     : base(services, loggerFactory.CreateLogger($"{nameof(LeaseBasedQueueBalancer)}-{name}"))
 {
     this.options       = options;
     this.leaseProvider = leaseProvider;
     this.timerRegistry = timerRegistry;
     this.executor      = new AsyncSerialExecutor();
     this.myQueues      = new List <AcquiredQueue>();
 }
 public StreamProviderManagerAgent(Silo silo, List<IProvider> allSiloProviders)
     : base(Constants.StreamProviderManagerAgentSystemTargetId, silo.SiloAddress)
 {
     logger = LogManager.GetLogger("StreamProviderUpdateAgent", LoggerType.Runtime);
     this.streamProviderManager = (StreamProviderManager)silo.StreamProviderManager;
     providerConfigurations = silo.GlobalConfig.ProviderConfigurations;
     this.allSiloProviders = allSiloProviders;
     nonReentrancyGuarantor = new AsyncSerialExecutor();
 }
 public StreamProviderManagerAgent(Silo silo, List <IProvider> allSiloProviders)
     : base(Constants.StreamProviderManagerAgentSystemTargetId, silo.SiloAddress)
 {
     logger = LogManager.GetLogger("StreamProviderUpdateAgent", LoggerType.Runtime);
     this.streamProviderManager = (StreamProviderManager)silo.StreamProviderManager;
     providerConfigurations     = silo.GlobalConfig.ProviderConfigurations;
     this.allSiloProviders      = allSiloProviders;
     nonReentrancyGuarantor     = new AsyncSerialExecutor();
 }
Esempio n. 4
0
        public StreamProviderManagerAgent(Silo silo, IStreamProviderRuntime streamProviderRuntime, ILoggerFactory loggerFactory)
            : base(Constants.StreamProviderManagerAgentSystemTargetId, silo.SiloAddress, loggerFactory)

        {
            logger = loggerFactory.CreateLogger <StreamProviderManagerAgent>();
            this.streamProviderManager = (StreamProviderManager)silo.StreamProviderManager;
            providerConfigurations     = silo.GlobalConfig.ProviderConfigurations;
            this.streamProviderRuntime = streamProviderRuntime;
            nonReentrancyGuarantor     = new AsyncSerialExecutor();
        }
Esempio n. 5
0
 public TransactionalState(ITransactionalStateConfiguration transactionalStateConfiguration, IGrainActivationContext context, ITransactionDataCopier <TState> copier, ITransactionAgent transactionAgent, IProviderRuntime runtime, ILoggerFactory loggerFactory)
 {
     this.config           = transactionalStateConfiguration;
     this.context          = context;
     this.copier           = copier;
     this.transactionAgent = transactionAgent;
     this.runtime          = runtime;
     this.logger           = loggerFactory.CreateLogger($"{this.GetType().FullName}.{this.context.GrainIdentity}.{this.config.StateName}");
     this.transactionCopy  = new Dictionary <long, TState>();
     this.storageExecutor  = new AsyncSerialExecutor <bool>();
     this.log = new SortedDictionary <long, LogRecord <TState> >();
 }
        public async Task AsyncSerialExecutorTests_SerialSubmit()
        {
            AsyncSerialExecutor executor = new AsyncSerialExecutor();
            List <Task>         tasks    = new List <Task>();

            for (int i = 0; i < 10; i++)
            {
                int capture = i;
                output.WriteLine("Submitting Task {0}.", capture);
                tasks.Add(executor.AddNext(() => Operation(capture)));
            }
            await Task.WhenAll(tasks);
        }
        public async Task AsyncSerialExecutorTests_Small()
        {
            AsyncSerialExecutor executor = new AsyncSerialExecutor();
            List <Task>         tasks    = new List <Task>();

            operationsInProgress = 0;

            tasks.Add(executor.AddNext(() => Operation(1)));
            tasks.Add(executor.AddNext(() => Operation(2)));
            tasks.Add(executor.AddNext(() => Operation(3)));

            await Task.WhenAll(tasks);
        }
Esempio n. 8
0
        public async Task AsyncSerialExecutorTests_Small()
        {
            var executor = new AsyncSerialExecutor();
            var tasks    = new List <Task>();

            _random = new SafeRandom();
            _operationsInProgress = 0;

            tasks.Add(executor.AddNext(() => Operation(1)));
            tasks.Add(executor.AddNext(() => Operation(2)));
            tasks.Add(executor.AddNext(() => Operation(3)));

            await Task.WhenAll(tasks);
        }
        public async Task AsyncSerialExecutorTests_SerialSubmit()
        {
            AsyncSerialExecutor executor = new AsyncSerialExecutor();

            random = new SafeRandom();
            List <Task> tasks = new List <Task>();

            for (int i = 0; i < 10; i++)
            {
                int capture = i;
                logger.Info("Submitting Task {0}.", capture);
                tasks.Add(executor.AddNext(() => Operation(capture)));
            }
            await Task.WhenAll(tasks);
        }
        internal PersistentStreamPullingManager(
            SystemTargetGrainId managerId,
            string strProviderName,
            IStreamProviderRuntime runtime,
            IStreamPubSub streamPubSub,
            IQueueAdapterFactory adapterFactory,
            IStreamQueueBalancer streamQueueBalancer,
            IStreamFilter streamFilter,
            StreamPullingAgentOptions options,
            ILoggerFactory loggerFactory,
            SiloAddress siloAddress)
            : base(managerId, siloAddress, lowPriority: false, loggerFactory)
        {
            if (string.IsNullOrWhiteSpace(strProviderName))
            {
                throw new ArgumentNullException("strProviderName");
            }
            if (runtime == null)
            {
                throw new ArgumentNullException("runtime", "IStreamProviderRuntime runtime reference should not be null");
            }
            if (streamPubSub == null)
            {
                throw new ArgumentNullException("streamPubSub", "StreamPubSub reference should not be null");
            }
            if (streamQueueBalancer == null)
            {
                throw new ArgumentNullException("streamQueueBalancer", "IStreamQueueBalancer streamQueueBalancer reference should not be null");
            }

            queuesToAgentsMap      = new Dictionary <QueueId, PersistentStreamPullingAgent>();
            streamProviderName     = strProviderName;
            providerRuntime        = runtime;
            pubSub                 = streamPubSub;
            this.options           = options;
            nonReentrancyGuarantor = new AsyncSerialExecutor();
            latestRingNotificationSequenceNumber = 0;
            latestCommandNumber = 0;
            queueBalancer       = streamQueueBalancer;
            this.streamFilter   = streamFilter;
            this.adapterFactory = adapterFactory;

            queueAdapterCache = adapterFactory.GetQueueAdapterCache();
            logger            = loggerFactory.CreateLogger($"{GetType().FullName}.{streamProviderName}");
            Log(ErrorCode.PersistentStreamPullingManager_01, "Created {0} for Stream Provider {1}.", GetType().Name, streamProviderName);
            this.loggerFactory = loggerFactory;
            IntValueStatistic.FindOrCreate(new StatisticName(StatisticNames.STREAMS_PERSISTENT_STREAM_NUM_PULLING_AGENTS, strProviderName), () => queuesToAgentsMap.Count);
        }
        internal PersistentStreamPullingManager(
            GrainId id,
            string strProviderName,
            IStreamProviderRuntime runtime,
            IStreamPubSub streamPubSub,
            IQueueAdapterFactory adapterFactory,
            IStreamQueueBalancer streamQueueBalancer,
            TimeSpan queueGetPeriod,
            TimeSpan initQueueTimeout,
            TimeSpan maxEvenDeliveryTime)
            : base(id, runtime.ExecutingSiloAddress)
        {
            if (string.IsNullOrWhiteSpace(strProviderName))
            {
                throw new ArgumentNullException("strProviderName");
            }
            if (runtime == null)
            {
                throw new ArgumentNullException("runtime", "IStreamProviderRuntime runtime reference should not be null");
            }
            if (streamPubSub == null)
            {
                throw new ArgumentNullException("streamPubSub", "StreamPubSub reference should not be null");
            }
            if (streamQueueBalancer == null)
            {
                throw new ArgumentNullException("streamQueueBalancer", "IStreamQueueBalancer streamQueueBalancer reference should not be null");
            }

            queuesToAgentsMap                    = new Dictionary <QueueId, PersistentStreamPullingAgent>();
            streamProviderName                   = strProviderName;
            providerRuntime                      = runtime;
            pubSub                               = streamPubSub;
            this.queueGetPeriod                  = queueGetPeriod;
            this.initQueueTimeout                = initQueueTimeout;
            this.maxEvenDeliveryTime             = maxEvenDeliveryTime;
            nonReentrancyGuarantor               = new AsyncSerialExecutor();
            latestRingNotificationSequenceNumber = 0;
            latestCommandNumber                  = 0;
            queueBalancer                        = streamQueueBalancer;
            this.adapterFactory                  = adapterFactory;

            queueAdapterCache = adapterFactory.GetQueueAdapterCache();
            logger            = providerRuntime.GetLogger(GetType().Name + "-" + streamProviderName);
            logger.Info((int)ErrorCode.PersistentStreamPullingManager_01, "Created {0} for Stream Provider {1}.", GetType().Name, streamProviderName);

            IntValueStatistic.FindOrCreate(new StatisticName(StatisticNames.STREAMS_PERSISTENT_STREAM_NUM_PULLING_AGENTS, strProviderName), () => queuesToAgentsMap.Count);
        }
Esempio n. 12
0
        public async Task AsyncSerialExecutorTests_SerialSubmit()
        {
            var executor = new AsyncSerialExecutor();

            _random = new SafeRandom();
            var tasks = new List <Task>();

            for (var i = 0; i < 10; i++)
            {
                var capture = i;
                _output.WriteLine("Submitting Task {0}.", capture);
                tasks.Add(executor.AddNext(() => Operation(capture)));
            }

            await Task.WhenAll(tasks);
        }
        internal PersistentStreamPullingManager(
            GrainId id, 
            string strProviderName, 
            IStreamProviderRuntime runtime,
            IStreamPubSub streamPubSub,
            IQueueAdapterFactory adapterFactory,
            IStreamQueueBalancer streamQueueBalancer,
            PersistentStreamProviderConfig config)
            : base(id, runtime.ExecutingSiloAddress)
        {
            if (string.IsNullOrWhiteSpace(strProviderName))
            {
                throw new ArgumentNullException("strProviderName");
            }
            if (runtime == null)
            {
                throw new ArgumentNullException("runtime", "IStreamProviderRuntime runtime reference should not be null");
            }
            if (streamPubSub == null)
            {
                throw new ArgumentNullException("streamPubSub", "StreamPubSub reference should not be null");
            }
            if (streamQueueBalancer == null)
            {
                throw new ArgumentNullException("streamQueueBalancer", "IStreamQueueBalancer streamQueueBalancer reference should not be null");
            }

            queuesToAgentsMap = new Dictionary<QueueId, PersistentStreamPullingAgent>();
            streamProviderName = strProviderName;
            providerRuntime = runtime;
            pubSub = streamPubSub;
            this.config = config;
            nonReentrancyGuarantor = new AsyncSerialExecutor();
            latestRingNotificationSequenceNumber = 0;
            latestCommandNumber = 0;
            queueBalancer = streamQueueBalancer;
            this.adapterFactory = adapterFactory;

            queueAdapterCache = adapterFactory.GetQueueAdapterCache();
            logger = TraceLogger.GetLogger(GetType().Name + "-" + streamProviderName, TraceLogger.LoggerType.Provider);
            Log(ErrorCode.PersistentStreamPullingManager_01, "Created {0} for Stream Provider {1}.", GetType().Name, streamProviderName);

            IntValueStatistic.FindOrCreate(new StatisticName(StatisticNames.STREAMS_PERSISTENT_STREAM_NUM_PULLING_AGENTS, strProviderName), () => queuesToAgentsMap.Count);
            queuePrintTimer = base.RegisterTimer(AsyncTimerCallback, null, QUEUES_PRINT_PERIOD, QUEUES_PRINT_PERIOD);
        }
Esempio n. 14
0
        internal PersistentStreamPullingManager(
            GrainId id,
            string strProviderName,
            IStreamProviderRuntime runtime,
            IStreamPubSub streamPubSub,
            IQueueAdapterFactory adapterFactory,
            IStreamQueueBalancer streamQueueBalancer,
            PersistentStreamProviderConfig config)
            : base(id, runtime.ExecutingSiloAddress)
        {
            if (string.IsNullOrWhiteSpace(strProviderName))
            {
                throw new ArgumentNullException("strProviderName");
            }
            if (runtime == null)
            {
                throw new ArgumentNullException("runtime", "IStreamProviderRuntime runtime reference should not be null");
            }
            if (streamPubSub == null)
            {
                throw new ArgumentNullException("streamPubSub", "StreamPubSub reference should not be null");
            }
            if (streamQueueBalancer == null)
            {
                throw new ArgumentNullException("streamQueueBalancer", "IStreamQueueBalancer streamQueueBalancer reference should not be null");
            }

            queuesToAgentsMap      = new Dictionary <QueueId, PersistentStreamPullingAgent>();
            streamProviderName     = strProviderName;
            providerRuntime        = runtime;
            pubSub                 = streamPubSub;
            this.config            = config;
            nonReentrancyGuarantor = new AsyncSerialExecutor();
            latestRingNotificationSequenceNumber = 0;
            latestCommandNumber = 0;
            queueBalancer       = streamQueueBalancer;
            this.adapterFactory = adapterFactory;

            queueAdapterCache = adapterFactory.GetQueueAdapterCache();
            logger            = LogManager.GetLogger(GetType().Name + "-" + streamProviderName, LoggerType.Provider);
            Log(ErrorCode.PersistentStreamPullingManager_01, "Created {0} for Stream Provider {1}.", GetType().Name, streamProviderName);

            IntValueStatistic.FindOrCreate(new StatisticName(StatisticNames.STREAMS_PERSISTENT_STREAM_NUM_PULLING_AGENTS, strProviderName), () => queuesToAgentsMap.Count);
            queuePrintTimer = base.RegisterTimer(AsyncTimerCallback, null, QUEUES_PRINT_PERIOD, QUEUES_PRINT_PERIOD);
        }
Esempio n. 15
0
        public async Task AsyncSerialExecutorTests_ParallelSubmit()
        {
            AsyncSerialExecutor    executor     = new AsyncSerialExecutor();
            ConcurrentStack <Task> tasks        = new ConcurrentStack <Task>();
            List <Task>            enqueueTasks = new List <Task>();

            for (int i = 0; i < 10; i++)
            {
                int capture = i;
                enqueueTasks.Add(
                    Task.Run(() =>
                {
                    output.WriteLine("Submitting Task {0}.", capture);
                    tasks.Push(executor.AddNext(() => Operation(capture)));
                }));
            }
            await Task.WhenAll(enqueueTasks);

            await Task.WhenAll(tasks);
        }
        internal PersistentStreamPullingManager(
            GrainId id, 
            string strProviderName, 
            IStreamProviderRuntime runtime,
            IQueueAdapterFactory adapterFactory,
            IStreamQueueBalancer streamQueueBalancer,
            TimeSpan queueGetPeriod, 
            TimeSpan initQueueTimeout,
            TimeSpan maxEvenDeliveryTime)
            : base(id, runtime.ExecutingSiloAddress)
        {
            if (string.IsNullOrWhiteSpace(strProviderName))
            {
                throw new ArgumentNullException("strProviderName");
            }
            if (runtime == null)
            {
                throw new ArgumentNullException("runtime", "IStreamProviderRuntime runtime reference should not be null");
            }
            if (streamQueueBalancer == null)
            {
                throw new ArgumentNullException("streamQueueBalancer", "IStreamQueueBalancer streamQueueBalancer reference should not be null");
            }

            queuesToAgentsMap = new Dictionary<QueueId, PersistentStreamPullingAgent>();
            streamProviderName = strProviderName;
            providerRuntime = runtime;
            this.queueGetPeriod = queueGetPeriod;
            this.initQueueTimeout = initQueueTimeout;
            this.maxEvenDeliveryTime = maxEvenDeliveryTime;
            nonReentrancyGuarantor = new AsyncSerialExecutor();
            latestRingNotificationSequenceNumber = 0;
            queueBalancer = streamQueueBalancer;
            this.adapterFactory = adapterFactory;

            queueAdapterCache = adapterFactory.GetQueueAdapterCache();
            logger = providerRuntime.GetLogger(GetType().Name + "-" + streamProviderName);
            logger.Info((int)ErrorCode.PersistentStreamPullingManager_01, "Created {0} for Stream Provider {1}.", GetType().Name, streamProviderName);

            IntValueStatistic.FindOrCreate(new StatisticName(StatisticNames.STREAMS_PERSISTENT_STREAM_NUM_PULLING_AGENTS, strProviderName), () => queuesToAgentsMap.Count);
        }