예제 #1
0
        internal Publication(ClientConductor clientConductor, string channel, int streamId, int sessionId, IReadablePosition positionLimit, LogBuffers logBuffers, long registrationId)
        {
            var buffers           = logBuffers.AtomicBuffers();
            var logMetaDataBuffer = buffers[LogBufferDescriptor.LOG_META_DATA_SECTION_INDEX];

            for (var i = 0; i < LogBufferDescriptor.PARTITION_COUNT; i++)
            {
                _termAppenders[i] = new TermAppender(buffers[i], buffers[i + LogBufferDescriptor.PARTITION_COUNT]);
            }

            var termLength = logBuffers.TermLength();

            _maxPayloadLength    = LogBufferDescriptor.MtuLength(logMetaDataBuffer) - DataHeaderFlyweight.HEADER_LENGTH;
            MaxMessageLength     = FrameDescriptor.ComputeMaxMessageLength(termLength);
            _clientConductor     = clientConductor;
            Channel              = channel;
            StreamId             = streamId;
            SessionId            = sessionId;
            InitialTermId        = LogBufferDescriptor.InitialTermId(logMetaDataBuffer);
            _logMetaDataBuffer   = logMetaDataBuffer;
            RegistrationId       = registrationId;
            _positionLimit       = positionLimit;
            _logBuffers          = logBuffers;
            _positionBitsToShift = IntUtil.NumberOfTrailingZeros(termLength);
            _headerWriter        = new HeaderWriter(LogBufferDescriptor.DefaultFrameHeader(logMetaDataBuffer));
        }
        internal ConcurrentPublication(
            ClientConductor clientConductor,
            string channel,
            int streamId,
            int sessionId,
            IReadablePosition positionLimit,
            int channelStatusId,
            LogBuffers logBuffers,
            long originalRegistrationId,
            long registrationId)
            : base(
                clientConductor,
                channel,
                streamId,
                sessionId,
                positionLimit,
                channelStatusId,
                logBuffers,
                originalRegistrationId,
                registrationId
                )
        {
            var buffers = logBuffers.DuplicateTermBuffers();

            for (var i = 0; i < LogBufferDescriptor.PARTITION_COUNT; i++)
            {
                _termAppenders[i] = new TermAppender(buffers[i], _logMetaDataBuffer, i);
            }
        }
예제 #3
0
        public void SetUp()
        {
            _sendBuffer        = new byte[SendBufferCapacity];
            _atomicSendBuffer  = new UnsafeBuffer(_sendBuffer);
            _logMetaDataBuffer = new UnsafeBuffer(new byte[LogBufferDescriptor.LOG_META_DATA_LENGTH]);
            _termBuffers       = new UnsafeBuffer[LogBufferDescriptor.PARTITION_COUNT];

            _conductor        = A.Fake <ClientConductor>();
            _logBuffers       = A.Fake <LogBuffers>();
            _publicationLimit = A.Fake <IReadablePosition>();

            A.CallTo(() => _publicationLimit.Volatile).Returns(2 * SendBufferCapacity);
            A.CallTo(() => _logBuffers.TermBuffers()).Returns(_termBuffers);
            A.CallTo(() => _logBuffers.TermLength()).Returns(LogBufferDescriptor.TERM_MIN_LENGTH);
            A.CallTo(() => _logBuffers.MetaDataBuffer()).Returns(_logMetaDataBuffer);

            LogBufferDescriptor.InitialTermId(_logMetaDataBuffer, TermID1);
            LogBufferDescriptor.TimeOfLastStatusMessage(_logMetaDataBuffer, 0);

            for (var i = 0; i < LogBufferDescriptor.PARTITION_COUNT; i++)
            {
                _termBuffers[i] = new UnsafeBuffer(new byte[LogBufferDescriptor.TERM_MIN_LENGTH]);
            }

            _publication = new Publication(_conductor, Channel, StreamID1, SessionID1, _publicationLimit, _logBuffers, CorrelationID);

            _publication.IncRef();

            LogBufferDescriptor.InitialiseTailWithTermId(_logMetaDataBuffer, PartionIndex, TermID1);
        }
