Exemple #1
0
        /// <summary>Constructor to use for grain services</summary>
        protected GrainService(GrainId grainId, Silo silo, ILoggerFactory loggerFactory)
            : base(SystemTargetGrainId.Create(grainId.Type, silo.SiloAddress), silo.SiloAddress, lowPriority: true, loggerFactory: loggerFactory)
        {
            typeName = this.GetType().FullName;
            Logger   = loggerFactory.CreateLogger(typeName);

            ring = silo.RingProvider;
            StoppedCancellationTokenSource = new CancellationTokenSource();
        }
Exemple #2
0
 internal SystemTarget(GrainType grainType, SiloAddress silo, bool lowPriority, ILoggerFactory loggerFactory)
     : this(SystemTargetGrainId.Create(grainType, silo), silo, lowPriority, loggerFactory)
 {
 }
Exemple #3
0
 internal SystemTarget(GrainType grainType, SiloAddress silo, ILoggerFactory loggerFactory)
     : this(SystemTargetGrainId.Create(grainType, silo), silo, false, loggerFactory)
 {
 }
        private async Task RunAsync()
        {
            try
            {
                var grainFactory     = _services.GetRequiredService <IInternalGrainFactory>();
                var cancellationTask = _cancellation.Token.WhenCancelled();
                while (!_cancellation.IsCancellationRequested)
                {
                    var gateway = _gatewayManager.GetLiveGateway();
                    try
                    {
                        var provider    = grainFactory.GetGrain <IClusterManifestSystemTarget>(SystemTargetGrainId.Create(Constants.ManifestProviderType, gateway).GrainId);
                        var refreshTask = provider.GetClusterManifest().AsTask();
                        var task        = await Task.WhenAny(cancellationTask, refreshTask).ConfigureAwait(false);

                        if (ReferenceEquals(task, cancellationTask))
                        {
                            return;
                        }

                        if (!_updates.TryPublish(await refreshTask))
                        {
                            await Task.Delay(StandardExtensions.Min(_typeManagementOptions.TypeMapRefreshInterval, TimeSpan.FromMilliseconds(500)));

                            continue;
                        }

                        _initialized.TrySetResult(true);

                        if (_logger.IsEnabled(LogLevel.Debug))
                        {
                            _logger.LogDebug("Refreshed cluster manifest");
                        }

                        await Task.WhenAny(cancellationTask, Task.Delay(_typeManagementOptions.TypeMapRefreshInterval));
                    }
                    catch (Exception exception)
                    {
                        _logger.LogWarning(exception, "Error trying to get cluster manifest from gateway {Gateway}", gateway);
                        await Task.Delay(StandardExtensions.Min(_typeManagementOptions.TypeMapRefreshInterval, TimeSpan.FromSeconds(5)));
                    }
                }
            }
            finally
            {
                _initialized.TrySetResult(false);

                if (_logger.IsEnabled(LogLevel.Debug))
                {
                    _logger.LogDebug("Stopped refreshing cluster manifest");
                }
            }
        }