Esempio n. 1
0
            public virtual State ProcessSubscriptionError(RtmSubscriptionError error)
            {
                Log.V("Processing subscription error, state: {0}, error: {1}", this, error);

                if (_awaiter.IsCompleted)
                {
                    Log.V("Subscription error ignored because state is completed, state: {0}, error: {1}", this, error);
                    return(null);
                }

                if (IsSubscribed)
                {
                    if (_fsm.IsTrackPosition && !string.IsNullOrEmpty(error.Position))
                    {
                        _fsm.Position = error.Position;
                    }

                    _awaiter.Succeed(new Failed(this));
                    return(_awaiter.Result);
                }
                else if (IsUnsubscribing)
                {
                    if (_fsm.IsTrackPosition && !string.IsNullOrEmpty(error.Position))
                    {
                        _fsm.Position = error.Position;
                    }

                    _awaiter.Succeed(new Unsubscribed(_fsm));
                    return(_awaiter.Result);
                }

                Log.V("Subscription error ignored because state is not subscribed or unsubscribing state, state: {0}, error: {1}", this, error);
                return(null);
            }
        public async Task FailOnOutOfSyncWhenAdvancedMode()
        {
            var channel = GenerateRandomChannelName();

            var client = new RtmClientBuilder(Config.Endpoint, Config.AppKey)
                         .SetConnector(ConnectAndOutOfSyncOnData)
                         .Build();

            var queue = client.CreateStateQueue();

            var obs = new TestSubscriptionObserverQueue(queue);

            obs.ObserveSubscriptionState();
            obs.ObserveSubscriptionPdu();

            client.OnError += ex =>
            {
                queue.Enqueue($"error:{ex.Message}");
            };

            client.CreateSubscription(channel, SubscriptionModes.Advanced, obs);

            RtmSubscriptionError subError = null;

            obs.OnSubscriptionError += (_, error) => subError = error;

            client.Start();

            await queue.AssertDequeue(
                "rtm:created",
                "rtm:enter-unsubscribed",
                "leave-stopped",
                "enter-connecting",
                "leave-connecting",
                "rtm:leave-unsubscribed",
                "rtm:enter-subscribing",
                "enter-connected",
                "rtm:leave-subscribing",
                "rtm:enter-subscribed");

            // trigger subscription/info
            await client.Publish(channel, "msg", Ack.Yes);

            await queue.AssertDequeue(
                $"rtm:leave-subscribed",
                "rtm:enter-failed",
                $"rtm:subscription-error:{RtmSubscriptionError.OutOfSync}");

            var sub = await client.GetSubscription(channel);

            Assert.That(subError.Position, Is.EqualTo(sub.Position));

            await queue.AssertEmpty(client, millis : 200);

            await client.Dispose();
        }
Esempio n. 3
0
        public bool ProcessSubscriptionError(RtmSubscriptionError error)
        {
            Log.V("Processing subscription error, subscription: {0}, error: {1}", this, error);

            if (_state.ProcessSubscriptionError(error) != null)
            {
                this.NotifySubscriptionError(error);
                return(true);
            }

            return(false);
        }
Esempio n. 4
0
 public void OnSubscriptionError(ISubscription subscription, RtmSubscriptionError error)
 {
     _observers.NotifySubscriptionError(subscription, error);
 }
Esempio n. 5
0
 void ISubscriptionObserver.OnSubscriptionError(ISubscription subscription, RtmSubscriptionError error)
 {
     OnSubscriptionError.InvokeSafe(subscription, error);
 }
 public static void NotifySubscriptionError(this SubscriptionFuture future, RtmSubscriptionError error)
 {
     future?.Observer.NotifySubscriptionError(future, error);
 }
        public static void NotifySubscriptionError(this IEnumerable <ISubscriptionObserver> observers, ISubscription subscription, RtmSubscriptionError error)
        {
            if (observers == null)
            {
                return;
            }

            foreach (var observer in observers)
            {
                try
                {
                    observer.OnSubscriptionError(subscription, error);
                }
                catch (Exception ex)
                {
                    UnhandledExceptionWatcher.Swallow(ex);
                }
            }
        }
 public static void NotifySubscriptionError(this ISubscriptionObserver observer, ISubscription subscription, RtmSubscriptionError error)
 {
     if (observer != null)
     {
         observer.OnSubscriptionError(subscription, error);
     }
 }