// Placed object message payload into a segment from a buffer pool. When this get's too big, older blocks will be purged private ArraySegment <byte> SerializeMessageIntoPooledSegment(GeneratedBatchContainer queueMessage) { // serialize payload byte[] serializedPayload = this.serializationManager.SerializeToByteArray(queueMessage.Payload); int size = serializedPayload.Length; // get segment from current block ArraySegment <byte> segment; if (currentBuffer == null || !currentBuffer.TryGetSegment(size, out segment)) { // no block or block full, get new block and try again currentBuffer = bufferPool.Allocate(); if (this.OnBlockAllocated == null) { throw new OrleansException("Eviction strategy's OnBlockAllocated is not set for current data adapter, this will affect cache purging"); } //call EvictionStrategy's OnBlockAllocated method this.OnBlockAllocated.Invoke(currentBuffer); // if this fails with clean block, then requested size is too big if (!currentBuffer.TryGetSegment(size, out segment)) { string errmsg = Format(CultureInfo.InvariantCulture, "Message size is to big. MessageSize: {0}", size); throw new ArgumentOutOfRangeException(nameof(queueMessage), errmsg); } } Buffer.BlockCopy(serializedPayload, 0, segment.Array, segment.Offset, size); return(segment); }
// Placed object message payload into a segment from a buffer pool. When this get's too big, older blocks will be purged private ArraySegment <byte> SerializeMessageIntoPooledSegment(GeneratedBatchContainer queueMessage) { // serialize payload byte[] serializedPayload = SerializationManager.SerializeToByteArray(queueMessage.Payload); int size = serializedPayload.Length; // get segment from current block ArraySegment <byte> segment; if (currentBuffer == null || !currentBuffer.TryGetSegment(size, out segment)) { // no block or block full, get new block and try again currentBuffer = bufferPool.Allocate(); currentBuffer.SetPurgeAction(PurgeAction); // if this fails with clean block, then requested size is too big if (!currentBuffer.TryGetSegment(size, out segment)) { string errmsg = Format(CultureInfo.InvariantCulture, "Message size is to big. MessageSize: {0}", size); throw new ArgumentOutOfRangeException("queueMessage", errmsg); } } Buffer.BlockCopy(serializedPayload, 0, segment.Array, segment.Offset, size); return(segment); }
private ArraySegment <byte> GetSegment(int size) { // get segment from current block ArraySegment <byte> segment; if (currentBuffer == null || !currentBuffer.TryGetSegment(size, out segment)) { // no block or block full, get new block and try again currentBuffer = bufferPool.Allocate(); if (this.OnBlockAllocated == null) { throw new OrleansException("Eviction strategy's OnBlockAllocated is not set for current data adapter, this will affect cache purging"); } //call EvictionStrategy's OnBlockAllocated method this.OnBlockAllocated.Invoke(currentBuffer); // if this fails with clean block, then requested size is too big if (!currentBuffer.TryGetSegment(size, out segment)) { string errmsg = String.Format(CultureInfo.InvariantCulture, "Message size is to big. MessageSize: {0}", size); throw new ArgumentOutOfRangeException(nameof(size), errmsg); } } return(segment); }
// Placed object message payload into a segment from a buffer pool. When this get's too big, older blocks will be purged private ArraySegment <byte> SerializeMessageIntoPooledSegment(MemoryMessageData queueMessage) { // serialize payload int size = SegmentBuilder.CalculateAppendSize(queueMessage.Payload); // get segment from current block ArraySegment <byte> segment; if (currentBuffer == null || !currentBuffer.TryGetSegment(size, out segment)) { // no block or block full, get new block and try again currentBuffer = bufferPool.Allocate(); //call EvictionStrategy's OnBlockAllocated method this.evictionStrategy.OnBlockAllocated(currentBuffer); // if this fails with clean block, then requested size is too big if (!currentBuffer.TryGetSegment(size, out segment)) { string errmsg = String.Format(CultureInfo.InvariantCulture, "Message size is too big. MessageSize: {0}", size); throw new ArgumentOutOfRangeException(nameof(queueMessage), errmsg); } } // encode namespace, offset, partitionkey, properties and payload into segment int writeOffset = 0; SegmentBuilder.Append(segment, ref writeOffset, queueMessage.Payload); return(segment); }
// Placed object message payload into a segment from a buffer pool. When this get's too big, older blocks will be purged private ArraySegment <byte> SerializeMessageIntoPooledSegment(GeneratedBatchContainer queueMessage) { byte[] serializedPayload = this.serializationManager.SerializeToByteArray(queueMessage.Payload); // get size of namespace, offset, partitionkey, properties, and payload int size = SegmentBuilder.CalculateAppendSize(serializedPayload); // get segment ArraySegment <byte> segment; if (currentBuffer == null || !currentBuffer.TryGetSegment(size, out segment)) { // no block or block full, get new block and try again currentBuffer = bufferPool.Allocate(); //call EvictionStrategy's OnBlockAllocated method this.evictionStrategy.OnBlockAllocated(currentBuffer); // if this fails with clean block, then requested size is too big if (!currentBuffer.TryGetSegment(size, out segment)) { string errmsg = $"Message size is to big. MessageSize: {size}"; throw new ArgumentOutOfRangeException(nameof(queueMessage), errmsg); } } // encode namespace, offset, partitionkey, properties and payload into segment int writeOffset = 0; SegmentBuilder.Append(segment, ref writeOffset, serializedPayload); return(segment); }
// Placed object message payload into a segment from a buffer pool. When this get's too big, older blocks will be purged private ArraySegment <byte> SerializeMessageIntoPooledSegment(EventData queueMessage) { byte[] payloadBytes = queueMessage.GetBytes(); string streamNamespace = queueMessage.GetStreamNamespaceProperty(); int size = SegmentBuilder.CalculateAppendSize(streamNamespace) + SegmentBuilder.CalculateAppendSize(queueMessage.Offset) + SegmentBuilder.CalculateAppendSize(payloadBytes); // get segment from current block ArraySegment <byte> segment; if (currentBuffer == null || !currentBuffer.TryGetSegment(size, out segment)) { // no block or block full, get new block and try again currentBuffer = bufferPool.Allocate(); currentBuffer.SetPurgeAction(PurgeAction); // if this fails with clean block, then requested size is too big if (!currentBuffer.TryGetSegment(size, out segment)) { string errmsg = String.Format(CultureInfo.InvariantCulture, "Message size is to big. MessageSize: {0}", size); throw new ArgumentOutOfRangeException("queueMessage", errmsg); } } // encode namespace, offset, and payload into segment int writeOffset = 0; SegmentBuilder.Append(segment, ref writeOffset, streamNamespace); SegmentBuilder.Append(segment, ref writeOffset, queueMessage.Offset); SegmentBuilder.Append(segment, ref writeOffset, payloadBytes); return(segment); }
public void FillBlockTestBvt() { IObjectPool <FixedSizeBuffer> pool = new MyTestPooled(); FixedSizeBuffer buffer = pool.Allocate(); ArraySegment <byte> segment; for (int i = 0; i < TestBlockSize; i++) { Assert.True(buffer.TryGetSegment(1, out segment), String.Format("Should be able to get {0}th segement of size 1.", i + 1)); Assert.Equal(i, segment.Offset); Assert.Equal(1, segment.Count); } Assert.False(buffer.TryGetSegment(1, out segment), String.Format("Should be able to get {0}th segement of size 1.", TestBlockSize + 1)); Assert.Null(segment.Array); Assert.Equal(0, segment.Offset); Assert.Equal(0, segment.Count); }
public void FillBlockTestBvt() { IObjectPool <FixedSizeBuffer> pool = new MyTestPooled(); FixedSizeBuffer buffer = pool.Allocate(); ArraySegment <byte> segment; for (int i = 0; i < TestBlockSize; i++) { Assert.True(buffer.TryGetSegment(1, out segment), String.Format("Should be able to get {0}th segement of size 1.", i + 1)); Assert.Equal(i, segment.Offset); Assert.Single(segment); } Assert.False(buffer.TryGetSegment(1, out segment), String.Format("Should be able to get {0}th segement of size 1.", TestBlockSize + 1)); Assert.Null(segment.Array); Assert.Equal(0, segment.Offset); #pragma warning disable xUnit2013 // Do not use equality check to check for collection size. Assert.Equal(0, segment.Count); #pragma warning restore xUnit2013 // Do not use equality check to check for collection size. }
public void EmptyBlockTryGetMaxSegmentBvt() { IObjectPool <FixedSizeBuffer> pool = new MyTestPooled(); FixedSizeBuffer buffer = pool.Allocate(); ArraySegment <byte> segment; Assert.True(buffer.TryGetSegment(TestBlockSize, out segment), "Should be able to get segement of block size."); Assert.NotNull(segment.Array); Assert.Equal(0, segment.Offset); Assert.Equal(TestBlockSize, segment.Count); }
public void EmptyBlockGetSegmentTooLargeBvt() { IObjectPool <FixedSizeBuffer> pool = new MyTestPooled(); FixedSizeBuffer buffer = pool.Allocate(); ArraySegment <byte> segment; Assert.False(buffer.TryGetSegment(TestBlockSize + 1, out segment), "Should not be able to get segement that is bigger than block."); Assert.Null(segment.Array); Assert.Equal(0, segment.Offset); Assert.Equal(0, segment.Count); }
public void EmptyBlockGetSegmentTooLargeBvt() { IObjectPool <FixedSizeBuffer> pool = new MyTestPooled(); FixedSizeBuffer buffer = pool.Allocate(); ArraySegment <byte> segment; Assert.False(buffer.TryGetSegment(TestBlockSize + 1, out segment), "Should not be able to get segement that is bigger than block."); Assert.Null(segment.Array); Assert.Equal(0, segment.Offset); #pragma warning disable xUnit2013 // Do not use equality check to check for collection size. Assert.Equal(0, segment.Count); #pragma warning restore xUnit2013 // Do not use equality check to check for collection size. }
private ArraySegment <byte> GetSegment(int size) { // get segment from current block ArraySegment <byte> segment; if (currentBuffer == null || !currentBuffer.TryGetSegment(size, out segment)) { // no block or block full, get new block and try again currentBuffer = bufferPool.Allocate(); //call EvictionStrategy's OnBlockAllocated method this.evictionStrategy.OnBlockAllocated(currentBuffer); // if this fails with clean block, then requested size is too big if (!currentBuffer.TryGetSegment(size, out segment)) { throw new ArgumentOutOfRangeException(nameof(size), $"Message size is to big. MessageSize: {size}"); } } return(segment); }
private ArraySegment <byte> GetSegment(int size) { // get segment from current block ArraySegment <byte> segment; if (currentBuffer == null || !currentBuffer.TryGetSegment(size, out segment)) { // no block or block full, get new block and try again currentBuffer = bufferPool.Allocate(); currentBuffer.SetPurgeAction(PurgeAction); // if this fails with clean block, then requested size is too big if (!currentBuffer.TryGetSegment(size, out segment)) { string errmsg = String.Format(CultureInfo.InvariantCulture, "Message size is to big. MessageSize: {0}", size); throw new ArgumentOutOfRangeException("size", errmsg); } } return(segment); }
// Placed object message payload into a segment from a buffer pool. When this get's too big, older blocks will be purged private ArraySegment <byte> SerializeMessageIntoPooledSegment(TestQueueMessage queueMessage) { // get segment from current block ArraySegment <byte> segment; if (currentBuffer == null || !currentBuffer.TryGetSegment(queueMessage.Data.Length, out segment)) { // no block or block full, get new block and try again currentBuffer = bufferPool.Allocate(); currentBuffer.SetPurgeAction(PurgeAction); // if this fails with clean block, then requested size is too big if (!currentBuffer.TryGetSegment(queueMessage.Data.Length, out segment)) { string errmsg = String.Format(CultureInfo.InvariantCulture, "Message size is to big. MessageSize: {0}", queueMessage.Data.Length); throw new ArgumentOutOfRangeException("queueMessage", errmsg); } } Buffer.BlockCopy(queueMessage.Data, 0, segment.Array, segment.Offset, queueMessage.Data.Length); return(segment); }
// Placed object message payload into a segment from a buffer pool. When this get's too big, older blocks will be purged private ArraySegment <byte> SerializeMessageIntoPooledSegment(MemoryMessageData queueMessage) { // serialize payload int size = queueMessage.Payload.Count; // get segment from current block ArraySegment <byte> segment; if (currentBuffer == null || !currentBuffer.TryGetSegment(size, out segment)) { // no block or block full, get new block and try again currentBuffer = bufferPool.Allocate(); currentBuffer.SetPurgeAction(PurgeAction); // if this fails with clean block, then requested size is too big if (!currentBuffer.TryGetSegment(size, out segment)) { string errmsg = String.Format(CultureInfo.InvariantCulture, "Message size is too big. MessageSize: {0}", size); throw new ArgumentOutOfRangeException(nameof(queueMessage), errmsg); } } Buffer.BlockCopy(queueMessage.Payload.Array, queueMessage.Payload.Offset, segment.Array, segment.Offset, queueMessage.Payload.Count); return(segment); }