/// <summary>
        /// Callback method invoked every time a meta message is being sent.
        /// </summary>
        /// <returns>Always true.</returns>
        /// <exception cref="ArgumentNullException"><paramref name="message"/> is null.</exception>
        public override bool SendMeta(IClientSession session, IMutableMessage message)
        {
            if (message == null)
            {
                throw new ArgumentNullException("message");
            }

            string channel = message.Channel;

            if (Channel.MetaHandshake.Equals(channel, StringComparison.OrdinalIgnoreCase))
            {
                IDictionary <string, object> ext = message.GetExtension(true);
                lock (ext) ext[ExtensionField] = true;

                _ackId = -1;
            }
            else if (_serverSupportsAcks &&
                     Channel.MetaConnect.Equals(channel, StringComparison.OrdinalIgnoreCase))
            {
                IDictionary <string, object> ext = message.GetExtension(true);
                lock (ext) ext[ExtensionField] = _ackId;
            }

            return(true);
        }
        /// <summary>
        /// Callback method invoked every time a meta message is received.
        /// </summary>
        /// <returns>Always true.</returns>
        /// <exception cref="ArgumentNullException"><paramref name="message"/> is null.</exception>
        public override bool ReceiveMeta(IClientSession session, IMutableMessage message)
        {
            if (message == null)
            {
                throw new ArgumentNullException("message");
            }

            string channel = message.Channel;

            if (Channel.MetaHandshake.Equals(channel, StringComparison.OrdinalIgnoreCase))
            {
                IDictionary <string, object> ext = message.GetExtension(false);

                object val;
                _serverSupportsAcks = (ext != null &&
                                       ext.TryGetValue(ExtensionField, out val) &&
                                       ObjectConverter.ToPrimitive <bool>(val, false));
            }
            else if (_serverSupportsAcks &&
                     message.IsSuccessful &&
                     Channel.MetaConnect.Equals(channel, StringComparison.OrdinalIgnoreCase))
            {
                IDictionary <string, object> ext = message.GetExtension(false);

                object val;
                if (ext != null && ext.TryGetValue(ExtensionField, out val))
                {
                    _ackId = ObjectConverter.ToPrimitive <int>(val, _ackId);
                }
            }

            return(true);
        }
Beispiel #3
0
        /// <summary>
        /// Callback method invoked every time a meta message is received.
        /// </summary>
        /// <returns>Always true.</returns>
        /// <exception cref="ArgumentNullException"><paramref name="message"/> is null.</exception>
        public override bool ReceiveMeta(IClientSession session, IMutableMessage message)
        {
            if (message == null)
            {
                throw new ArgumentNullException("message");
            }

            IDictionary <string, object> ext = message.GetExtension(false);
            object val;

            if (ext != null && ext.TryGetValue(ExtensionField, out val))
            {
                IDictionary <string, object> sync
                    = ObjectConverter.ToObject <IDictionary <string, object> >(val);

                if (sync != null &&             // && sync.ContainsKey("a")
                    sync.ContainsKey("tc") && sync.ContainsKey("ts") && sync.ContainsKey("p"))
                {
                    long now = CurrentTimeMillis();

                    long tc = ObjectConverter.ToPrimitive <long>(sync["tc"], 0);
                    long ts = ObjectConverter.ToPrimitive <long>(sync["ts"], 0);
                    int  p  = ObjectConverter.ToPrimitive <int>(sync["p"], 0);
                    //int a = ObjectConverter.ToPrimitive<int>(sync["a"], 0);

                    int l2 = (int)((now - tc - p) / 2);
                    int o2 = (int)(ts - tc - l2);

                    _lag    = (_lag == 0) ? l2 : ((_lag + l2) / 2);
                    _offset = (_offset == 0) ? o2 : ((_offset + o2) / 2);
                }
            }

            return(true);
        }
Beispiel #4
0
        /// <summary>
        /// Callback method invoked every time a meta message is being sent.
        /// </summary>
        /// <returns>Always true.</returns>
        /// <exception cref="ArgumentNullException"><paramref name="message"/> is null.</exception>
        public override bool SendMeta(IClientSession session, IMutableMessage message)
        {
            if (message == null)
            {
                throw new ArgumentNullException("message");
            }

            long now = CurrentTimeMillis();
            IDictionary <string, object> timesync
                = new Dictionary <string, object>(StringComparer.OrdinalIgnoreCase)
                {
                { "tc", now },
                { "l", _lag },
                { "o", _offset }
                };

            IDictionary <string, object> ext = message.GetExtension(true);

            lock (ext) ext[ExtensionField] = timesync;

            return(true);
        }