/// <summary>
        /// Overrides the default Stream lifecycle implementation.  See interface definitions for more details.
        /// </summary>
        /// <param name="writeStreamFactory">Creates sequentially writable Streams.  These Streams won't last long, so the primary
        /// concern will be that they should be fast.  This will be invoked on the thread(s) writing to the rolling memory.</param>
        /// <param name="writeStreamToReadStreamConverter">Converts Streams created by writeStreamFactory to sequentially readable
        /// Streams.  Ordinarily data will sit in these Streams between being written and being read, so an underlying storage
        /// medium which can buffer the expected amount of data is preferable.  This will ordinarily be invoked on the thread(s)
        /// reading from the rolling memory, although it may be invoked during writing if clearing space becomes an immediate
        /// requirement.</param>
        /// <param name="writeStreamDataSourceDisposerFactory">Creates IDataSourceDisposers for Streams created by
        /// writeStreamFactory.</param>
        /// <param name="readStreamDataSourceDisposerFactory">Creates IDataSourceDisposers for Streams returned by
        /// IWriteStreamToReadStreamConverter.</param>
        /// <returns></returns>

        public RollingMemoryBuilder SetupStreamLifecycleImplementation(
            IWriteStreamFactory writeStreamFactory, IWriteStreamToReadStreamConverter writeStreamToReadStreamConverter,
            IStreamDataSourceDisposerFactory writeStreamDataSourceDisposerFactory, IStreamDataSourceDisposerFactory readStreamDataSourceDisposerFactory)
        {
            if (writeStreamFactory == null)
                throw new ArgumentNullException("writeStreamFactory");

            if (writeStreamToReadStreamConverter == null)
                throw new ArgumentNullException("writeStreamToReadStreamConverter");

            if (writeStreamDataSourceDisposerFactory == null)
                throw new ArgumentNullException("writeStreamDataSourceDisposerFactory");

            if (readStreamDataSourceDisposerFactory == null)
                throw new ArgumentNullException("readStreamDataSourceDisposerFactory");

            _writeStreamFactory = new Lazy<IWriteStreamFactory>(() => writeStreamFactory, true);

            _writeStreamToReadStreamConverter = new Lazy<IWriteStreamToReadStreamConverter>(() => writeStreamToReadStreamConverter, true);

            _writeStreamDataSourceDisposerFactory = new Lazy<IStreamDataSourceDisposerFactory>(() => writeStreamDataSourceDisposerFactory, true);

            _readStreamDataSourceDisposerFactory = new Lazy<IStreamDataSourceDisposerFactory>(() => readStreamDataSourceDisposerFactory, true);

            return this;
        }
 public CompletedWriteStreamBuffer(IReadStreamQueueTarget readStreamQueueTarget,
     IWriteStreamToReadStreamConverter writeStreamToReadStreamConverter,
     IStreamDataSourceDisposerFactory readStreamDataSourceDisposerFactory,
     IDataSourceDisposerRegister dataSourceDisposerRegister,
     long? maximumAllowedWriteStreamBytes)
 {
     _readStreamQueueTarget = readStreamQueueTarget;
     _writeStreamToReadStreamConverter = writeStreamToReadStreamConverter;
     _maximumAllowedWriteStreamBytes = maximumAllowedWriteStreamBytes;
     _readStreamDataSourceDisposerFactory = readStreamDataSourceDisposerFactory;
     _dataSourceDisposerRegister = dataSourceDisposerRegister;
 }
Example #3
0
        public RollingMemory(
            IWriteStreamFactory writeStreamFactory,
            IWriteStreamToReadStreamConverter writeStreamToReadStreamConverter,
            IStreamDataSourceDisposerFactory writeStreamDataSourceDisposerFactory,
            IStreamDataSourceDisposerFactory readStreamDataSourceDisposerFactory,
            IRollingMemoryStateMonitor rollingMemoryStateMonitor,
            long? maximumAllowedWriteStreamBytes, TimeSpan? maximumAllowedUnavailableAge,
            long? maximumAllowedUnavailableBytes, ICurrentDateTimeSource currentDateTimeSource)
        {

            var readStreamQueue = new ReadStreamQueue();

            var dataSourceDisposerRegister = new DataSourceDisposerRegister();

            var completedWriteStreamBuffer = new CompletedWriteStreamBuffer(
                readStreamQueue,
                writeStreamToReadStreamConverter,
                readStreamDataSourceDisposerFactory,
                dataSourceDisposerRegister,
                maximumAllowedWriteStreamBytes);

            var rollingMemoryWriteStream = new RollingMemoryWriteStream(
                writeStreamFactory,
                completedWriteStreamBuffer,
                completedWriteStreamBuffer,
                currentDateTimeSource,
                writeStreamDataSourceDisposerFactory,
                dataSourceDisposerRegister,
                rollingMemoryStateMonitor);

            var readStreamQueueRefresher = new ReadStreamQueueRefresher(
                rollingMemoryWriteStream,
                completedWriteStreamBuffer,
                maximumAllowedUnavailableAge,
                maximumAllowedUnavailableBytes);

            var completedReadStreamHandler = new CompletedReadStreamHandler(
                dataSourceDisposerRegister);

            var rollingMemoryReadStream = new RollingMemoryReadStream(
                readStreamQueue,
                readStreamQueueRefresher,
                completedReadStreamHandler,
                rollingMemoryStateMonitor);

            _readStream = rollingMemoryReadStream;

            _writeStream = rollingMemoryWriteStream;

            _completedWriteStreamBuffer = completedWriteStreamBuffer;
        }
        public RollingMemoryWriteStream(IWriteStreamFactory targetFactory,
            ICompletedWriteStreamHandler completedWriteStreamHandler,
            IWriteStreamLengthValidator activeWriteStreamLengthValidator,
            ICurrentDateTimeSource currentDateTimeSource,
            IStreamDataSourceDisposerFactory writeStreamDataSourceDisposerFactory,
            IDataSourceDisposerRegister dataSourceDisposerRegister,
            IRollingMemoryStateMonitor rollingMemoryStateMonitor)
        {
            _targetFactory = targetFactory;

            _completedWriteStreamHandler = completedWriteStreamHandler;

            _activeWriteStreamLengthValidator = activeWriteStreamLengthValidator;

            _currentDateTimeSource = currentDateTimeSource;

            _writeStreamDataSourceDisposerFactory = writeStreamDataSourceDisposerFactory;

            _dataSourceDisposerRegister = dataSourceDisposerRegister;

            _rollingMemoryStateMonitor = rollingMemoryStateMonitor;
        }