public ChannelPurger(IMessageSelector selector, params IPollableChannel[] channels)
 {
     AssertUtils.ArgumentHasElements(channels, "channel");
     if(channels.Length == 1) {
         if (channels[0] == null)
             throw new ArgumentException("channel must not be null");
     }
     _selector = selector;
     _channels = channels;
 }
 /// <summary>
 /// Remove and return any messages that are stored for the current thread
 /// and do not match the provided <paramref name="selector"/>.
 /// </summary>
 /// <param name="selector">the message selector</param>
 /// <returns>the removed messages</returns>
 public override IList<IMessage> Purge(IMessageSelector selector)
 {
     IList<IMessage> removedMessages = new List<IMessage>();
     IMessage[] allMessages = _queue.ToArray();
     foreach(IMessage message in allMessages) {
         if(!selector.Accept(message) && _queue.Remove(message)) {
             removedMessages.Add(message);
         }
     }
     return removedMessages;
 }
 /// <summary>
 /// Create a MessageFilter that will delegate to the given
 /// </summary>
 /// <param name="selector"></param>
 public MessageFilter(IMessageSelector selector)
 {
     AssertUtils.ArgumentNotNull(selector, "selector must not be null");
     _selector = selector;
 }
 /// <summary>
 /// Create a new wire tap with the provided <see cref="IMessageSelector"/>.
 /// </summary>
 /// <param name="channel">the <see cref="IMessageChannel"/> to which intercepted messages will be sent</param>
 /// <param name="selector">the <see cref="IMessageSelector"/> that must accept a message for it to be sent to the intercepting channel</param>
 public WireTap(IMessageChannel channel, IMessageSelector selector)
 {
     AssertUtils.ArgumentNotNull(channel, "_channel", "_channel must not be null");
     _channel = channel;
     _selector = selector;
 }
        public override IList<IMessage> Purge(IMessageSelector selector)
        {
            if(selector == null) {
                return Clear();
            }

            // removing during iterate through an IEnumerable is not supported in .NET.
            // so we use a two step algorythm. first we add all message not accepted by the
            // the selector to a list and then we iterate through this list and remove the elements
            IList<IMessage> messagesToRemove = new List<IMessage>();
            foreach(IMessage message in _queue) {
                if (!selector.Accept(message)) {
                    messagesToRemove.Add(message);
                }
            }

            IList<IMessage> purgedMessages = new List<IMessage>();
            foreach(IMessage message in messagesToRemove) {
                if(_queue.Remove(message)) {
                    purgedMessages.Add(message);
                }
            }
            return purgedMessages;
        }
 public NetworkMessageHost(IMessageSelector selector)
 {
     this.selector = selector;
     this.listener = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
     this.connections = new List<SocketConnection>();
 }
 public abstract IList<IMessage> Purge(IMessageSelector selector);