示例#1
0
            public override void channelRead(ChannelHandlerContext ctx, Object msg)
            {
                Channel child = (Channel)msg;

                child.pipeline().addLast(childHandler);
                childGroup.register(child);
            }
示例#2
0
 protected internal override void decode(ChannelHandlerContext ctx, ByteBuf @in, IList <object> @out)
 {
     if (@in.readableBytes() > 0)
     {
         throw new System.InvalidOperationException("Not expecting any data here");
     }
 }
示例#3
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: protected void encode(io.netty.channel.ChannelHandlerContext ctx, org.neo4j.causalclustering.core.consensus.RaftMessages_ClusterIdAwareMessage msg, java.util.List<Object> out) throws Exception
        protected internal override void Encode(ChannelHandlerContext ctx, Org.Neo4j.causalclustering.core.consensus.RaftMessages_ClusterIdAwareMessage msg, IList <object> @out)
        {
            @out.Add(msg);
            Handler replicatedContentHandler = new Handler(this, @out, ctx.alloc());

            msg.message().dispatch(replicatedContentHandler);
        }
示例#4
0
        /// <exception cref="System.Exception"/>
        public override void MessageReceived(ChannelHandlerContext ctx, MessageEvent e)
        {
            RpcInfo  info          = (RpcInfo)e.GetMessage();
            RpcCall  call          = (RpcCall)info.Header();
            EndPoint remoteAddress = info.RemoteAddress();

            if (Log.IsTraceEnabled())
            {
                Log.Trace(program + " procedure #" + call.GetProcedure());
            }
            if (this.progNumber != call.GetProgram())
            {
                Log.Warn("Invalid RPC call program " + call.GetProgram());
                SendAcceptedReply(call, remoteAddress, RpcAcceptedReply.AcceptState.ProgUnavail,
                                  ctx);
                return;
            }
            int ver = call.GetVersion();

            if (ver < lowProgVersion || ver > highProgVersion)
            {
                Log.Warn("Invalid RPC call version " + ver);
                SendAcceptedReply(call, remoteAddress, RpcAcceptedReply.AcceptState.ProgMismatch,
                                  ctx);
                return;
            }
            HandleInternal(ctx, info);
        }
示例#5
0
        /// <summary>
        /// .NET-specific decoding handler for incoming UDP messages.
        /// </summary>
        public override void Read(ChannelHandlerContext ctx, object msg)
        {
            var dgram = msg as DatagramPacket;

            if (dgram == null)
            {
                ctx.FireRead(msg);
                return;
            }

            var buf       = dgram.Content;
            var sender    = dgram.Sender;
            var recipient = dgram.Recipient;

            try
            {
                var  decoder  = new Decoder(_signatureFactory);
                bool finished = decoder.Decode(ctx, buf, recipient, sender);
                if (finished)
                {
                    // prepare finish
                    ctx.FireRead(decoder.PrepareFinish());
                }
                else
                {
                    Logger.Warn("Did not get the complete packet!");
                }
            }
            catch (Exception ex)
            {
                Logger.Error("Error in UDP decoding.", ex);
                throw;
            }
        }
示例#6
0
        public override void ExceptionCaught(ChannelHandlerContext ctx, Exception cause)
        {
            if (_failed || IsShuttingDown(ctx))
            {
                return;
            }
            _failed = true;               // log only the first exception to not pollute the log

            try
            {
                // Netty throws a NativeIoException on connection reset - directly importing that class
                // caused a host of linking errors, because it depends on JNI to work. Hence, we just
                // test on the message we know we'll get.
                if (Exceptions.contains(cause, e => e.Message.contains("Connection reset by peer")))
                {
                    _log.warn("Fatal error occurred when handling a client connection, " + "remote peer unexpectedly closed connection: %s", ctx.channel());
                }
                else
                {
                    _log.error("Fatal error occurred when handling a client connection: " + ctx.channel(), cause);
                }
            }
            finally
            {
                ctx.close();
            }
        }
