Esempio n. 1
0
        /// <summary>
        /// Compact the buffer to reclaim unused space above the limit.
        /// </summary>
        /// <returns> the builder for fluent API usage. </returns>
        public BufferBuilder Compact()
        {
            _capacity = Math.Max(INITIAL_CAPACITY, BitUtil.FindNextPositivePowerOfTwo(_limit));
            _buffer   = CopyOf(_buffer, _capacity);
            _mutableDirectBuffer.Wrap(_buffer);

            return(this);
        }
Esempio n. 2
0
            public unsafe void Send(ReadOnlySpan <byte> message)
            {
                if (!IsConnected)
                    throw new InvalidOperationException("Trying to send when not connected");

                fixed(byte *ptr = message)
                {
                    _buffer.Wrap(ptr, message.Length);

                    var spinWait = new SpinWait();

                    while (true)
                    {
                        var errorCode = _publication.Offer(_buffer, 0, message.Length, _dataReservedValueSupplier);

                        if (errorCode >= 0)
                        {
                            break;
                        }

                        var result = Utils.InterpretPublicationOfferResult(errorCode);

                        if (result == AeronResultType.Success)
                        {
                            break;
                        }

                        if (result == AeronResultType.ShouldRetry)
                        {
                            spinWait.SpinOnce();
                            continue;
                        }

                        _client.SessionDisconnected(this);
                        return;
                    }

                    _buffer.Release();
                }
            }
Esempio n. 3
0
        /// <summary>
        /// Pre touch memory pages so they are faulted in to be available before access.
        /// </summary>
        public void PreTouch()
        {
            const int    value        = 0;
            int          pageSize     = LogBufferDescriptor.PageSize(_logMetaDataBuffer);
            UnsafeBuffer atomicBuffer = new UnsafeBuffer();

            foreach (MappedByteBuffer buffer in _mappedByteBuffers)
            {
                atomicBuffer.Wrap(buffer.Pointer, 0, (int)buffer.Capacity);

                for (int i = 0, length = atomicBuffer.Capacity; i < length; i += pageSize)
                {
                    atomicBuffer.CompareAndSetInt(i, value, value);
                }
            }
        }
Esempio n. 4
0
 /// <summary>
 /// Wrap a region of an underlying log buffer so it can represent a claimed space for use by a publisher.
 /// </summary>
 /// <param name="buffer"> to be wrapped. </param>
 /// <param name="offset"> at which the claimed region begins including space for the header. </param>
 /// <param name="length"> length of the underlying claimed region including space for the header. </param>
 public void Wrap(IAtomicBuffer buffer, int offset, int length)
 {
     _buffer.Wrap(buffer, offset, length);
 }
Esempio n. 5
0
 public static unsafe void Release(this UnsafeBuffer buffer)
 => buffer.Wrap((byte *)0, 0);
 /// <summary>
 /// Wrap a region of an underlying log buffer so can can represent a claimed space for use by a publisher.
 /// </summary>
 /// <param name="buffer"> to be wrapped. </param>
 /// <param name="offset"> at which the claimed region begins including space for the header. </param>
 /// <param name="length"> length of the underlying claimed region including space for the header. </param>
 public void Wrap(UnsafeBuffer buffer, int offset, int length)
 {
     _buffer.Wrap(buffer, offset, length);
 }
Esempio n. 7
0
 private void Resize(int newCapacity)
 {
     _buffer.Wrap(CopyOf(_buffer.ByteArray, newCapacity));
 }