Ejemplo n.º 1
0
    /// <summary>
    /// Add coroutine to a parallel group and start it
    /// </summary>
    public static void AsParallelGroup(this IEnumerator coroutine, MonoBehaviour parent, string groupName)
    {
        if (!Runners.ContainsKey(groupName))
        {
            Runners.Add(groupName, 0);
        }

        Runners[groupName]++;
        parent.StartCoroutine(DoParallel(coroutine, parent, groupName));
    }
Ejemplo n.º 2
0
 /// <summary>
 /// Method checks if given ID is unique in the Dictionary of runners.
 /// </summary>
 /// <param name="id"></param>
 /// <returns></returns>
 public static bool CheckID(int id)
 {
     if ((Runners.ContainsKey(id)))
     {
         return(false);
     }
     else
     {
         return(true);
     }
 }
Ejemplo n.º 3
0
 private void ProcessRunnerDefinition(RunnerDefinition runner)
 {
     if (runner.SelectionId is null)
     {
         return;
     }
     if (Runners.ContainsKey((long)runner.SelectionId))
     {
         Runners[(long)runner.SelectionId].SetDefinition(runner);
     }
 }
Ejemplo n.º 4
0
        private void ProcessOrderRunnerChange(OrderRunnerChange orc)
        {
            if (orc.SelectionId is null)
            {
                return;
            }
            var selectionId = (long)orc.SelectionId;

            if (!Runners.ContainsKey(selectionId))
            {
                Runners.Add(selectionId, new RunnerCache(selectionId));
            }

            Runners[selectionId].OnOrderChange(orc);
        }
Ejemplo n.º 5
0
        private void ProcessRunnerChange(RunnerChange runnerChange)
        {
            if (runnerChange.SelectionId is null)
            {
                return;
            }
            var selectionId = (long)runnerChange.SelectionId;

            if (!Runners.ContainsKey(selectionId))
            {
                Runners.Add(selectionId, new RunnerCache(selectionId));
            }

            Runners[selectionId]
            .OnRunnerChange(runnerChange, LastPublishedTime);
        }
Ejemplo n.º 6
0
        private async Task DistributedStart()
        {
            try
            {
                if (Interlocked.CompareExchange(ref distributedMonitorTimeLock, 1, 0) == 0)
                {
                    var consumers = rabbitEventBusContainer.GetConsumers();
                    foreach (var consumer in consumers)
                    {
                        if (consumer is RabbitConsumer value)
                        {
                            for (int i = 0; i < value.QueueList.Count(); i++)
                            {
                                var queue = value.QueueList[i];
                                var key   = queue.ToString();
                                if (!Runners.ContainsKey(key))
                                {
                                    var weight = 100000 - Runners.Count;
                                    var(isOk, lockId, expectMillisecondDelay) = await grainFactory.GetGrain <IWeightHoldLock>(key).Lock(weight, lockHoldingSeconds);

                                    if (isOk)
                                    {
                                        if (Runners.TryAdd(key, lockId))
                                        {
                                            var runner = new ConsumerRunner(client, provider, value, queue);
                                            ConsumerRunners.TryAdd(key, runner);
                                            await runner.Run();
                                        }
                                    }
                                }
                            }
                        }
                    }
                    Interlocked.Exchange(ref distributedMonitorTimeLock, 0);
                    if (logger.IsEnabled(LogLevel.Information))
                    {
                        logger.LogInformation("EventBus Background Service is working.");
                    }
                }
            }
            catch (Exception exception)
            {
                logger.LogError(exception.InnerException ?? exception, nameof(DistributedStart));
                Interlocked.Exchange(ref distributedMonitorTimeLock, 0);
            }
        }
Ejemplo n.º 7
0
        private async Task DistributedStart()
        {
            try
            {
                if (Interlocked.CompareExchange(ref distributedMonitorTimeLock, 1, 0) == 0)
                {
                    var consumers = kafkaEventBusContainer.GetConsumers();
                    foreach (var consumer in consumers)
                    {
                        if (consumer is KafkaConsumer value)
                        {
                            for (int i = 0; i < value.Topics.Count(); i++)
                            {
                                var topic = value.Topics[i];
                                var key   = $"{topic}_{value.Group}";
                                if (!Runners.ContainsKey(key))
                                {
                                    var weight = 100000 - Runners.Count;
                                    var(isOk, lockId, expectMillisecondDelay) = await grainFactory.GetGrain <IWeightHoldLock>(key).Lock(weight, lockHoldingSeconds);

                                    if (isOk)
                                    {
                                        if (Runners.TryAdd(key, lockId))
                                        {
                                            var runner = new ConsumerRunner(client, provider.GetService <ILogger <ConsumerRunner> >(), value, topic);
                                            ConsumerRunners.TryAdd(key, runner);
                                            await runner.Run();
                                        }
                                    }
                                }
                            }
                        }
                    }
                    Interlocked.Exchange(ref distributedMonitorTimeLock, 0);
                }
            }
            catch (Exception exception)
            {
                logger.LogError(exception.InnerException ?? exception, nameof(DistributedStart));
                Interlocked.Exchange(ref distributedMonitorTimeLock, 0);
            }
        }
Ejemplo n.º 8
0
 /// <summary>
 /// Get amount of coroutines, that is processing (not finished) in group
 /// </summary>
 public static int GroupProcessing(string groupName)
 {
     return(Runners.ContainsKey(groupName) ? Runners[groupName] : 0);
 }