예제 #4
0
 internal Publication(
     ClientConductor clientConductor,
     string channel,
     int streamId,
     int sessionId,
     IReadablePosition positionLimit,
     int channelStatusId,
     LogBuffers logBuffers,
     long originalRegistrationId,
     long registrationId)
 {
     _logMetaDataBuffer   = logBuffers.MetaDataBuffer();
     TermBufferLength     = logBuffers.TermLength();
     MaxMessageLength     = FrameDescriptor.ComputeMaxMessageLength(TermBufferLength);
     MaxPayloadLength     = LogBufferDescriptor.MtuLength(_logMetaDataBuffer) - DataHeaderFlyweight.HEADER_LENGTH;
     _maxPossiblePosition = TermBufferLength * (1L << 31);
     _conductor           = clientConductor;
     Channel                 = channel;
     StreamId                = streamId;
     SessionId               = sessionId;
     InitialTermId           = LogBufferDescriptor.InitialTermId(_logMetaDataBuffer);
     _originalRegistrationId = originalRegistrationId;
     RegistrationId          = registrationId;
     _positionLimit          = positionLimit;
     _channelStatusId        = channelStatusId;
     _logBuffers             = logBuffers;
     PositionBitsToShift     = LogBufferDescriptor.PositionBitsToShift(TermBufferLength);
     _headerWriter           = new HeaderWriter(LogBufferDescriptor.DefaultFrameHeader(_logMetaDataBuffer));
 }
예제 #5
0
        internal Publication(ClientConductor clientConductor, string channel, int streamId, int sessionId, IReadablePosition positionLimit, LogBuffers logBuffers, long registrationId)
        {
            var buffers = logBuffers.AtomicBuffers();
            var logMetaDataBuffer = buffers[LogBufferDescriptor.LOG_META_DATA_SECTION_INDEX];

            for (var i = 0; i < LogBufferDescriptor.PARTITION_COUNT; i++)
            {
                _termAppenders[i] = new TermAppender(buffers[i], buffers[i + LogBufferDescriptor.PARTITION_COUNT]);
            }

            var termLength = logBuffers.TermLength();
            _maxPayloadLength = LogBufferDescriptor.MtuLength(logMetaDataBuffer) - DataHeaderFlyweight.HEADER_LENGTH;
            MaxMessageLength = FrameDescriptor.ComputeMaxMessageLength(termLength);
            _clientConductor = clientConductor;
            Channel = channel;
            StreamId = streamId;
            SessionId = sessionId;
            InitialTermId = LogBufferDescriptor.InitialTermId(logMetaDataBuffer);
            _logMetaDataBuffer = logMetaDataBuffer;
            RegistrationId = registrationId;
            _positionLimit = positionLimit;
            _logBuffers = logBuffers;
            _positionBitsToShift = IntUtil.NumberOfTrailingZeros(termLength);
            _headerWriter = new HeaderWriter(LogBufferDescriptor.DefaultFrameHeader(logMetaDataBuffer));
        }
