Ejemplo n.º 1
0
        public int AddSource(TcpClient client)
        {
            var streamId = Interlocked.Increment(ref _streamCount);
            var s        = new CommandStream(streamId, client, _serializer);
            var ctx      = new CommandHanderStreamContext
            {
                StreamId  = streamId,
                Stream    = s,
                InitEvent = new ManualResetEventSlim(false)
            };
            var t = CommandStreamLoop(ctx);

            _tasks.Add(t);
            ctx.InitEvent.Wait();
            return(streamId);
        }
Ejemplo n.º 2
0
        private void HandleCommand <T>(T command, CommandStream stream, int commandId, int streamId) where T : Command
        {
            var           t = typeof(T);
            List <object> list;

            if (!_handlers.TryGetValue(t, out list))
            {
                return;
            }

            lock (list)
            {
                for (var i = 0; i < list.Count; ++i)
                {
                    var h = (CommandHandlerDelegate <T>)list[i];
                    ThreadPool.QueueUserWorkItem((o) => h(command, streamId, new CommandAnswerContext(_stats, stream, commandId)));
                }
            }
        }
Ejemplo n.º 3
0
 internal CommandAnswerContext(CommandStats stats, CommandStream stream, int tag)
 {
     _stats  = stats;
     _stream = stream;
     _tag    = tag;
 }