Beispiel #1
0
        private void ProcessEventControl(IncomingNotification notification)
        {
            var controlEvent = (ControlNotification)notification;

            switch (controlEvent.ControlType)
            {
            case ControlType.STREAMING_PAUSED:
                _telemetryRuntimeProducer.RecordStreamingEvent(new StreamingEvent(EventTypeEnum.StreamingStatus, (int)StreamingStatusEnum.Paused));
                DispatchActionEvent(SSEClientActions.SUBSYSTEM_DOWN);
                break;

            case ControlType.STREAMING_RESUMED:
                lock (_eventOccupancyLock)
                {
                    _telemetryRuntimeProducer.RecordStreamingEvent(new StreamingEvent(EventTypeEnum.StreamingStatus, (int)StreamingStatusEnum.Enabled));
                    if (_publisherAvailable)
                    {
                        DispatchActionEvent(SSEClientActions.SUBSYSTEM_READY);
                    }
                }
                break;

            case ControlType.STREAMING_DISABLED:
                _telemetryRuntimeProducer.RecordStreamingEvent(new StreamingEvent(EventTypeEnum.StreamingStatus, (int)StreamingStatusEnum.Disabled));
                DispatchActionEvent(SSEClientActions.SUBSYSTEM_OFF);
                break;

            default:
                _log.Error($"Incorrect control type. {controlEvent.ControlType}");
                break;
            }
        }
Beispiel #2
0
        public async Task <bool> StartSse()
        {
            try
            {
                var response = await _authApiClient.AuthenticateAsync();

                _log.Debug($"Auth service response pushEnabled: {response.PushEnabled}.");

                if (response.PushEnabled.Value && _sseHandler.Start(response.Token, response.Channels))
                {
                    _backOff.Reset();
                    ScheduleNextTokenRefresh(response.Expiration.Value);
                    _telemetryRuntimeProducer.RecordStreamingEvent(new StreamingEvent(EventTypeEnum.TokenRefresh, CalcularteNextTokenExpiration(response.Expiration.Value)));
                    return(true);
                }

                StopSse();

                if (response.Retry.Value)
                {
                    ScheduleNextTokenRefresh(_backOff.GetInterval());
                }
                else
                {
                    ForceCancellationToken();
                }
            }
            catch (Exception ex)
            {
                _log.Error($"StartSse: {ex.Message}");
            }

            return(false);
        }
Beispiel #3
0
        private void ProcessErrorNotification(NotificationError notificationError)
        {
            _log.Debug($"Notification error: {notificationError.Message}. Status Server: {notificationError.StatusCode}.");

            _telemetryRuntimeProducer.RecordStreamingEvent(new StreamingEvent(EventTypeEnum.AblyError, notificationError.Code));

            if (notificationError.Code >= 40140 && notificationError.Code <= 40149)
            {
                throw new ReadStreamException(SSEClientActions.RETRYABLE_ERROR, $"Ably Notification code: {notificationError.Code}");
            }

            if (notificationError.Code >= 40000 && notificationError.Code <= 49999)
            {
                throw new ReadStreamException(SSEClientActions.NONRETRYABLE_ERROR, $"Ably Notification code: {notificationError.Code}");
            }
        }
Beispiel #4
0
        public void Start()
        {
            _tasksManager.Start(() =>
            {
                try
                {
                    while (!_synchronizer.SyncAll(_shutdownCancellationTokenSource, asynchronous: false))
                    {
                        _wrapperAdapter.TaskDelay(500).Wait();
                    }

                    _statusManager.SetReady();
                    _telemetrySyncTask.RecordConfigInit();
                    _synchronizer.StartPeriodicDataRecording();

                    if (_streamingEnabled)
                    {
                        _log.Debug("Starting streaming mode...");
                        var connected = _pushManager.StartSse().Result;

                        if (connected)
                        {
                            return;
                        }
                    }

                    _log.Debug("Starting polling mode ...");
                    _synchronizer.StartPeriodicFetching();
                    _telemetryRuntimeProducer.RecordStreamingEvent(new StreamingEvent(EventTypeEnum.SyncMode, (int)SyncModeEnum.Polling));
                }
                catch (Exception ex)
                {
                    _log.Debug("Exception initialization SDK.", ex);
                }
            }, _shutdownCancellationTokenSource, "SDK Initialization");
        }