Esempio n. 1
0
        /// <summary>
        /// Instantiate a new LZ4 codec handler.
        /// </summary>
        /// <param name="blockSize">Block size to compress against.</param>
        /// <param name="highCompression">Whether to use high compression mode.</param>
        /// <param name="memoryStreamManager">RecyclableMemoryStreamManager to allocate buffers from.</param>
        /// <param name="codecProvider">Which codec provider to use.</param>
        public LZ4Codec(int blockSize, bool highCompression, RecyclableMemoryStreamManager memoryStreamManager,
                        CodecProvider codecProvider)
        {
            if (blockSize < 1 << 12 || blockSize > 1 << 28)
            {
                throw new ArgumentOutOfRangeException(nameof(blockSize),
                                                      "Block size must be between 4KB and 256MB inclusive.");
            }
            if (memoryStreamManager == null)
            {
                throw new ArgumentNullException(nameof(memoryStreamManager));
            }
            switch (codecProvider)
            {
            case CodecProvider.LZ4Net:
                this.provider = new LZ4NetCodecProvider();
                break;
            default:
                throw new ArgumentOutOfRangeException(nameof(codecProvider));
            }

            this.BlockSize = blockSize;
            this.HighCompression = highCompression;
            this.Codec = codecProvider;
            this.memoryStreamManager = memoryStreamManager;
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="ByteArraySerializer"/> class.
        /// </summary>
        /// <param name="compressionOption">The compression option.</param>
        public ByteArraySerializer(CompressionOption compressionOption)
        {
            _serializer = new WireSerializer();
            _memoryManager = new RecyclableMemoryStreamManager();

            _compressionOption = compressionOption;
            _streamCompressor = GetCompressor(compressionOption);
        }
        public void SetUp()
        {
            if (this.memoryStreamManager == null)
            {
                this.memoryStreamManager = new RecyclableMemoryStreamManager(1 << 17, 1 << 20, 1 << 24);
            }

            this.dimensionSet = DimensionSetTests.CreateDimensionSet(2);
            this.dataStore = new TestKeyedDataStore(this.dimensionSet, this.memoryStreamManager);
        }
Esempio n. 4
0
 public void SetUp()
 {
     this.stream = new MemoryStream();
     this.streamManager = new RecyclableMemoryStreamManager(1 << 17, 2, 1 << 24);
     this.dimensions = new DimensionSet(new HashSet<Dimension>(new[] {new Dimension(AnyDimension)}));
     this.data = new KeyedDataStore<InternalHitCount>(this.dimensions,
                                                                                 this.streamManager);
     var hitCount = new InternalHitCount();
     hitCount.AddValue(AnyDataValue);
     this.data.AddValue(new DimensionSpecification {{AnyDimension, AnyDimensionValue}}, AnyDataValue);
     this.data.Merge();
 }
Esempio n. 5
0
        public WriterStream(Stream innerStream, RecyclableMemoryStreamManager memStreamManager)
        {
            if (innerStream == null || !innerStream.CanWrite)
            {
                throw new ArgumentException("input stream must be writable");
            }

            this.innerStream = innerStream;

            // our buffer must be able to hold at least any primitive (sizeof ulong)
            this.intermediateBufferStream = memStreamManager != null
                                                ? memStreamManager.GetStream("BondWriterStream", sizeof(ulong))
                                                : new MemoryStream(sizeof(ulong));
        }
        public CommandHandlerController(
            CommandHandlingSettings settings,
            RecyclableMemoryStreamManager recyclableMemoryStreamManager)
        {
            _settings = settings;
            _recyclableMemoryStreamManager = recyclableMemoryStreamManager;

            var temp = _settings.OnPredispatch ?? ((_, __) => { });
            _predispatch = (metadata, headers) =>
            {
                metadata[CommandMessageExtensions.UserKey] = (User as ClaimsPrincipal) ?? new ClaimsPrincipal(new ClaimsIdentity());
                try
                {
                    temp(metadata, headers);
                }
                catch(Exception ex)
                {
                    s_logger.ErrorException("Exception occured invoking the Predispatch hook", ex);
                }
            };
        }
Esempio n. 7
0
 /// <summary>
 /// Instantiate a new LZ4 codec handler using the default settings for block size, high compression, and codec provider.
 /// </summary>
 /// <param name="memoryStreamManager">RecyclableMemoryStreamManager to allocate buffers from.</param>
 public LZ4Codec(RecyclableMemoryStreamManager memoryStreamManager)
     : this(DefaultBlockSize, DefaultHighCompression, memoryStreamManager, CodecProvider.Default) { }
        /// <summary>
        /// Allocate a new RecyclableMemoryStream object
        /// </summary>
        /// <param name="memoryManager">The memory manager</param>
        /// <param name="tag">A string identifying this stream for logging and debugging purposes</param>
        /// <param name="requestedSize">The initial requested size to prevent future allocations</param>
        /// <param name="initialLargeBuffer">An initial buffer to use. This buffer will be owned by the stream and returned to the memory manager upon Dispose.</param>
        internal RecyclableMemoryStream(RecyclableMemoryStreamManager memoryManager, string tag, int requestedSize,
            byte[] initialLargeBuffer)
            : base(emptyArray)
        {
            this.memoryManager = memoryManager;
            this.id = Guid.NewGuid();
            this.tag = tag;

            if (requestedSize < memoryManager.BlockSize)
            {
                requestedSize = memoryManager.BlockSize;
            }

            if (initialLargeBuffer == null)
            {
                this.EnsureCapacity(requestedSize);
            }
            else
            {
                this.largeBuffer = initialLargeBuffer;
            }

            this.disposed = false;

            if (this.memoryManager.GenerateCallStacks)
            {
                this.allocationStack = Environment.StackTrace;
            }

            this.memoryManager.ReportStreamCreated();
        }
Esempio n. 9
0
 /// <summary>
 /// Instantiate a new LZ4 codec handler using the default codec provider.
 /// </summary>
 /// <param name="blockSize">Block size to compress against.</param>
 /// <param name="highCompression">Whether to use high compression mode.</param>
 /// <param name="memoryStreamManager">RecyclableMemoryStreamManager to allocate buffers from.</param>
 public LZ4Codec(int blockSize, bool highCompression, RecyclableMemoryStreamManager memoryStreamManager)
     : this(blockSize, highCompression, memoryStreamManager, CodecProvider.Default) { }
 /// <summary>
 /// Allocate a new RecyclableMemoryStream object
 /// </summary>
 /// <param name="memoryManager">The memory manager</param>
 /// <param name="tag">A string identifying this stream for logging and debugging purposes</param>
 public RecyclableMemoryStream(RecyclableMemoryStreamManager memoryManager, string tag)
     : this(memoryManager, tag, 0, null)
 {
 }
 /// <summary>
 /// Allocate a new RecyclableMemoryStream object
 /// </summary>
 /// <param name="memoryManager">The memory manager</param>
 /// <param name="tag">A string identifying this stream for logging and debugging purposes</param>
 /// <param name="requestedSize">The initial requested size to prevent future allocations</param>
 public RecyclableMemoryStream(RecyclableMemoryStreamManager memoryManager, string tag, int requestedSize)
     : this(memoryManager, tag, requestedSize, null)
 {
 }
Esempio n. 12
0
        public override void Setup()
        {
            this.dataManager.CompactionConfiguration =
                new DataCompactionConfiguration(new[]
                                         {
                                             new DataIntervalConfiguration(TimeSpan.FromMinutes(5), TimeSpan.MaxValue), 
                                         });
            this.dataManager.MaximumDataAge = TimeSpan.Zero; // Don't want data getting deleted here.

            // Make a counter and write some stuff.
            this.dimensionSet = new DimensionSet(new HashSet<Dimension> { new Dimension(AnyDimension), });
            var counter = this.dataManager.CreateHitCounter(AnyCounter, this.dimensionSet).Result; 

            var dims = new DimensionSpecification();
            var timestamp = DateTime.Now;
            dims[AnyDimension] = "a";
            counter.Increment(dims, timestamp);
            dims[AnyDimension] = "b";
            counter.Increment(2, dims, timestamp);
            dims[AnyDimension] = "c";
            counter.Increment(dims, timestamp);

            // We need to force a seal by setting some value waaaay in the future.
            counter.Increment(dims, timestamp.AddYears(10));

            this.memoryStreamManager = new RecyclableMemoryStreamManager(1 << 17, 1 << 20, 1 << 24);
        }
 /// <summary>
 /// Allocate a new RecyclableMemoryStream object.
 /// </summary>
 /// <param name="memoryManager">The memory manager</param>
 /// <param name="id">A unique identifier which can be used to trace usages of the stream.</param>
 public RecyclableMemoryStream(RecyclableMemoryStreamManager memoryManager, Guid id)
     : this(memoryManager, id, null, 0, null)
 {
 }
Esempio n. 14
0
 public RecyclableMemoryStream(RecyclableMemoryStreamManager memoryManager)
     : this();
Esempio n. 15
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="next"></param>
 public RequestResponseLoggingMiddleware(RequestDelegate next)
 {
     _next = next;
     _recyclableMemoryStreamManager = new RecyclableMemoryStreamManager();
 }
Esempio n. 16
0
 /// <summary>
 /// Create an aggregation client for a given data type.
 /// </summary>
 /// <param name="dataType">Type of sample to aggregate.</param>
 /// <param name="name">Name of the data to aggregate.</param>
 /// <param name="sources">List of source systems to aggregate from.</param>
 /// <param name="startTime">Start of timespan to aggregate data for.</param>
 /// <param name="endTime">End of timespan to aggregate data for.</param>
 /// <param name="streamManager">RecyclableMemoryStreamManager to use when aggregating data.</param>
 /// <returns>Suitable aggregation client.</returns>
 public static IPersistedDataAggregator CreateAggregatorForSampleType(MetricSystem.PersistedDataType dataType, string name,
                                                                      IEnumerable<string> sources,
                                                                      DateTime startTime, DateTime endTime,
                                                                      RecyclableMemoryStreamManager streamManager)
 {
     return CreateAggregatorForSampleType(dataType, name, null, sources, startTime, endTime, streamManager);
 }
Esempio n. 17
0
 public void BeBinaryWriter_Close_Sets_Frame_Body_Length()
 {
     const int frameLength = 10;
     const int iterations = 8;
     var bufferPool = new RecyclableMemoryStreamManager();
     using (var stream = bufferPool.GetStream("test"))
     {
         for (var i = 0; i < iterations; i++)
         {
             var writer = new FrameWriter(stream);
             writer.WriteFrameHeader(2, 0, 127, 8);
             writer.WriteInt16(Convert.ToInt16(0x0900 + i));
             var length = writer.Close();
             Assert.AreEqual(frameLength, length);
         }
         Assert.AreEqual(frameLength * iterations, stream.Length);
         for (byte i = 0; i < iterations; i++)
         {
             var buffer = new byte[frameLength];
             stream.Position = i * frameLength;
             stream.Read(buffer, 0, frameLength);
             CollectionAssert.AreEqual(new byte[] { 2, 0, 127, 8, 0, 0, 0, 2, 9, i}, buffer);
         }
     }
 }
Esempio n. 18
0
        public static IPersistedDataAggregator CreateAggregatorForSampleType(MetricSystem.PersistedDataType dataType, string name,
                                                                             DimensionSet dimensionSet,
                                                                             IEnumerable<string> sources,
                                                                             DateTime startTime, DateTime endTime,
                                                                             RecyclableMemoryStreamManager streamManager)
        {
            switch (dataType)
            {
            case MetricSystem.PersistedDataType.HitCount:
                return new PersistedDataAggregator<InternalHitCount>(name, dimensionSet, sources, 
                                                                            startTime, endTime, streamManager);

            case MetricSystem.PersistedDataType.VariableEncodedHistogram:
                return new PersistedDataAggregator<InternalHistogram>(name, dimensionSet, sources,
                                                                            startTime, endTime, streamManager);
                
            default:
                throw new ArgumentException("Invalid data type", "dataType");
            }
        }
 /// <summary>
 /// Allocate a new RecyclableMemoryStream object
 /// </summary>
 /// <param name="memoryManager">The memory manager</param>
 /// <param name="id">A unique identifier which can be used to trace usages of the stream.</param>
 /// <param name="tag">A string identifying this stream for logging and debugging purposes</param>
 /// <param name="requestedSize">The initial requested size to prevent future allocations</param>
 public RecyclableMemoryStream(RecyclableMemoryStreamManager memoryManager, Guid id, string tag, int requestedSize)
     : this(memoryManager, id, tag, requestedSize, null)
 {
 }
 /// <summary>
 /// Allocate a new RecyclableMemoryStream object
 /// </summary>
 /// <param name="memoryManager">The memory manager</param>
 /// <param name="id">A unique identifier which can be used to trace usages of the stream.</param>
 /// <param name="tag">A string identifying this stream for logging and debugging purposes</param>
 public RecyclableMemoryStream(RecyclableMemoryStreamManager memoryManager, Guid id, string tag)
     : this(memoryManager, id, tag, 0, null)
 {
 }
 /// <summary>
 /// Initializes the <see cref="SharedMemoryStream"/> class.
 /// </summary>
 static SharedMemoryStream()
 {
     StreamManager = new RecyclableMemoryStreamManager();
 }
Esempio n. 22
0
 static RecyclableMemoryStreamManager()
 {
     SharedInstance = new RecyclableMemoryStreamManager();
 }
 static RecyclableMemoryStreamManager()
 {
     SharedInstance = new RecyclableMemoryStreamManager();
 }
 /// <summary>
 /// Allocate a new RecyclableMemoryStream object.
 /// </summary>
 /// <param name="memoryManager">The memory manager</param>
 public RecyclableMemoryStream(RecyclableMemoryStreamManager memoryManager)
     : this(memoryManager, null, 0, null)
 {
 }
Esempio n. 25
0
 public void RecyclableMemoryStream_GetBufferList_Handles_Multiple_Blocks()
 {
     const int blockSize = 16;
     var buffer = new byte[256];
     for (var i = 0; i < buffer.Length; i++)
     {
         buffer[i] = (byte) i;
     }
     var bufferPool = new RecyclableMemoryStreamManager(blockSize, 1024, 1024 * 1024 * 10);
     using (var stream = (RecyclableMemoryStream)bufferPool.GetStream())
     {
         stream.Write(buffer, 0, 12);
         CollectionAssert.AreEqual(new[] { new ArraySegment<byte>(buffer, 0, 12) }, stream.GetBufferList());
     }
     using (var stream = (RecyclableMemoryStream)bufferPool.GetStream())
     {
         stream.Write(buffer, 0, blockSize);
         var bufferList = stream.GetBufferList();
         Assert.AreEqual(1, bufferList.Count);
         CollectionAssert.AreEqual(new[] { new ArraySegment<byte>(buffer, 0, blockSize) }, bufferList);
     }
     using (var stream = (RecyclableMemoryStream)bufferPool.GetStream())
     {
         stream.Write(buffer, 0, blockSize * 2);
         var bufferList = stream.GetBufferList();
         Assert.AreEqual(2, bufferList.Count);
         CollectionAssert.AreEqual(new[] { new ArraySegment<byte>(buffer, 0, blockSize), new ArraySegment<byte>(buffer, blockSize, blockSize) }, bufferList);
     }
     using (var stream = (RecyclableMemoryStream)bufferPool.GetStream())
     {
         stream.Write(buffer, 0, blockSize * 2 + 1);
         var bufferList = stream.GetBufferList();
         Assert.AreEqual(3, bufferList.Count);
         CollectionAssert.AreEqual(new[]
         {
             new ArraySegment<byte>(buffer, 0, blockSize),
             new ArraySegment<byte>(buffer, blockSize, blockSize),
             new ArraySegment<byte>(buffer, blockSize * 2, 1)
         }, bufferList);
     }
 }
 /// <summary>
 /// Allocate a new RecyclableMemoryStream object.
 /// </summary>
 /// <param name="memoryManager">The memory manager</param>
 public RecyclableMemoryStream(RecyclableMemoryStreamManager memoryManager)
     : this(memoryManager, Guid.NewGuid(), null, 0, null)
 {
 }