Exemplo n.º 1
0
        /// <summary>
        /// Insert a packet of frames into the log at the appropriate offset as indicated by the term offset header.
        /// </summary>
        /// <param name="termBuffer"> into which the packet should be inserted. </param>
        /// <param name="offset">     offset in the term at which the packet should be inserted. </param>
        /// <param name="packet">     containing a sequence of frames. </param>
        /// <param name="length">     of the sequence of frames in bytes. </param>
        public static void Insert(IAtomicBuffer termBuffer, int offset, UnsafeBuffer packet, int length)
        {
            var firstFrameLength = packet.GetInt(0); // LITTLE_ENDIAN

            packet.PutIntOrdered(0, 0);

            termBuffer.PutBytes(offset, packet, 0, length);
            FrameDescriptor.FrameLengthOrdered(termBuffer, offset, firstFrameLength);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Insert a packet of frames into the log at the appropriate offset as indicated by the term termOffset header.
        /// </summary>
        /// <param name="termBuffer"> into which the packet should be inserted. </param>
        /// <param name="termOffset">     offset in the term at which the packet should be inserted. </param>
        /// <param name="packet">     containing a sequence of frames. </param>
        /// <param name="length">     of the sequence of frames in bytes. </param>
        public static void Insert(IAtomicBuffer termBuffer, int termOffset, UnsafeBuffer packet, int length)
        {
            var firstFrameLength = packet.GetInt(0); // LITTLE_ENDIAN

            packet.PutIntOrdered(0, 0);
            Thread.MemoryBarrier(); // UnsafeAccess.UNSAFE.storeFence();

            termBuffer.PutBytes(termOffset, packet, 0, length);
            FrameDescriptor.FrameLengthOrdered(termBuffer, termOffset, firstFrameLength);
        }
Exemplo n.º 3
0
        public void ShouldAppendFrameToEmptyLog()
        {
            int          headerLength       = _defaultHeader.Capacity;
            UnsafeBuffer buffer             = new UnsafeBuffer(new byte[128]);
            const int    msgLength          = 20;
            int          frameLength        = msgLength + headerLength;
            int          alignedFrameLength = BitUtil.Align(frameLength, FrameDescriptor.FRAME_ALIGNMENT);
            const int    tail = 0;

            _logMetaDataBuffer.PutLong(TermTailCounterOffset, LogBufferDescriptor.PackTail(TermID, tail));

            Assert.That(_termAppender.AppendUnfragmentedMessage(_headerWriter, buffer, 0, msgLength, RVS, TermID), Is.EqualTo((long)alignedFrameLength));

            Assert.AreEqual(LogBufferDescriptor.RawTailVolatile(_logMetaDataBuffer, PartionIndex), LogBufferDescriptor.PackTail(TermID, tail + alignedFrameLength));

            A.CallTo(() => _headerWriter.Write(_termBuffer, tail, frameLength, TermID)).MustHaveHappened()
            .Then(A.CallTo(() => _termBuffer.PutBytes(headerLength, buffer, 0, msgLength)).MustHaveHappened())
            .Then(A.CallTo(() => _termBuffer.PutLong(tail + DataHeaderFlyweight.RESERVED_VALUE_OFFSET, RV, ByteOrder.LittleEndian)).MustHaveHappened())
            .Then(A.CallTo(() => _termBuffer.PutIntOrdered(tail, frameLength)).MustHaveHappened());
        }
Exemplo n.º 4
0
 /// <summary>
 ///     Set the value of the current active term count for the producer using memory ordered semantics.
 /// </summary>
 /// <param name="metaDataBuffer"> containing the metadata. </param>
 /// <param name="termCount">         value of the active term count used by the producer of this log. </param>
 public static void ActiveTermCountOrdered(UnsafeBuffer metaDataBuffer, int termCount)
 {
     metaDataBuffer.PutIntOrdered(LOG_ACTIVE_TERM_COUNT_OFFSET, termCount);
 }
Exemplo n.º 5
0
 /// <summary>
 ///     Set whether the log is considered connected or not by the driver.
 /// </summary>
 /// <param name="metaDataBuffer"> containing the metadata. </param>
 /// <param name="isConnected">       or not </param>
 public static void IsConnected(UnsafeBuffer metaDataBuffer, bool isConnected)
 {
     metaDataBuffer.PutIntOrdered(LOG_IS_CONNECTED_OFFSET, isConnected ? 1 : 0);
 }
Exemplo n.º 6
0
        /// <summary>
        /// Commit the message to the log buffer so that is it available to subscribers.
        /// </summary>
        public void Commit()
        {
            var frameLength = _buffer.Capacity;

            _buffer.PutIntOrdered(HeaderFlyweight.FRAME_LENGTH_FIELD_OFFSET, frameLength);
        }
 /// <summary>
 /// Set the number of active transports for the Image.
 /// </summary>
 /// <param name="metadataBuffer"> containing the meta data. </param>
 /// <param name="numberOfActiveTransports"> value to be set. </param>
 public static void ActiveTransportCount(UnsafeBuffer metadataBuffer, int numberOfActiveTransports)
 {
     metadataBuffer.PutIntOrdered(LOG_ACTIVE_TRANSPORT_COUNT, numberOfActiveTransports);
 }
Exemplo n.º 8
0
 /// <summary>
 /// Set the status of the log buffer with StoreStore memory ordering semantics.
 /// </summary>
 /// <param name="status"> to be set for the log buffer. </param>
 public void StatusOrdered(int status)
 {
     _metaDataBuffer.PutIntOrdered(LogBufferDescriptor.TERM_STATUS_OFFSET, status);
 }
Exemplo n.º 9
0
 public virtual void SignalReady(int version)
 {
     buffer.PutIntOrdered(versionFieldOffset, version);
 }
Exemplo n.º 10
0
 /// <summary>
 /// Set the value of the current active partition index for the producer using memory ordered semantics.
 /// </summary>
 /// <param name="logMetaDataBuffer">    containing the meta data. </param>
 /// <param name="activePartitionIndex"> value of the active partition index used by the producer of this log. </param>
 public static void ActivePartitionIndex(UnsafeBuffer logMetaDataBuffer, int activePartitionIndex)
 {
     logMetaDataBuffer.PutIntOrdered(LOG_ACTIVE_PARTITION_INDEX_OFFSET, activePartitionIndex);
 }