Пример #1
0
Publication::Publication(
    ClientConductor &conductor,
    const std::string &channel,
    std::int64_t registrationId,
    std::int32_t streamId,
    std::int32_t sessionId,
    UnsafeBufferPosition& publicationLimit,
    LogBuffers &buffers)
    :
    m_conductor(conductor),
    m_logMetaDataBuffer(buffers.atomicBuffer(LogBufferDescriptor::LOG_META_DATA_SECTION_INDEX)),
    m_channel(channel),
    m_registrationId(registrationId),
    m_streamId(streamId),
    m_sessionId(sessionId),
    m_initialTermId(LogBufferDescriptor::initialTermId(m_logMetaDataBuffer)),
    m_maxPayloadLength(LogBufferDescriptor::mtuLength(m_logMetaDataBuffer) - DataFrameHeader::LENGTH),
    m_maxMessageLength(FrameDescriptor::computeMaxMessageLength(buffers.atomicBuffer(0).capacity())),
    m_positionBitsToShift(util::BitUtil::numberOfTrailingZeroes(buffers.atomicBuffer(0).capacity())),
    m_publicationLimit(publicationLimit),
    m_headerWriter(LogBufferDescriptor::defaultFrameHeader(m_logMetaDataBuffer))
{
    for (int i = 0; i < LogBufferDescriptor::PARTITION_COUNT; i++)
    {
        /*
         * TODO:
         * perhaps allow copy-construction and be able to move appenders and AtomicBuffers directly into Publication for
         * locality.
         */
        m_appenders[i] = std::unique_ptr<TermAppender>(new TermAppender(
            buffers.atomicBuffer(i),
            buffers.atomicBuffer(LogBufferDescriptor::LOG_META_DATA_SECTION_INDEX),
            i));
    }
}
Пример #2
0
Publication::Publication(
    ClientConductor &conductor,
    const std::string &channel,
    std::int64_t registrationId,
    std::int32_t streamId,
    std::int32_t sessionId,
    UnsafeBufferPosition& publicationLimit,
    LogBuffers &buffers)
    :
    m_conductor(conductor),
    m_channel(channel),
    m_registrationId(registrationId),
    m_streamId(streamId),
    m_sessionId(sessionId),
    m_publicationLimit(publicationLimit),
    m_logMetaDataBuffer(buffers.atomicBuffer(LogBufferDescriptor::LOG_META_DATA_SECTION_INDEX))
{
    const std::int32_t mtuLength = LogBufferDescriptor::mtuLength(m_logMetaDataBuffer);
    std::int32_t capacity = buffers.atomicBuffer(0).capacity();

    for (int i = 0; i < LogBufferDescriptor::PARTITION_COUNT; i++)
    {
        AtomicBuffer defaultFrameHeader = LogBufferDescriptor::defaultFrameHeader(m_logMetaDataBuffer, i);

        /*
         * TODO:
         * perhaps allow copy-construction and be able to move appenders and AtomicBuffers directly into Publication for
         * locality.
         */
        m_appenders[i] = std::unique_ptr<TermAppender>(new TermAppender(
            buffers.atomicBuffer(i),
            buffers.atomicBuffer(i + LogBufferDescriptor::PARTITION_COUNT),
            defaultFrameHeader,
            mtuLength));
    }

    LogBufferDescriptor::activeTermId(m_logMetaDataBuffer, LogBufferDescriptor::initialTermId(m_logMetaDataBuffer));
    m_positionBitsToShift = util::BitUtil::numberOfTrailingZeroes(capacity);
}