Ejemplo n.º 1
0
        public EmbeddedChannel(IChannelId id, bool hasDisconnect, bool start, params IChannelHandler[] handlers)
            : base(null, id)
        {
            this.Metadata      = hasDisconnect ? METADATA_DISCONNECT : METADATA_NO_DISCONNECT;
            this.Configuration = new DefaultChannelConfiguration(this);
            if (handlers == null)
            {
                throw new ArgumentNullException(nameof(handlers));
            }

            IChannelPipeline p = this.Pipeline;

            p.AddLast(new ActionChannelInitializer <IChannel>(channel =>
            {
                IChannelPipeline pipeline = channel.Pipeline;
                foreach (IChannelHandler h in handlers)
                {
                    if (h == null)
                    {
                        break;
                    }
                    pipeline.AddLast(h);
                }
            }));

            if (start)
            {
                this.Start();
            }
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Creates a new instance.
 /// </summary>
 /// <param name="parent">The parent of this channel. Pass <c>null</c> if there's no parent.</param>
 /// <param name="id">An <see cref="IChannelId"/> for the new channel.</param>
 protected AbstractChannel(IChannel parent, IChannelId id)
 {
     this.Parent        = parent;
     this.Id            = id;
     this.channelUnsafe = this.NewUnsafe();
     this.pipeline      = this.NewChannelPipeline();
 }
Ejemplo n.º 3
0
        public void EnsureDefaultChannelId()
        {
            TestChannel channel   = new TestChannel();
            IChannelId  channelId = channel.Id;

            Assert.True(channelId is DefaultChannelId);
        }
Ejemplo n.º 4
0
        /// <summary>
        ///     Create a new instance with the pipeline initialized with the specified handlers.
        /// </summary>
        /// <param name="id">The <see cref="IChannelId" /> of this channel.</param>
        /// <param name="handlers">
        ///     The <see cref="IChannelHandler" />s that will be added to the <see cref="IChannelPipeline" />
        /// </param>
        public EmbeddedChannel(IChannelId id, params IChannelHandler[] handlers)
            : base(null, id)
        {
            this.Configuration = new DefaultChannelConfiguration(this);
            if (handlers == null)
            {
                throw new NullReferenceException("handlers cannot be null");
            }

            IChannelPipeline p = this.Pipeline;

            p.AddLast(new ActionChannelInitializer <IChannel>(channel =>
            {
                IChannelPipeline pipeline = channel.Pipeline;
                foreach (IChannelHandler h in handlers)
                {
                    if (h == null)
                    {
                        break;
                    }
                    pipeline.AddLast(h);
                }
            }));

            Task future = this.loop.RegisterAsync(this);

            Debug.Assert(future.IsCompleted);
            p.AddLast(new LastInboundHandler(this.InboundMessages, this.RecordException));
        }
Ejemplo n.º 5
0
 public EmbeddedChannel(IChannel parent, IChannelId id, bool hasDisconnect, bool register, params IChannelHandler[] handlers)
     : base(parent, id)
 {
     Metadata      = GetMetadata(hasDisconnect);
     Configuration = new DefaultChannelConfiguration(this);
     Setup(register, handlers);
 }
Ejemplo n.º 6
0
        public IChannel Find(IChannelId id)
        {
            IChannel channel;

            this.nonServerChannels.TryGetValue(id, out channel);
            return(channel);
        }
Ejemplo n.º 7
0
        /// <summary>Create a new instance with the pipeline initialized with the specified handlers.</summary>
        /// <param name="id">The <see cref="IChannelId" /> of this channel.</param>
        /// <param name="hasDisconnect">
        ///     <c>false</c> if this <see cref="IChannel" /> will delegate <see cref="DisconnectAsync" />
        ///     to <see cref="CloseAsync" />, <c>true</c> otherwise.
        /// </param>
        /// <param name="handlers">
        ///     The <see cref="IChannelHandler" />s that will be added to the <see cref="IChannelPipeline" />
        /// </param>
        public EmbeddedChannel(IChannelId id, bool hasDisconnect, params IChannelHandler[] handlers)
            : base(null, id)
        {
            this.Metadata      = hasDisconnect ? METADATA_DISCONNECT : METADATA_NO_DISCONNECT;
            this.Configuration = new DefaultChannelConfiguration(this);
            if (handlers == null)
            {
                throw new ArgumentNullException(nameof(handlers));
            }

            IChannelPipeline p = this.Pipeline;

            p.AddLast(new ActionChannelInitializer <IChannel>(channel =>
            {
                IChannelPipeline pipeline = channel.Pipeline;
                foreach (IChannelHandler h in handlers)
                {
                    if (h == null)
                    {
                        break;
                    }
                    pipeline.AddLast(h);
                }
            }));

            Task future = this.loop.RegisterAsync(this);

            Debug.Assert(future.IsCompleted);
            p.AddLast(new LastInboundHandler(this.InboundMessages, this.RecordException));
        }
Ejemplo n.º 8
0
 /// <summary>
 /// Creates a new instance.
 ///
 //* @param parent
 //*        the parent of this channel. {@code null} if there's no parent.
 /// </summary>
 protected AbstractChannel(IChannel parent , IChannelId id)
 {
     this.Parent = parent;
     this.Id = id;
     this.channelUnsafe = this.NewUnsafe();
     this.pipeline = new DefaultChannelPipeline(this);
 }
Ejemplo n.º 9
0
 public int CompareTo(IChannelId other)
 {
     if (other is EmbeddedChannelId)
     {
         return 0;
     }
     return string.Compare(this.AsLongText(), other.AsLongText(), StringComparison.Ordinal);
 }
Ejemplo n.º 10
0
 public int CompareTo(IChannelId other)
 {
     if (other.AsShortText() == Id)
     {
         return(1);
     }
     return(0);
 }
Ejemplo n.º 11
0
 public int CompareTo(IChannelId other)
 {
     if (other is EmbeddedChannelId)
     {
         return(0);
     }
     return(string.Compare(this.AsLongText(), other.AsLongText(), StringComparison.Ordinal));
 }
Ejemplo n.º 12
0
 public int CompareTo(IChannelId other)
 {
     if (other is EmbeddedChannelId)
     {
         return 0;
     }
     return string.Compare(ToString(), other.ToString(), StringComparison.Ordinal);
 }
Ejemplo n.º 13
0
 bool IEquatable <IChannelId> .Equals(IChannelId other)
 {
     if (ReferenceEquals(this, other))
     {
         return(true);
     }
     return(other is Http2StreamChannelId streamChannelId && Equals(streamChannelId));
 }
Ejemplo n.º 14
0
 public int CompareTo(IChannelId other)
 {
     if (other is EmbeddedChannelId)
     {
         return(0);
     }
     return(string.Compare(ToString(), other.ToString(), StringComparison.Ordinal));
 }
Ejemplo n.º 15
0
        internal static bool Delete(NettyNetwork network, IChannelId channelId)
        {
            if (!NetworkConnections.TryGetValue(network.Id, out ConcurrentDictionary <IChannelId, ChannelContext> connections))
            {
                return(false);
            }

            return(connections.TryRemove(channelId, out ChannelContext value));
        }
Ejemplo n.º 16
0
 /// <summary>
 /// Creates a new instance.
 /// </summary>
 /// <param name="parent">The parent of this channel. Pass <c>null</c> if there's no parent.</param>
 /// <param name="id">An <see cref="IChannelId"/> for the new channel.</param>
 protected AbstractChannel(IChannel parent, IChannelId id)
 {
     Parent             = parent;
     Id                 = id;
     _channelUnsafe     = NewUnsafe();
     _pipeline          = NewChannelPipeline();
     _unsafeVoidPromise = new VoidChannelPromise(this, false);
     _closeFuture       = NewPromise();
 }
Ejemplo n.º 17
0
 protected AbstractChannel(IChannelId id, IChannel parent)
 {
     Contract.Requires(id != null);
     Id = id;
     Parent = parent;
     // ReSharper disable once VirtualMemberCallInContructor
     _channelUnsafe = NewUnsafe();
     _pipeline = new DefaultChannelPipeline(this);
 }
Ejemplo n.º 18
0
 protected AbstractChannel(IChannelId id, IChannel parent)
 {
     Contract.Requires(id != null);
     Id     = id;
     Parent = parent;
     // ReSharper disable once VirtualMemberCallInContructor
     _channelUnsafe = NewUnsafe();
     _pipeline      = new DefaultChannelPipeline(this);
 }
Ejemplo n.º 19
0
        public IChannel Find(IChannelId id)
        {
            var connction = this.FindConnectionInfo(id);

            if (connction != null)
            {
                return(connction.Channel);
            }
            return(default);
Ejemplo n.º 20
0
 private void AddCallContextAwaiter(IChannelId channelId, int rpcId, ICallContext callContext)
 {
     if (!CallContexts.TryGetValue(channelId, out ConcurrentDictionary <int, ICallContext> callContexts))
     {
         callContexts = new ConcurrentDictionary <int, ICallContext>();
         CallContexts.AddOrUpdate(channelId, callContexts, (k, v) => callContexts);
     }
     callContexts.AddOrUpdate(rpcId, callContext, (k, v) => callContext);
 }
Ejemplo n.º 21
0
        public EmbeddedChannel(IChannelId id, bool hasDisconnect, IChannelConfiguration config,
                               params IChannelHandler[] handlers)
            : base(null, id)
        {
            Contract.Requires(config != null);

            this.Metadata      = GetMetadata(hasDisconnect);
            this.Configuration = config;
            this.Setup(true, handlers);
        }
Ejemplo n.º 22
0
        public bool Remove(IChannelId channelId)
        {
            IChannel ch;

            if (this.nonServerChannels.TryRemove(channelId, out ch))
            {
                return(true);
            }

            return(false);
        }
Ejemplo n.º 23
0
        public EmbeddedChannel(IChannelId id, bool hasDisconnect, IChannelConfiguration config, params IChannelHandler[] handlers)
            : base(null, id)
        {
            if (config is null)
            {
                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.config);
            }

            Metadata      = GetMetadata(hasDisconnect);
            Configuration = config;
            Setup(true, handlers);
        }
Ejemplo n.º 24
0
 public IChannel Find(IChannelId id)
 {
     if (_nonServerChannels.TryGetValue(id, out IChannel channel))
     {
         return(channel);
     }
     else
     {
         _ = _serverChannels.TryGetValue(id, out channel);
         return(channel);
     }
 }
Ejemplo n.º 25
0
        internal ICallContext CreateAwaiterCallContext <TResult>(IChannelId channelId, int rpcId, Type messageType)
        {
            var callContext = new CallContext <TResult>()
            {
                MessageType = messageType,
                Tcs         = new TaskCompletionSource <TResult>(),
            };

            AddCallContextAwaiter(channelId, rpcId, callContext);

            return(callContext);
        }
Ejemplo n.º 26
0
        public void DisposeConnection(IChannelId clientID)
        {
            if (!TryGetClient(clientID, out GameClient Client))
            {
                return;
            }

            if (Client != null)
            {
                Client.Dispose();
            }

            this._clients.TryRemove(clientID, out Client);
        }
Ejemplo n.º 27
0
        public IChannel Find(IChannelId id)
        {
            IChannel channel;

            if (this.nonServerChannels.TryGetValue(id, out channel))
            {
                return(channel);
            }
            else
            {
                this.serverChannels.TryGetValue(id, out channel);
                return(channel);
            }
        }
Ejemplo n.º 28
0
        public bool Remove(IChannelId channelId)
        {
            //IChannel ch;

            if (_serverChannels.TryRemove(channelId, out _))
            {
                return(true);
            }

            if (_nonServerChannels.TryRemove(channelId, out _))
            {
                return(true);
            }

            return(false);
        }
Ejemplo n.º 29
0
 public int CompareTo(IChannelId other)
 {
     if (other is Http2StreamChannelId otherId)
     {
         int res = _parentId.CompareTo(otherId._parentId);
         if (0u >= (uint)res)
         {
             return(_id - otherId._id);
         }
         else
         {
             return(res);
         }
     }
     return(_parentId.CompareTo(other));
 }
Ejemplo n.º 30
0
 public EveryOneBut(IChannelId id)
 {
     _id = id;
 }
Ejemplo n.º 31
0
 public int CompareTo(IChannelId other) => 0;
Ejemplo n.º 32
0
 /// <summary>
 ///     Create a new instance with an empty pipeline with the specified <see cref="IChannelId" />.
 /// </summary>
 /// <param name="channelId">The <see cref="IChannelId" /> of this channel. </param>
 public EmbeddedChannel(IChannelId channelId)
     : this(channelId, EMPTY_HANDLERS)
 {
 }
Ejemplo n.º 33
0
 public EmbeddedChannel(IChannelId id, bool hasDisconnect, bool register, params IChannelHandler[] handlers)
     : this(null, id, hasDisconnect, register, handlers)
 {
 }
Ejemplo n.º 34
0
 public EmbeddedChannel(IChannelId id, params IChannelHandler[] handlers)
     : this(id, false, handlers)
 {
 }
 public EveryOneBut(IChannelId id)
 {
     this.id = id;
 }
Ejemplo n.º 36
0
 public int CompareTo(IChannelId other)
 {
     return 0;
 }