示例#7
0
            public override void MessageReceived(ChannelHandlerContext ctx, MessageEvent e)
            {
                ChannelBuffer buf = (ChannelBuffer)e.GetMessage();

                // Read reply
                if (!ValidMessageLength(buf.ReadableBytes()))
                {
                    e.GetChannel().Close();
                    return;
                }
                // handling fragment header for TCP, 4 bytes.
                byte[] fragmentHeader = Arrays.CopyOfRange(buf.Array(), 0, 4);
                int    fragmentSize   = XDR.FragmentSize(fragmentHeader);
                bool   isLast         = XDR.IsLastFragment(fragmentHeader);

                System.Diagnostics.Debug.Assert((fragmentSize == 28 && isLast == true));
                XDR xdr = new XDR();

                xdr.WriteFixedOpaque(Arrays.CopyOfRange(buf.Array(), 4, buf.ReadableBytes()));
                RpcReply reply = RpcReply.Read(xdr);

                if (reply.GetState() == RpcReply.ReplyState.MsgAccepted)
                {
                    RpcAcceptedReply acceptedReply = (RpcAcceptedReply)reply;
                    Handle(acceptedReply, xdr);
                }
                else
                {
                    RpcDeniedReply deniedReply = (RpcDeniedReply)reply;
                    Handle(deniedReply);
                }
                e.GetChannel().Close();
            }
示例#8
0
 protected internal override void Decode(ChannelHandlerContext ctx, object msg, IList <object> @out)
 {
     if (msg is ReplicatedContent)
     {
         _replicatedContents.AddLast(( ReplicatedContent )msg);
     }
     else if (msg is RaftLogEntryTermsDecoder.RaftLogEntryTerms)
     {
         foreach (long term in ((RaftLogEntryTermsDecoder.RaftLogEntryTerms)msg).Terms())
         {
             _raftLogEntryTerms.AddLast(term);
         }
     }
     else if (msg is RaftMessageDecoder.ClusterIdAwareMessageComposer)
     {
         if (_messageComposer != null)
         {
             throw new System.InvalidOperationException("Received raft message header. Pipeline already contains message header waiting to build.");
         }
         _messageComposer = (RaftMessageDecoder.ClusterIdAwareMessageComposer)msg;
     }
     else
     {
         throw new System.InvalidOperationException("Unexpected object in the pipeline: " + msg);
     }
     if (_messageComposer != null)
     {
         Optional <Org.Neo4j.causalclustering.core.consensus.RaftMessages_ClusterIdAwareMessage> clusterIdAwareMessage = _messageComposer.maybeCompose(_clock, _raftLogEntryTerms, _replicatedContents);
         clusterIdAwareMessage.ifPresent(message =>
         {
             Clear(message);
             @out.Add(message);
         });
     }
 }
示例#9
0
        public override void channelRead(ChannelHandlerContext ctx, Object msg)
        {
            bool release = true;

            try
            {
                if (acceptInboundMessage(msg))
                {
                    I imsg = (I)msg;
                    channelRead0(ctx, imsg);
                }
                else
                {
                    release = false;
                    ctx.fireChannelRead(msg);
                }
            }
            finally
            {
                if (autoRelease && release)
                {
//					ReferenceCountUtil.release(msg);
                }
            }
        }
示例#10
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: protected void decode(io.netty.channel.ChannelHandlerContext ctx, io.netty.buffer.ByteBuf msg, java.util.List<Object> out) throws Exception
        protected internal override void Decode(ChannelHandlerContext ctx, ByteBuf msg, IList <object> @out)
        {
            long    txId    = msg.readLong();
            StoreId storeId = StoreIdMarshal.INSTANCE.unmarshal(new NetworkReadableClosableChannelNetty4(msg));

            @out.Add(new TxPullRequest(txId, storeId));
        }
示例#11
0
			/// <exception cref="System.Exception"/>
			public override void ExceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e)
			{
				Org.Jboss.Netty.Channel.Channel ch = e.GetChannel();
				Exception cause = e.GetCause();
				if (cause is TooLongFrameException)
				{
					this.SendError(ctx, HttpResponseStatus.BadRequest);
					return;
				}
				else
				{
					if (cause is IOException)
					{
						if (cause is ClosedChannelException)
						{
							ShuffleHandler.Log.Debug("Ignoring closed channel error", cause);
							return;
						}
						string message = cause.Message.ToString();
						if (ShuffleHandler.IgnorableErrorMessage.Matcher(message).Matches())
						{
							ShuffleHandler.Log.Debug("Ignoring client socket close", cause);
							return;
						}
					}
				}
				ShuffleHandler.Log.Error("Shuffle error: ", cause);
				if (ch.IsConnected())
				{
					ShuffleHandler.Log.Error("Shuffle error " + e);
					this.SendError(ctx, HttpResponseStatus.InternalServerError);
				}
			}
