Example usage for io.netty.channel ChannelHandlerContext read

List of usage examples for io.netty.channel ChannelHandlerContext read

Introduction

In this page you can find the example usage for io.netty.channel ChannelHandlerContext read.

Prototype

@Override
    ChannelHandlerContext read();

Source Link

Usage

From source file:org.apache.hyracks.http.server.HttpRequestCapacityController.java

License:Apache License

@Override
public void channelReadComplete(ChannelHandlerContext ctx) throws Exception {
    ctx.read();
    super.channelReadComplete(ctx);
}

From source file:org.apache.qpid.proton.netty.ProtonNettyHandler.java

License:Apache License

@Override
public void channelActive(ChannelHandlerContext ctx) {
    synchronized (lock) {
        System.out.println("ACTIVE");
        transport = Transport.Factory.create();
        transport.setContext(ctx);//from w  w w  .j  av  a2  s. c o  m

        Sasl sasl = transport.sasl();
        sasl.setMechanisms("ANONYMOUS");
        sasl.server();
        sasl.done(Sasl.PN_SASL_OK);

        connection = Connection.Factory.create();
        collector = Collector.Factory.create();
        connection.collect(collector);
        transport.bind(connection);

        // XXX: really we should fire both of these off of an
        //      initial transport event
        write(ctx);
        int capacity = transport.capacity();
        if (capacity > 0) {
            ctx.read();
        }
    }
}

From source file:org.apache.qpid.proton.netty.ProtonNettyHandler.java

License:Apache License

@Override
public void channelRead(final ChannelHandlerContext ctx, Object msg) {
    synchronized (lock) {
        ByteBuf buf = (ByteBuf) msg;// w  ww .  j  av  a 2s.c om
        try {
            while (buf.readableBytes() > 0) {
                int capacity = transport.capacity();
                if (capacity <= 0) {
                    throw new IllegalStateException("discarding bytes: " + buf.readableBytes());
                }
                ByteBuffer tail = transport.tail();
                int min = Math.min(capacity, buf.readableBytes());
                tail.limit(tail.position() + min);
                buf.readBytes(tail);
                transport.process();
                dispatch();
            }
        } finally {
            buf.release();
        }

        int capacity = transport.capacity();
        if (capacity > 0) {
            ctx.read();
        }
    }
}

From source file:org.asynchttpclient.netty.handler.AsyncHttpClientHandler.java

License:Open Source License

@Override
public void channelRead(final ChannelHandlerContext ctx, Object msg) throws Exception {

    Channel channel = ctx.channel();
    Object attribute = Channels.getAttribute(channel);

    try {//from  w w  w  .ja v  a  2 s. co m
        if (attribute instanceof Callback) {
            Callback ac = (Callback) attribute;
            if (msg instanceof LastHttpContent) {
                ac.call();
            } else if (!(msg instanceof HttpContent)) {
                logger.info("Received unexpected message while expecting a chunk: " + msg);
                ac.call();
                Channels.setDiscard(channel);
            }

        } else if (attribute instanceof NettyResponseFuture) {
            NettyResponseFuture<?> future = (NettyResponseFuture<?>) attribute;
            handleRead(channel, future, msg);

        } else if (attribute instanceof StreamedResponsePublisher) {

            StreamedResponsePublisher publisher = (StreamedResponsePublisher) attribute;

            if (msg instanceof HttpContent) {
                ByteBuf content = ((HttpContent) msg).content();
                // Republish as a HttpResponseBodyPart
                if (content.readableBytes() > 0) {
                    HttpResponseBodyPart part = config.getResponseBodyPartFactory().newResponseBodyPart(content,
                            false);
                    ctx.fireChannelRead(part);
                }
                if (msg instanceof LastHttpContent) {
                    // Remove the handler from the pipeline, this will trigger
                    // it to finish
                    ctx.pipeline().remove(publisher);
                    // Trigger a read, just in case the last read complete
                    // triggered no new read
                    ctx.read();
                    // Send the last content on to the protocol, so that it can
                    // conclude the cleanup
                    handleRead(channel, publisher.future(), msg);
                }
            } else {
                logger.info("Received unexpected message while expecting a chunk: " + msg);
                ctx.pipeline().remove(publisher);
                Channels.setDiscard(channel);
            }
        } else if (attribute != DiscardEvent.INSTANCE) {
            // unhandled message
            logger.debug("Orphan channel {} with attribute {} received message {}, closing", channel, attribute,
                    msg);
            Channels.silentlyCloseChannel(channel);
        }
    } finally {
        ReferenceCountUtil.release(msg);
    }
}

