protected void RaiseChannelAdded(ActorChannel channel) { Channels.Add(channel); var channelAddedEvent = new ChannelAddedEvent(channel); InputQueue.Add(channelAddedEvent); }
protected void RaiseChannelRemoved(ActorChannel channel) { if (!Channels.Remove(channel)) { throw new InvalidOperationException("Failed to remove channel from actor"); } var channelRemovedEvent = new ChannelRemovedEvent(channel); InputQueue.Add(channelRemovedEvent); }
protected void RaiseMessageReceived(ActorChannel channel, object message) { var messageReceivedEvent = new MessageReceivedEvent(channel, message); InputQueue.Add(messageReceivedEvent); }
public InputQueue Create(string inputFilePath, string outputFilePath, IEnumerable <InputStream> inputStreams, OutputQueue outputQueue) { if (inputStreams == null) { throw new ArgumentNullException("Input streams must be non-empty"); } if (outputQueue == null) { throw new ArgumentNullException("Output queue must be non-empty"); } if (string.IsNullOrEmpty(inputFilePath)) { throw new ArgumentException("Input file path must be non-empty"); } if (string.IsNullOrEmpty(outputFilePath)) { throw new ArgumentException("Output file path must be non-empty"); } InputQueue inputQueue = new InputQueue(); if (inputStreams.Count() == 1) { Stream rawOutputStream = File.Create(outputFilePath); OutputStream outputStream = new OutputStream(0, rawOutputStream); InputWorkItem workItem = new InputWorkItem( inputStreams.First(), outputStream, outputQueue, _compressionSettings ); inputQueue.Add(workItem); } else { FileInfo inputFileInfo = new FileInfo(inputFilePath); if (!inputFileInfo.Exists) { throw new ArgumentException("Input file does not exist"); } long availableMemoryStreamsCount = CalculateAvailableMemoryStreamsCount(inputStreams, inputFileInfo); int index = 0; foreach (InputStream inputStream in inputStreams) { Stream rawOutputStream = index < availableMemoryStreamsCount ? (Stream)(new MemoryStream()) : (Stream)(new TempFileStream()); OutputStream outputStream = new OutputStream(index++, rawOutputStream); InputWorkItem workItem = new InputWorkItem( inputStream, outputStream, outputQueue, _compressionSettings ); inputQueue.Add(workItem); } } return(inputQueue); }