示例#12
0
        /// <exception cref="System.Exception"/>
        public override void ExceptionCaught(ChannelHandlerContext ctx, Exception cause)
        {
            Exception e       = cause is Exception ? (Exception)cause : new Exception(cause);
            string    output  = JsonUtil.ToJsonString(e);
            ByteBuf   content = Unpooled.WrappedBuffer(Sharpen.Runtime.GetBytesForString(output
                                                                                         , Charsets.Utf8));
            DefaultFullHttpResponse resp = new DefaultFullHttpResponse(HttpVersion.Http11, HttpResponseStatus
                                                                       .InternalServerError, content);

            resp.Headers().Set(HttpHeaders.Names.ContentType, WebHdfsHandler.ApplicationJsonUtf8
                               );
            if (e is ArgumentException)
            {
                resp.SetStatus(HttpResponseStatus.BadRequest);
            }
            else
            {
                if (e is FileNotFoundException)
                {
                    resp.SetStatus(HttpResponseStatus.NotFound);
                }
            }
            resp.Headers().Set(HttpHeaders.Names.ContentLength, resp.Content().ReadableBytes(
                                   ));
            resp.Headers().Set(HttpHeaders.Names.Connection, HttpHeaders.Values.Close);
            ctx.Write(resp).AddListener(ChannelFutureListener.Close);
        }
示例#13
0
 /// <exception cref="System.Exception"/>
 public override void ChannelIdle(ChannelHandlerContext ctx, IdleStateEvent e)
 {
     if (e.GetState() == IdleState.AllIdle)
     {
         e.GetChannel().Close();
     }
 }
        protected internal override void Decode(ChannelHandlerContext ctx, ByteBuf @in, IList <object> @out)
        {
            // Will use the first five bytes to detect a protocol.
            if (@in.readableBytes() < 5)
            {
                return;
            }

            if (DetectSsl(@in))
            {
                EnableSsl(ctx);
            }
            else if (IsHttp(@in))
            {
                SwitchToWebsocket(ctx);
            }
            else if (IsBoltPreamble(@in))
            {
                SwitchToSocket(ctx);
            }
            else
            {
                // TODO: send a alert_message for a ssl connection to terminate the handshake
                @in.clear();
                ctx.close();
            }
        }
        private void SwitchToWebsocket(ChannelHandlerContext ctx)
        {
            ChannelPipeline p = ctx.pipeline();

            p.addLast(new HttpServerCodec(), new HttpObjectAggregator(MAX_WEBSOCKET_HANDSHAKE_SIZE), new WebSocketServerProtocolHandler("/", null, false, MAX_WEBSOCKET_FRAME_SIZE), new WebSocketFrameAggregator(MAX_WEBSOCKET_FRAME_SIZE), new WebSocketFrameTranslator(), NewHandshaker());
            p.remove(this);
        }
        private void SwitchToSocket(ChannelHandlerContext ctx)
        {
            ChannelPipeline p = ctx.pipeline();

            p.addLast(NewHandshaker());
            p.remove(this);
        }
示例#17
0
 public override void channelInactive(ChannelHandlerContext ctx)
 {
     if (_outerInstance.closeHandler != null)
     {
         _outerInstance.closeHandler.run();
     }
     ctx.fireChannelInactive();
 }
 public override void ChannelInactive(ChannelHandlerContext ctx)
 {
     if (proxiedChannel != null)
     {
         proxiedChannel.Close();
         proxiedChannel = null;
     }
 }
示例#19
0
        protected internal override void Decode(ChannelHandlerContext ctx, ByteBuf msg, IList <object> @out)
        {
            int           ordinal    = msg.readInt();
            long          latestTxid = msg.readLong();
            CatchupResult status     = Enum.GetValues(typeof(CatchupResult))[ordinal];

            @out.Add(new TxStreamFinishedResponse(status, latestTxid));
        }
