public DefaultChannelHandlerContext(DefaultChannelPipeline pipeline, IChannelHandlerInvoker invoker, string name,
     IChannelHandler handler)
     : base(pipeline, invoker, name, GetSkipPropagationFlags(handler))
 {
     Contract.Requires(handler != null);
     Handler = handler;
 }
 public DefaultChannelHandlerContext(DefaultChannelPipeline pipeline, IChannelHandlerInvoker invoker, string name,
                                     IChannelHandler handler)
     : base(pipeline, invoker, name, GetSkipPropagationFlags(handler))
 {
     Contract.Requires(handler != null);
     Handler = handler;
 }
Ejemplo n.º 3
0
 public IChannelPipeline AddLast(IChannelHandlerInvoker invoker, params IChannelHandler[] handlers)
 {
     foreach (IChannelHandler h in handlers)
     {
         this.AddLast(invoker, (string)null, h);
     }
     return(this);
 }
Ejemplo n.º 4
0
 public IChannelPipeline AddLast(IChannelHandlerInvoker invoker, params IChannelHandler[] handlers)
 {
     Contract.Requires(handlers != null);
     foreach (var handler in handlers)
     {
         AddLast(invoker, (string)null, handler);
     }
     return(this);
 }
Ejemplo n.º 5
0
 public IChannelPipeline AddAfter(IChannelHandlerInvoker invoker, string baseName, string name, IChannelHandler handler)
 {
     lock (this.head)
     {
         AbstractChannelHandlerContext ctx = this.GetContextOrThrow(baseName);
         name = this.FilterName(name, handler);
         this.AddAfterUnsafe(name, ctx, new DefaultChannelHandlerContext(this, invoker, name, handler));
     }
     return(this);
 }
Ejemplo n.º 6
0
 public IChannelPipeline AddBefore(IChannelHandlerInvoker invoker, string baseName, string name,
                                   IChannelHandler handler)
 {
     lock (_head)
     {
         var ctx = GetContextOrThrow(baseName);
         name = FilterName(name, handler);
         AddBeforeUnsafe(name, ctx, new DefaultChannelHandlerContext(this, invoker, name, handler));
     }
     return(this);
 }
Ejemplo n.º 7
0
 IEventExecutor ExecutorSafe(IChannelHandlerInvoker invoker)
 {
     if (invoker == null)
     {
         // We check for channel().isRegistered and handlerAdded because even if isRegistered() is false we
         // can safely access the invoker() if handlerAdded is true. This is because in this case the Channel
         // was previously registered and so we can still access the old EventLoop to dispatch things.
         return(this.channel.Registered || this.registered ? this.channel.EventLoop : null);
     }
     return(invoker.Executor);
 }
        protected AbstractChannelHandlerContext(IChannelPipeline pipeline, IChannelHandlerInvoker invoker,
                                                string name, PropagationDirections skipPropagationDirections)
        {
            Contract.Requires(pipeline != null);
            Contract.Requires(name != null);

            this.Channel = pipeline.Channel();
            this.invoker = invoker;
            this.skipPropagationFlags = skipPropagationDirections;
            this.Name = name;
        }
        protected AbstractChannelHandlerContext(DefaultChannelPipeline pipeline, IChannelHandlerInvoker invoker,
                                                string name, int skipPropagationDirections)
        {
            Contract.Requires(pipeline != null);
            Contract.Requires(name != null);

            this.pipeline             = pipeline;
            this.Name                 = name;
            this.invoker              = invoker;
            this.SkipPropagationFlags = skipPropagationDirections;
        }
        protected AbstractChannelHandlerContext(IChannelPipeline pipeline, IChannelHandlerInvoker invoker,
            string name, PropagationDirections skipPropagationDirections)
        {
            Contract.Requires(pipeline != null);
            Contract.Requires(name != null);

            this.Channel = pipeline.Channel();
            this.invoker = invoker;
            this.skipPropagationFlags = skipPropagationDirections;
            this.Name = name;
        }
Ejemplo n.º 11
0
        public IChannelPipeline AddFirst(IChannelHandlerInvoker invoker, params IChannelHandler[] handlers)
        {
            Contract.Requires(handlers != null);

            for (int i = handlers.Length - 1; i >= 0; i--)
            {
                IChannelHandler h = handlers[i];
                this.AddFirst(invoker, (string)null, h);
            }

            return(this);
        }
Ejemplo n.º 12
0
        public IChannelPipeline AddBefore(IChannelHandlerInvoker invoker, string baseName, string name, IChannelHandler handler)
        {
            IEventExecutor executor;
            AbstractChannelHandlerContext newCtx;
            AbstractChannelHandlerContext ctx;
            bool inEventLoop;

            lock (this)
            {
                CheckMultiplicity(handler);
                ctx = this.GetContextOrThrow(baseName);

                newCtx   = new DefaultChannelHandlerContext(this, invoker, this.FilterName(name, handler), handler);
                executor = this.ExecutorSafe(invoker);

                // If the executor is null it means that the channel was not registered on an eventloop yet.
                // In this case we add the context to the pipeline and add a task that will call
                // ChannelHandler.handlerAdded(...) once the channel is registered.
                if (executor == null)
                {
                    AddBefore0(ctx, newCtx);
                    this.CallHandlerCallbackLater(newCtx, true);
                    return(this);
                }

                inEventLoop = executor.InEventLoop;
                if (inEventLoop)
                {
                    AddBefore0(ctx, newCtx);
                }
            }

            if (inEventLoop)
            {
                this.CallHandlerAdded0(newCtx);
            }
            else
            {
                executor.SubmitAsync(() =>
                {
                    lock (this)
                    {
                        AddBefore0(ctx, newCtx);
                    }
                    this.CallHandlerAdded0(newCtx);
                    return(0);
                }).Wait();
            }
            return(this);
        }
Ejemplo n.º 13
0
        public IChannelPipeline AddLast(IChannelHandlerInvoker invoker, string name, IChannelHandler handler)
        {
            Contract.Requires(handler != null);
            lock (_head)
            {
                name = FilterName(name, handler);
                var newContext = new DefaultChannelHandlerContext(this, invoker, name, handler);

                var prev = _tail.Prev;
                newContext.Prev = prev;
                newContext.Next = _tail;
                prev.Next       = newContext;
                _tail.Prev      = newContext;

                _nameContextMap.Add(name, newContext);
                CallHandlerAdded(newContext);
            }
            return(this);
        }
Ejemplo n.º 14
0
        public IChannelPipeline AddFirst(IChannelHandlerInvoker invoker, string name, IChannelHandler handler)
        {
            Contract.Requires(handler != null);

            lock (this.head)
            {
                name = this.FilterName(name, handler);
                var newCtx = new DefaultChannelHandlerContext(this, invoker, name, handler);
                CheckMultiplicity(newCtx);

                AbstractChannelHandlerContext nextCtx = this.head.Next;
                newCtx.Prev    = this.head;
                newCtx.Next    = nextCtx;
                this.head.Next = newCtx;
                nextCtx.Prev   = newCtx;

                this.nameContextMap.Add(name, newCtx);

                this.CallHandlerAdded(newCtx);
            }
            return(this);
        }
        protected AbstractChannelHandlerContext(DefaultChannelPipeline pipeline, IChannelHandlerInvoker invoker,
            string name,
            int skipPropagationFlags)
        {
            Contract.Requires(pipeline != null);
            Contract.Requires(name != null);

            Pipeline = pipeline;
            _invoker = invoker;
            Name = name;
            SkipPropagationFlags = skipPropagationFlags;
        }