예제 #6
0
        internal ExclusivePublication(
            ClientConductor clientConductor,
            string channel,
            int streamId,
            int sessionId,
            IReadablePosition positionLimit,
            LogBuffers logBuffers,
            long originalRegistrationId,
            long registrationId)
        {
            var buffers           = logBuffers.TermBuffers();
            var logMetaDataBuffer = logBuffers.MetaDataBuffer();

            for (var i = 0; i < LogBufferDescriptor.PARTITION_COUNT; i++)
            {
                _termAppenders[i] = new ExclusiveTermAppender(buffers[i], logMetaDataBuffer, i);
            }

            var termLength = logBuffers.TermLength();

            _termBufferLength    = termLength;
            MaxPayloadLength     = LogBufferDescriptor.MtuLength(logMetaDataBuffer) - DataHeaderFlyweight.HEADER_LENGTH;
            MaxMessageLength     = FrameDescriptor.ComputeExclusiveMaxMessageLength(termLength);
            _maxPossiblePosition = termLength * (1L << 31);
            _conductor           = clientConductor;
            Channel   = channel;
            StreamId  = streamId;
            SessionId = sessionId;

            _logMetaDataBuffer      = logMetaDataBuffer;
            _originalRegistrationId = originalRegistrationId;
            RegistrationId          = registrationId;
            _positionLimit          = positionLimit;
            _logBuffers             = logBuffers;
            _positionBitsToShift    = IntUtil.NumberOfTrailingZeros(termLength);
            _headerWriter           = new HeaderWriter(LogBufferDescriptor.DefaultFrameHeader(logMetaDataBuffer));
            InitialTermId           = LogBufferDescriptor.InitialTermId(logMetaDataBuffer);

            var activeIndex = LogBufferDescriptor.ActivePartitionIndex(logMetaDataBuffer);

            _activePartitionIndex = activeIndex;

            long rawTail = LogBufferDescriptor.RawTail(_logMetaDataBuffer, activeIndex);

            _termId            = LogBufferDescriptor.TermId(rawTail);
            _termOffset        = LogBufferDescriptor.TermOffset(rawTail, termLength);
            _termBeginPosition =
                LogBufferDescriptor.ComputeTermBeginPosition(_termId, _positionBitsToShift, InitialTermId);
        }
예제 #7
0
        internal ExclusivePublication(
            ClientConductor clientConductor,
            string channel,
            int streamId,
            int sessionId,
            IReadablePosition positionLimit,
            int channelStatusId,
            LogBuffers logBuffers,
            long originalRegistrationId,
            long registrationId)
            : base(
                clientConductor,
                channel,
                streamId,
                sessionId,
                positionLimit,
                channelStatusId,
                logBuffers,
                originalRegistrationId,
                registrationId,
                FrameDescriptor.ComputeExclusiveMaxMessageLength(logBuffers.TermLength())
                )
        {
            var buffers           = logBuffers.DuplicateTermBuffers();
            var logMetaDataBuffer = logBuffers.MetaDataBuffer();

            for (var i = 0; i < LogBufferDescriptor.PARTITION_COUNT; i++)
            {
                _termAppenders[i] = new ExclusiveTermAppender(buffers[i], logMetaDataBuffer, i);
            }

            var termCount = LogBufferDescriptor.ActiveTermCount(logMetaDataBuffer);
            var index     = LogBufferDescriptor.IndexByTermCount(termCount);

            _activePartitionIndex = index;

            var rawTail = LogBufferDescriptor.RawTail(_logMetaDataBuffer, index);

            _termId            = LogBufferDescriptor.TermId(rawTail);
            _termOffset        = LogBufferDescriptor.TermOffset(rawTail);
            _termBeginPosition =
                LogBufferDescriptor.ComputeTermBeginPosition(_termId, _positionBitsToShift, InitialTermId);
        }