示例#20
0
 public RpcInfo(RpcMessage header, ChannelBuffer data, ChannelHandlerContext channelContext
                , Org.Jboss.Netty.Channel.Channel channel, EndPoint remoteAddress)
 {
     this.header        = header;
     this.data          = data;
     this.channel       = channel;
     this.remoteAddress = remoteAddress;
 }
        private void EnableSsl(ChannelHandlerContext ctx)
        {
            ChannelPipeline p = ctx.pipeline();

            p.addLast(_sslCtx.newHandler(ctx.alloc()));
            p.addLast(new TransportSelectionHandler(_boltChannel, null, _encryptionRequired, true, _logging, _boltProtocolFactory));
            p.remove(this);
        }
示例#22
0
        public override void ExceptionCaught(ChannelHandlerContext ctx, Exception cause)
        {
            ReleaseDfsResources();
            DefaultHttpResponse resp = ExceptionHandler.ExceptionCaught(cause);

            resp.Headers().Set(HttpHeaders.Names.Connection, HttpHeaders.Values.Close);
            ctx.WriteAndFlush(response).AddListener(ChannelFutureListener.Close);
        }
 public _ChannelFutureListener_115(SimpleHttpProxyHandler _enclosing, ChannelHandlerContext
                                   ctx, HttpRequest req, IO.Netty.Channel.Channel client)
 {
     this._enclosing = _enclosing;
     this.ctx        = ctx;
     this.req        = req;
     this.client     = client;
 }
        private static ChannelHandlerContext ChannelHandlerContextMock()
        {
            Channel channel = mock(typeof(Channel));
            ChannelHandlerContext context = mock(typeof(ChannelHandlerContext));

            when(context.channel()).thenReturn(channel);
            return(context);
        }
示例#25
0
 public override void channelActive(ChannelHandlerContext ctx)
 {
     // This method will be invoked only if this handler was added
     // before channelActive() event is fired.  If a user adds this handler
     // after the channelActive() event, initialize() will be called by beforeAdd().
     initialize(ctx);
     base.channelActive(ctx);
 }
示例#26
0
 public override void channelReadComplete(ChannelHandlerContext ctx)
 {
     if ((readerIdleTimeNanos > 0 || allIdleTimeNanos > 0) && reading)
     {
         lastReadTime = ticksInNanos();
         reading      = false;
     }
     ctx.fireChannelReadComplete();
 }
示例#27
0
 public override void channelRead(ChannelHandlerContext ctx, Object msg)
 {
     if (readerIdleTimeNanos > 0 || allIdleTimeNanos > 0)
     {
         reading = true;
         firstReaderIdleEvent = firstAllIdleEvent = true;
     }
     ctx.fireChannelRead(msg);
 }
示例#28
0
 public override void channelRegistered(ChannelHandlerContext ctx)
 {
     // Initialize early if channel is active already.
     if (ctx.channel().isActive())
     {
         initialize(ctx);
     }
     base.channelRegistered(ctx);
 }
示例#29
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public void writeComplete(org.jboss.netty.channel.ChannelHandlerContext ctx, org.jboss.netty.channel.WriteCompletionEvent e) throws Exception
            public override void WriteComplete(ChannelHandlerContext ctx, WriteCompletionEvent e)
            {
                if (LastException != null)
                {
                    outerInstance.msgLog.Error("Recovered from:", LastException);
                    LastException = null;
                }
                base.WriteComplete(ctx, e);
            }
示例#30
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public void channelDisconnected(org.jboss.netty.channel.ChannelHandlerContext ctx, org.jboss.netty.channel.ChannelStateEvent e) throws Exception
        public override void ChannelDisconnected(ChannelHandlerContext ctx, ChannelStateEvent e)
        {
            base.ChannelDisconnected(ctx, e);

            if (!ctx.Channel.Connected)
            {
                TryToCloseChannel(ctx.Channel);
            }
        }
示例#31
0
 public virtual void Read(ChannelHandlerContext ctx, object msg)
 {
     // do nothing by default
     // can be overridden
 }
示例#32
0
 public virtual void UserEventTriggered(ChannelHandlerContext ctx, object evt)
 {
     // do nothing by default
     // can be overridden
 }