From source file:org.asynchttpclient.netty.handler.AsyncHttpClientHandler.java

License:Open Source License

@Override
public void channelReadComplete(ChannelHandlerContext ctx) throws Exception {
    if (!isHandledByReactiveStreams(ctx)) {
        ctx.read();
    } else {/*  www  . j  a  v  a  2 s . c om*/
        ctx.fireChannelReadComplete();
    }
}

From source file:org.kobeyoung81.dummyhttpproxy.HexDumpProxyBackendHandler.java

License:Apache License

@Override
public void channelActive(ChannelHandlerContext ctx) {
    ctx.read();
    //ctx.write(Unpooled.EMPTY_BUFFER);
}

From source file:org.opencloudb.net.mysql.FrontendAuthenticator.java

License:Open Source License

protected void success(ChannelHandlerContext ctx, AuthPacket auth) {
    ConnectionInfo conInf = NettyUtil.getConnectionInfo(ctx);
    conInf.setUser(auth.user);//  w w w. ja v a  2 s  .  c om
    conInf.setSchema(auth.database);
    conInf.setCharsetIndex(auth.charsetIndex);
    // conInf.setHandler(new FrontendCommandHandler(source));
    if (LOGGER.isInfoEnabled()) {
        StringBuilder s = new StringBuilder();
        s.append(ctx.channel()).append('\'').append(auth.user).append("' login success");
        byte[] extra = auth.extra;
        if (extra != null && extra.length > 0) {
            s.append(",extra:").append(new String(extra));
        }
        LOGGER.info(s.toString());
    }

    ctx.writeAndFlush(ctx.alloc().ioBuffer(AUTH_OK.length).writeBytes(AUTH_OK));
    FrontSession session = new FrontSession(ctx,
            MycatSystem.getInstance().getPrivileges().isReadOnly(conInf.getUser()), conInf);
    NettyUtil.removeConnectionInfo(ctx);
    NettyUtil.updateFrontSession(ctx, session);
    // to query hanlder
    NettyUtil.setConnectionHandler(ctx, FrontendCommandHandler.INSTANCE);
    ctx.read();
}

From source file:org.opendaylight.controller.netconf.nettyutil.handler.ssh.virtualsocket.ChannelOutputStream.java

License:Open Source License

public void read(ChannelHandlerContext ctx) {
    ctx.read();
}

From source file:org.opendaylight.controller.netconf.util.handler.NetconfEOMAggregator.java

License:Open Source License

@Override
protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {
    int index = indexOfSequence(in, NetconfMessageConstants.END_OF_MESSAGE);
    if (index == -1) {
        logger.debug("Message is not complete, read again.");
        if (logger.isTraceEnabled()) {
            String str = in.toString(Charsets.UTF_8);
            logger.trace("Message read so far: {}", str);
        }/*from  w  w  w.j  a va2  s  .  co  m*/
        ctx.read();
    } else {
        ByteBuf msg = in.readBytes(index);
        in.readBytes(NetconfMessageConstants.END_OF_MESSAGE.length);
        in.discardReadBytes();
        logger.debug("Message is complete.");
        out.add(msg);
    }
}

From source file:org.opendaylight.controller.netconf.util.handler.NetconfMessageAggregator.java

License:Open Source License

@Override
protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {
    int index = indexOfSequence(in, eom);
    if (index == -1) {
        logger.debug("Message is not complete, read again.");
        ctx.read();
    } else {//from   www  .  j a  v  a  2 s. c  om
        ByteBuf msg = in.readBytes(index);
        in.readBytes(eom.length);
        in.discardReadBytes();
        logger.debug("Message is complete.");
        out.add(msg);
    }
}