예제 #8
0
        public void SetUp()
        {
            _sendBuffer        = new byte[SendBufferCapacity];
            _atomicSendBuffer  = new UnsafeBuffer(_sendBuffer);
            _logMetaDataBuffer = new UnsafeBuffer(new byte[LogBufferDescriptor.LOG_META_DATA_LENGTH]);
            _termBuffers       = new UnsafeBuffer[LogBufferDescriptor.PARTITION_COUNT];

            _conductor        = A.Fake <ClientConductor>();
            _logBuffers       = A.Fake <LogBuffers>();
            _publicationLimit = A.Fake <IReadablePosition>();

            A.CallTo(() => _publicationLimit.GetVolatile()).Returns(2 * SendBufferCapacity);
            A.CallTo(() => _logBuffers.DuplicateTermBuffers()).Returns(_termBuffers);
            A.CallTo(() => _logBuffers.TermLength()).Returns(LogBufferDescriptor.TERM_MIN_LENGTH);
            A.CallTo(() => _logBuffers.MetaDataBuffer()).Returns(_logMetaDataBuffer);

            LogBufferDescriptor.InitialTermId(_logMetaDataBuffer, TermID1);
            LogBufferDescriptor.MtuLength(_logMetaDataBuffer, MTU_LENGTH);
            LogBufferDescriptor.TermLength(_logMetaDataBuffer, LogBufferDescriptor.TERM_MIN_LENGTH);
            LogBufferDescriptor.PageSize(_logMetaDataBuffer, PAGE_SIZE);
            LogBufferDescriptor.IsConnected(_logMetaDataBuffer, false);

            for (var i = 0; i < LogBufferDescriptor.PARTITION_COUNT; i++)
            {
                _termBuffers[i] = new UnsafeBuffer(new byte[LogBufferDescriptor.TERM_MIN_LENGTH]);
            }

            _publication = new ConcurrentPublication(
                _conductor,
                Channel,
                StreamID1,
                SessionID1,
                _publicationLimit,
                ChannelEndpointStatus.NO_ID_ALLOCATED,
                _logBuffers,
                CorrelationID,
                CorrelationID);

            LogBufferDescriptor.InitialiseTailWithTermId(_logMetaDataBuffer, PartionIndex, TermID1);

            A.CallTo(() => _conductor.ReleasePublication(_publication)).Invokes(() => _publication.InternalClose());
        }
예제 #9
0
        public void SetUp()
        {
            _sendBuffer = new byte[SendBufferCapacity];
            _atomicSendBuffer = new UnsafeBuffer(_sendBuffer);
            _logMetaDataBuffer = new UnsafeBuffer(new byte[LogBufferDescriptor.LOG_META_DATA_LENGTH]);
            _termBuffers = new UnsafeBuffer[LogBufferDescriptor.PARTITION_COUNT];
            _termMetaDataBuffers = new UnsafeBuffer[LogBufferDescriptor.PARTITION_COUNT];
            _buffers = new UnsafeBuffer[LogBufferDescriptor.PARTITION_COUNT*2 + 1];

            _conductor = A.Fake<ClientConductor>();
            _logBuffers = A.Fake<LogBuffers>();
            _publicationLimit = A.Fake<IReadablePosition>();

            A.CallTo(() => _publicationLimit.Volatile).Returns(2*SendBufferCapacity);
            A.CallTo(() => _logBuffers.AtomicBuffers()).Returns(_buffers);
            A.CallTo(() => _logBuffers.TermLength()).Returns(LogBufferDescriptor.TERM_MIN_LENGTH);

            LogBufferDescriptor.InitialTermId(_logMetaDataBuffer, TermID1);
            LogBufferDescriptor.TimeOfLastStatusMessage(_logMetaDataBuffer, 0);

            for (var i = 0; i < LogBufferDescriptor.PARTITION_COUNT; i++)
            {
                _termBuffers[i] = new UnsafeBuffer(new byte[LogBufferDescriptor.TERM_MIN_LENGTH]);
                _termMetaDataBuffers[i] = new UnsafeBuffer(new byte[LogBufferDescriptor.TERM_META_DATA_LENGTH]);

                _buffers[i] = _termBuffers[i];
                _buffers[i + LogBufferDescriptor.PARTITION_COUNT] = _termMetaDataBuffers[i];
            }
            _buffers[LogBufferDescriptor.LOG_META_DATA_SECTION_INDEX] = _logMetaDataBuffer;

            _publication = new Publication(_conductor, Channel, StreamID1, SessionID1, _publicationLimit, _logBuffers, CorrelationID);

            _publication.IncRef();

            LogBufferDescriptor.InitialiseTailWithTermId(_termMetaDataBuffers[0], TermID1);
        }