Пример #1
0
        public SequencedIdGenerator(SequencedIdGeneratorOptions options, IdBuffer idBuffer)
        {
            _options = options;
            options.MachineRoomId &= 0x1f;

            _currentBuffer = idBuffer ?? throw new ArgumentNullException(nameof(idBuffer));
            _loadNextBufferThresholdLv1 = idBuffer.Current + (long)((idBuffer.Max - idBuffer.Current) * 0.1);
        }
Пример #2
0
        private SequencedIdGenerator CreateIdSequence(string businessId)
        {
            var idSequenceBuffer = _idSequenceStore.GetBufferAsync(businessId).ConfigureAwait(true).GetAwaiter().GetResult();
            var options          = new SequencedIdGeneratorOptions()
            {
                UseMachineRoomId     = idSequenceBuffer.UseMachineRoomId,
                MachineRoomId        = idSequenceBuffer.MachineRoomId,
                UseRandomTail        = idSequenceBuffer.UseRandomTail,
                NotifyLoadNextBuffer = NotifyLoadNextBuffer
            };
            IdBuffer             idBuffer   = new IdBuffer(idSequenceBuffer.CurrentId, idSequenceBuffer.MaxId);
            SequencedIdGenerator idSequence = new SequencedIdGenerator(options, idBuffer);

            return(idSequence);
        }