public void SetUp() { RcvBuffer = new UnsafeBuffer(new byte[ALIGNED_FRAME_LENGTH]); DataHeader = new DataHeaderFlyweight(); MockFragmentHandler = A.Fake <FragmentHandler>(); MockControlledFragmentHandler = A.Fake <IControlledFragmentHandler>(); Position = A.Fake <IPosition>(options => options.Wrapping(new AtomicLongPosition())); LogBuffers = A.Fake <LogBuffers>(); ErrorHandler = A.Fake <ErrorHandler>(); Subscription = A.Fake <Subscription>(); TermBuffers = new UnsafeBuffer[LogBufferDescriptor.PARTITION_COUNT]; DataHeader.Wrap(RcvBuffer); for (var i = 0; i < LogBufferDescriptor.PARTITION_COUNT; i++) { TermBuffers[i] = new UnsafeBuffer(new byte[TERM_BUFFER_LENGTH]); } logMetaDataBuffer = new UnsafeBuffer(new byte[LogBufferDescriptor.LOG_META_DATA_LENGTH]); A.CallTo(() => LogBuffers.TermBuffers()).Returns(TermBuffers); A.CallTo(() => LogBuffers.TermLength()).Returns(TERM_BUFFER_LENGTH); A.CallTo(() => LogBuffers.MetaDataBuffer()).Returns(logMetaDataBuffer); }
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)); }
public virtual void SetUp() { RcvBuffer = new UnsafeBuffer(new byte[ALIGNED_FRAME_LENGTH]); DataHeader = new DataHeaderFlyweight(); MockFragmentHandler = A.Fake<FragmentHandler>(); MockControlledFragmentHandler = A.Fake<IControlledFragmentHandler>(); Position = A.Fake<IPosition>(options => options.Wrapping(new AtomicLongPosition())); LogBuffers = A.Fake<LogBuffers>(); ErrorHandler = A.Fake<ErrorHandler>(); Subscription = A.Fake<Subscription>(); AtomicBuffers = new UnsafeBuffer[(LogBufferDescriptor.PARTITION_COUNT * 2) + 1]; TermBuffers = new UnsafeBuffer[LogBufferDescriptor.PARTITION_COUNT]; DataHeader.Wrap(RcvBuffer); for (var i = 0; i < LogBufferDescriptor.PARTITION_COUNT; i++) { AtomicBuffers[i] = new UnsafeBuffer(new byte[TERM_BUFFER_LENGTH]); TermBuffers[i] = AtomicBuffers[i]; AtomicBuffers[i + LogBufferDescriptor.PARTITION_COUNT] = new UnsafeBuffer(new byte[LogBufferDescriptor.TERM_META_DATA_LENGTH]); } AtomicBuffers[LogBufferDescriptor.LOG_META_DATA_SECTION_INDEX] = new UnsafeBuffer(new byte[LogBufferDescriptor.LOG_META_DATA_LENGTH]); A.CallTo(() => LogBuffers.AtomicBuffers()).Returns(AtomicBuffers); A.CallTo(() => LogBuffers.TermLength()).Returns(TERM_BUFFER_LENGTH); }
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); }
public unsafe void CouldCreateLogBuffers() { var sw = new Stopwatch(); var l1 = new LogBuffers("../AeronLogBufferTests"); Assert.IsTrue(l1.TermLength >= LogBufferDescriptor.TERM_MIN_LENGTH); Console.WriteLine($"TermLength: {l1.TermLength}"); var activePartitionIndex = LogBufferDescriptor.ActivePartitionIndex(l1.LogMetaData); Console.WriteLine($"Active partition: {activePartitionIndex}"); var activePartition = l1.Partitions[activePartitionIndex]; var rawTail = activePartition.RawTailVolatile; Console.WriteLine($"Raw tail: {rawTail}"); var ta = new TermAppender(activePartition); var defaultHeader = DataHeaderFlyweight.CreateDefaultHeader(0, 0, activePartition.TermId); var headerWriter = new HeaderWriter(defaultHeader); BufferClaim claim; ta.Claim(headerWriter, 100, out claim); claim.Commit(); }
/// <summary> /// Releases all resource used by the <see cref="T:Samarium.PluginFramework.Logger.Logger"/> object. /// </summary> /// <remarks>Call <see cref="Dispose"/> when you are finished using the <see cref="T:Samarium.PluginFramework.Logger.Logger"/>. The /// <see cref="Dispose"/> method leaves the <see cref="T:Samarium.PluginFramework.Logger.Logger"/> in an unusable state. /// After calling <see cref="Dispose"/>, you must release all references to the /// <see cref="T:Samarium.PluginFramework.Logger.Logger"/> so the garbage collector can reclaim the memory that the /// <see cref="T:Samarium.PluginFramework.Logger.Logger"/> was occupying.</remarks> public void Dispose() { try { instances.Remove(LoggerName); FlushBuffer(); LogBuffers.Remove(LogBuffers[CurrentInstanceIndex]); } catch (Exception) { Fatal("Error while disposing of logger!"); } }
/// <summary> /// Construct a new image over a log to represent a stream of messages from a <seealso cref="Publication"/>. /// </summary> /// <param name="subscription"> to which this <seealso cref="Image"/> belongs. </param> /// <param name="sessionId"> of the stream of messages. </param> /// <param name="subscriberPosition"> for indicating the position of the subscriber in the stream. </param> /// <param name="logBuffers"> containing the stream of messages. </param> /// <param name="errorHandler"> to be called if an error occurs when polling for messages. </param> /// <param name="sourceIdentity"> of the source sending the stream of messages. </param> /// <param name="correlationId"> of the request to the media driver. </param> public Image(Subscription subscription, int sessionId, IPosition subscriberPosition, LogBuffers logBuffers, ErrorHandler errorHandler, string sourceIdentity, long correlationId) { Subscription = subscription; SessionId = sessionId; _subscriberPosition = subscriberPosition; _logBuffers = logBuffers; _errorHandler = errorHandler; SourceIdentity = sourceIdentity; CorrelationId = correlationId; var buffers = logBuffers.AtomicBuffers(); Array.Copy(buffers, 0, _termBuffers, 0, LogBufferDescriptor.PARTITION_COUNT); var termLength = logBuffers.TermLength(); _termLengthMask = termLength - 1; _positionBitsToShift = IntUtil.NumberOfTrailingZeros(termLength); _header = new Header(LogBufferDescriptor.InitialTermId(buffers[LogBufferDescriptor.LOG_META_DATA_SECTION_INDEX]), _positionBitsToShift); }
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()); }
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); }
public AppendLog(string filepath, int bufferSizeMb = 100) { var bufferSizeInBytes = BitUtil.FindNextPositivePowerOfTwo(bufferSizeMb * 1024 * 1024); _logBuffers = new LogBuffers(filepath, bufferSizeInBytes); for (int i = 0; i < PARTITION_COUNT; i++) { _termAppenders[i] = new TermAppender(_logBuffers.Buffers[i], _logBuffers.Buffers[i + PARTITION_COUNT]); } _termLengthMask = _logBuffers.TermLength - 1; _positionBitsToShift = BitUtil.NumberOfTrailingZeros(_logBuffers.TermLength); _initialTermId = InitialTermId(_logBuffers.LogMetaData); //var defaultHeader = DefaultFrameHeader(_logBuffers.LogMetaData); var defaultHeader = DataHeaderFlyweight.CreateDefaultHeader(0, 0, _initialTermId); _headerWriter = new HeaderWriter(defaultHeader); _subscriberPosition = Position; Trace.Assert(_subscriberPosition == Position); _cleaner = Task.Factory.StartNew(async() => { try { } finally { while (!_cts.IsCancellationRequested) { // try to clean every second await _cleanEvent.WaitAsync(1000); CleanLogBuffer(); } } }, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default) .ContinueWith(task => { Console.WriteLine("AppendLog CleanLogBuffer should never throw exceptions" + Environment.NewLine + task.Exception); Environment.FailFast("AppendLog CleanLogBuffer should never throw exceptions", task.Exception); }, TaskContinuationOptions.OnlyOnFaulted); _poller = Task.Factory.StartNew(() => { try { } finally { var sw = new SpinWait(); while (!_cts.IsCancellationRequested) { var fragments = Poll(); if (fragments > 0) { sw.Reset(); } else { sw.SpinOnce(); } // TODO try waithandle as in IpcLongIncrementListener //Thread.SpinWait(0); } } }, CancellationToken.None, TaskCreationOptions.LongRunning, TaskScheduler.Default) .ContinueWith(task => { Console.WriteLine("AppendLog Poll should never throw exceptions" + Environment.NewLine + task.Exception); Environment.FailFast("AppendLog Poll should never throw exceptions", task.Exception); }, TaskContinuationOptions.OnlyOnFaulted); }