当前位置: 首页>>代码示例>>C#>>正文


C# StreamSequenceToken.Newer方法代码示例

本文整理汇总了C#中StreamSequenceToken.Newer方法的典型用法代码示例。如果您正苦于以下问题:C# StreamSequenceToken.Newer方法的具体用法?C# StreamSequenceToken.Newer怎么用?C# StreamSequenceToken.Newer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在StreamSequenceToken的用法示例。


在下文中一共展示了StreamSequenceToken.Newer方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: FindNodeBySequenceToken

        private LinkedListNode<TimedQueueCacheItem> FindNodeBySequenceToken(StreamSequenceToken sequenceToken)
        {
            // First we find a bucket where the node is in
            var sequenceBucket =
                _cacheCursorHistogram.First(
                    bucket =>
                        !sequenceToken.Newer(bucket.NewestMember.Value.SequenceToken) &&
                        !sequenceToken.Older(bucket.OldestMember.Value.SequenceToken));

            // Now that we have the bucket, we iterate on the members there starting from the newest in the bucket
            LinkedListNode<TimedQueueCacheItem> node = sequenceBucket.NewestMember;
            while (node != null && node.Value.SequenceToken.Newer(sequenceToken))
            {
                // did we get to the end?
                // node is the last message in the cache
                if (node.Next == null)
                    break;

                // if sequenceId is between the two, take the lower
                if (node.Next.Value.SequenceToken.Older(sequenceToken))
                {
                    node = node.Next;
                    break;
                }

                node = node.Next;
            }

            return node;
        }
开发者ID:gigya,项目名称:Orleans.KafkaStreamProvider,代码行数:30,代码来源:TimedQueueCache.cs

示例2: InitializeCursor

        internal void InitializeCursor(SimpleQueueCacheCursor cursor, StreamSequenceToken sequenceToken, bool enforceSequenceToken)
        {
            Log(logger, "InitializeCursor: {0} to sequenceToken {1}", cursor, sequenceToken);
           
            if (cachedMessages.Count == 0) // nothing in cache
            {
                StreamSequenceToken tokenToReset = sequenceToken ?? (lastSequenceTokenAddedToCache != null ? ((EventSequenceToken)lastSequenceTokenAddedToCache).NextSequenceNumber() : null);
                ResetCursor(cursor, tokenToReset);
                return;
            }

            // if offset is not set, iterate from newest (first) message in cache, but not including the irst message itself
            if (sequenceToken == null)
            {
                StreamSequenceToken tokenToReset = lastSequenceTokenAddedToCache != null ? ((EventSequenceToken)lastSequenceTokenAddedToCache).NextSequenceNumber() : null;
                ResetCursor(cursor, tokenToReset);
                return;
            }

            if (sequenceToken.Newer(cachedMessages.First.Value.SequenceToken)) // sequenceId is too new to be in cache
            {
                ResetCursor(cursor, sequenceToken);
                return;
            }

            LinkedListNode<SimpleQueueCacheItem> lastMessage = cachedMessages.Last;
            // Check to see if offset is too old to be in cache
            if (sequenceToken.Older(lastMessage.Value.SequenceToken))
            {
                if (enforceSequenceToken)
                {
                    // throw cache miss exception
                    throw new QueueCacheMissException(sequenceToken, cachedMessages.Last.Value.SequenceToken, cachedMessages.First.Value.SequenceToken);
                }
                sequenceToken = lastMessage.Value.SequenceToken;
            }

            // Now the requested sequenceToken is set and is also within the limits of the cache.

            // Find first message at or below offset
            // Events are ordered from newest to oldest, so iterate from start of list until we hit a node at a previous offset, or the end.
            LinkedListNode<SimpleQueueCacheItem> node = cachedMessages.First;
            while (node != null && node.Value.SequenceToken.Newer(sequenceToken))
            {
                // did we get to the end?
                if (node.Next == null) // node is the last message
                    break;
                
                // if sequenceId is between the two, take the higher
                if (node.Next.Value.SequenceToken.Older(sequenceToken))
                    break;
                
                node = node.Next;
            }

            // return cursor from start.
            SetCursor(cursor, node);
        }
开发者ID:PaulNorth,项目名称:orleans,代码行数:58,代码来源:SimpleQueueCache.cs


注:本文中的StreamSequenceToken.Newer方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。