Beispiel #1
0
        public override void ChannelRead(ChannelHandlerContext ctx, object msg)
        {
            try
            {
                if (!(msg is ByteBuf))
                {
                    // we know it is HTTP as we only have HTTP (for Websocket) and TCP handlers installed.
                    _log.warn("Unsupported connection type: 'HTTP'. Bolt protocol only operates over a TCP connection or WebSocket.");
                    ctx.close();
                    return;
                }
                ByteBuf buf = ( ByteBuf )msg;

                AssertEncryptedIfRequired();

                // try to fill out handshake buffer
                _handshakeBuffer.writeBytes(buf, Math.Min(buf.readableBytes(), _handshakeBuffer.writableBytes()));

                // we filled up the handshake buffer
                if (_handshakeBuffer.writableBytes() == 0)
                {
                    if (VerifyBoltPreamble())
                    {
                        // let's handshake
                        if (PerformHandshake())
                        {
                            // announce selected protocol to the client
                            ctx.writeAndFlush(ctx.alloc().buffer(4).writeInt((int)_protocol.version()));

                            // install related protocol handlers into the pipeline
                            _protocol.install();
                            ctx.pipeline().remove(this);

                            // if we somehow end up with more data in the incoming buffers, let's send them
                            // down to the pipeline for the chosen protocol handlers to handle whatever they
                            // are.
                            if (buf.readableBytes() > 0)
                            {
                                ctx.fireChannelRead(buf.readRetainedSlice(buf.readableBytes()));
                            }
                        }
                        else
                        {
                            ctx.writeAndFlush(ctx.alloc().buffer().writeBytes(new sbyte[] { 0, 0, 0, 0 })).addListener(ChannelFutureListener.CLOSE);
                        }
                    }
                    else
                    {
                        ctx.close();
                    }
                }
            }
            finally
            {
                ReferenceCountUtil.release(msg);
            }
        }
Beispiel #2
0
 public override void Close()
 {
     using (ErrorHandler errorHandler = new ErrorHandler("Closing ChunkedTransaction"))
     {
         if (_channel != null)
         {
             errorHandler.Execute(() => _channel.close());
         }
         _chunks.forEach(byteBuf => errorHandler.execute(() => ReferenceCountUtil.release(byteBuf)));
     }
 }
Beispiel #3
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public void channelRead(io.netty.channel.ChannelHandlerContext ctx, Object msg) throws Exception
        public override void ChannelRead(ChannelHandlerContext ctx, object msg)
        {
            ChannelInboundHandler @delegate = _protocol.select(_decoders);

            if (@delegate == null)
            {
                _log.warn("Unregistered handler for protocol %s", _protocol);

                /*
                 * Since we cannot process this message further we need to release the message as per netty doc
                 * see http://netty.io/wiki/reference-counted-objects.html#inbound-messages
                 */
                ReferenceCountUtil.release(msg);
                return;
            }
            @delegate.channelRead(ctx, msg);
        }
        public override void channelRead(ChannelHandlerContext ctx, Object msg)
        {
//			CodecOutputList outBuffers = CodecOutputList.newInstance();

            try
            {
                if (acceptInboundMessage(msg))
                {
                    I cast = (I)msg;

                    try
                    {
//						decode(ctx, cast, outBuffers);
                    }
                    finally
                    {
                        ReferenceCountUtil.release(cast);
                    }
                }
                else
                {
//					outBuffers.add(msg);
                }
            }
            catch (DecoderException e)
            {
                throw e;
            }
            catch (Exception e)
            {
                throw new DecoderException("channelRead", e);
            }
            finally
            {
//              int size = outBuffers.size();
//              for (int i = 0; i < size; i++)
//              {
//                  ctx.fireChannelRead(outBuffers.getUnsafe(i));
//              }
//              outBuffers.recycle();
            }
        }
 public bool release(int decrement)
 {
     return(ReferenceCountUtil.release(message, decrement));
 }
 public bool release()
 {
     return(ReferenceCountUtil.release(message));
 }