public void HandleInboundMultiPartChunk(MultiPartChunkDto chunk) { bool isAdded = false; ChunkReassemblyContext addedChunkReassemblyContext = null; var chunkReassemblyContext = chunkReassemblerContextsByMessageId.GetOrAdd( chunk.MultiPartMessageId, add => { // logger.Info(Thread.CurrentThread.ManagedThreadId + ": " + "NEW " + chunk.MultiPartMessageId + " " + this.GetHashCode()); isAdded = true; return addedChunkReassemblyContext = new ChunkReassemblyContext(chunk.ChunkCount); }); // if (isAdded) { // logger.Info(Thread.CurrentThread.ManagedThreadId + ": " + chunkReassemblyContext.GetHashCode() + " " + new ChunkReassemblyContext(0).GetHashCode() + ""); // } if (chunkReassemblyContext == addedChunkReassemblyContext) { Go(async () => { await Task.Delay(kSomethingExpiration).ConfigureAwait(false); RemoveAssemblerFromCache(chunk.MultiPartMessageId); }); } var completedChunks = chunkReassemblyContext.AddChunk(chunk); if (completedChunks != null) { ReassembleChunksAndDispatch(completedChunks); } }
public MultiPartChunkDto[] AddChunk(MultiPartChunkDto chunk) { if (Interlocked.CompareExchange(ref x[chunk.ChunkIndex], chunk, null) == null) { var newChunksRemaining = Interlocked.Decrement(ref chunksRemaining); if (newChunksRemaining < 100) { // Console.WriteLine(chunk.MultiPartMessageId.ToString("n").Substring(0, 6) + " MPP REMAINING " + newChunksRemaining); } if (newChunksRemaining == 0) { return x; } } return null; }