Example usage for io.netty.channel ChannelHandlerContext flush

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

Introduction

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

Prototype

@Override
    ChannelHandlerContext flush();

Source Link

Usage

From source file:com.linecorp.armeria.internal.Http1ObjectEncoder.java

License:Apache License

private ChannelFuture doWriteSplitData(ChannelHandlerContext ctx, int id, HttpData data, boolean endStream) {

    try {/*from   ww w  .  j  a v  a  2 s.  c o  m*/
        int offset = data.offset();
        int remaining = data.length();
        ChannelFuture lastFuture;
        for (;;) {
            // Ensure an HttpContent does not exceed the maximum length of a cleartext TLS record.
            final int chunkSize = Math.min(MAX_TLS_DATA_LENGTH, remaining);
            lastFuture = write(ctx, id, new DefaultHttpContent(dataChunk(data, offset, chunkSize)), false);
            remaining -= chunkSize;
            if (remaining == 0) {
                break;
            }
            offset += chunkSize;
        }

        if (endStream) {
            lastFuture = write(ctx, id, LastHttpContent.EMPTY_LAST_CONTENT, true);
        }

        ctx.flush();
        return lastFuture;
    } finally {
        ReferenceCountUtil.safeRelease(data);
    }
}

From source file:com.linecorp.armeria.server.http.HttpServerHandler.java

License:Apache License

private void respond(ChannelHandlerContext ctx, DecodedHttpRequest req, AggregatedHttpMessage res) {
    if (!handledLastRequest) {
        addKeepAliveHeaders(req, res);//from  w ww. ja v  a2s  . c  o  m
        write(ctx, req, res).addListener(CLOSE_ON_FAILURE);
    } else {
        // Note that it is perfectly fine not to set the 'content-length' header to the last response
        // of an HTTP/1 connection. We set it anyway to work around overly strict HTTP clients that always
        // require a 'content-length' header for non-chunked responses.
        setContentLength(req, res);
        write(ctx, req, res).addListener(CLOSE);
    }

    if (!isReading) {
        ctx.flush();
    }
}

From source file:com.linecorp.armeria.server.http.HttpServerHandler.java

License:Apache License

@Override
public void channelReadComplete(ChannelHandlerContext ctx) throws Exception {
    isReading = false;
    ctx.flush();
}

From source file:com.linecorp.armeria.server.HttpServerHandler.java

License:Apache License

private void respond(ChannelHandlerContext ctx, DecodedHttpRequest req, AggregatedHttpMessage res,
        RequestContext reqCtx, @Nullable Throwable cause) {
    if (!handledLastRequest) {
        addKeepAliveHeaders(req, res);//  w  w w  .j a  va  2 s.c o  m
        respond0(ctx, req, res, reqCtx, cause).addListener(CLOSE_ON_FAILURE);
    } else {
        // Note that it is perfectly fine not to set the 'content-length' header to the last response
        // of an HTTP/1 connection. We set it anyway to work around overly strict HTTP clients that always
        // require a 'content-length' header for non-chunked responses.
        setContentLength(req, res);
        respond0(ctx, req, res, reqCtx, cause).addListener(CLOSE);
    }

    if (!isReading) {
        ctx.flush();
    }
}

From source file:com.linkedin.r2.transport.http.client.Http2AlpnHandler.java

License:Apache License

@Override
public void flush(final ChannelHandlerContext ctx) throws Exception {
    _alpnPromise.addListener(f -> {/*  ww w .java  2 s . c o  m*/
        ChannelFuture future = (ChannelFuture) f;
        if (future.isSuccess()) {
            ctx.flush();
        }
    });
}

From source file:com.linkedin.r2.transport.http.client.Http2UpgradeHandler.java

License:Apache License

@Override
public void flush(ChannelHandlerContext ctx) throws Exception {
    _upgradePromise.addListener(f -> {
        ChannelFuture future = (ChannelFuture) f;
        if (future.isSuccess()) {
            ctx.flush();
        }/*  www .  j a  v  a 2s. co m*/
    });
}

From source file:com.linkedin.r2.transport.http.client.RAPRequestEncoder.java

License:Apache License

@Override
public void flush(ChannelHandlerContext ctx) throws Exception {
    if (_currentReader != null) {
        _currentReader.flush();/* w  w w. j  a v a  2s  . c om*/
    } else {
        ctx.flush();
    }
}

From source file:com.linkedin.r2.transport.http.client.SslRequestHandler.java

License:Apache License

@Override
public void flush(final ChannelHandlerContext ctx) throws Exception {
    if (_firstTimeScheme == null) {
        throw new IllegalStateException(
                "Flush is called before any request has been written into this channel!");
    }//from   ww  w  .j  a v  a2 s .c  o m
    if (_firstTimeScheme.equalsIgnoreCase(HTTPS_SCHEME)) {
        // make sure we don't call ctx#flush() immediately when the handshake is in progress.
        _sslHandler.handshakeFuture().addListener(new FutureListener<Channel>() {
            @Override
            public void operationComplete(Future<Channel> future) throws Exception {
                ctx.flush();
            }
        });
    } else {
        ctx.flush();
    }
}

From source file:com.mapr.franz.netty.FranzClientHandler.java

License:Apache License

@Override
public void inboundBufferUpdated(ChannelHandlerContext ctx, ByteBuf in) {
    ByteBuf out = ctx.nextOutboundByteBuffer();
    out.discardReadBytes();//  www  .  j ava2  s . co m
    out.writeBytes(in);
    ctx.flush();
}

From source file:com.miko.s4netty.handler.WorkerProviderHandler.java

License:Open Source License

@Override
public void channelReadComplete(ChannelHandlerContext ctx) {
    logger.debug("channelReadComplete ctx= " + ctx);
    ctx.flush();
}