示例#1
0
 private void BackgroundFlush()
 {
     if (_buffer != null)
     {
         _client.PushAsync(_buffer);
         _buffer = null;
     }
 }
示例#2
0
        public Task ReceiveAsync(IContext context)
        {
            switch (context.Message)
            {
            case Started _:
            {
                _scheduler.ScheduleTellRepeatedly(
                    TimeSpan.FromSeconds(5),
                    TimeSpan.FromSeconds(5),
                    context.Self,
                    Flush.Instance,
                    out _cts
                    );
                break;
            }

            case Stopping _:
            {
                _cts.Cancel();
                break;
            }

            case TrackedMessage tracked:
            {
                if (_buffer == null)
                {
                    _buffer = new List <TrackedMessage>(1000);
                }

                _buffer.Add(tracked);

                break;
            }

            case Flush _ when _buffer != null:
            {
                _client.PushAsync(_buffer);
                _buffer = null;
                break;
            }
            }
            return(Actor.Done);
        }
示例#3
0
        public async Task ReceiveAsync(IContext context)
        {
            switch (context.Message)
            {
            case Started _:
            {
                SherlockInspectionActor.Pid = context.Self;
                _scheduler.ScheduleTellRepeatedly(
                    TimeSpan.FromSeconds(5),
                    TimeSpan.FromSeconds(5),
                    context.Self,
                    Inspect.Instance,
                    out _cts
                    );
                break;
            }

            case Stopping _:
            {
                _cts.Cancel();
                break;
            }

            case AddToInspection add:
            {
                _targets.Add(add.Actor);
                break;
            }

            case Inspect i:
            {
                if (!_targets.Any())
                {
                    _logger.LogWarning("No targets configued");
                    return;
                }

                _logger.LogDebug("Sending inspection reports");
                // send reports
                try
                {
                    await _client.PushAsync(_reports.Reports.Values).ConfigureAwait(false);

                    _logger.LogDebug("Reports sent");
                }
                catch (RpcException ex)
                {
                    _logger.LogDebug("Sherlock server connection error: {message}", ex.Message);
                    if (ex.Status.StatusCode != StatusCode.Unavailable)
                    {
                        throw;
                    }
                }

                // refresh reports
                _logger.LogDebug("Creating new inspection reports");
                foreach (var t in _targets)
                {
                    t.Request(Inspect.Instance, context.Self);
                }

                break;
            }

            case InspectionReportRequest req:
            {
                context.Sender.Tell(_reports);
                break;
            }

            case InspectionReport report:
            {
                _reports.Reports[report.Pid.ToString()] = report;
                break;
            }
            }
        }