Example usage for io.netty.channel ChannelPipeline last

List of usage examples for io.netty.channel ChannelPipeline last

Introduction

In this page you can find the example usage for io.netty.channel ChannelPipeline last.

Prototype

ChannelHandler last();

Source Link

Document

Returns the last ChannelHandler in this pipeline.

Usage

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

License:Apache License

static HttpServer get(Channel channel) {
    final ChannelPipeline p = channel.pipeline();
    final ChannelHandler lastHandler = p.last();
    if (lastHandler instanceof HttpServer) {
        return (HttpServer) lastHandler;
    }/*  w w  w .  j  a v a 2s. c o  m*/

    for (ChannelHandler h : p.toMap().values()) {
        if (h instanceof HttpServer) {
            return (HttpServer) h;
        }
    }

    return null;
}

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

License:Apache License

@Nullable
static HttpServer get(Channel channel) {
    final ChannelPipeline p = channel.pipeline();
    final ChannelHandler lastHandler = p.last();
    if (lastHandler instanceof HttpServer) {
        return (HttpServer) lastHandler;
    }/*from  w  w  w. jav  a 2 s .  co m*/

    for (ChannelHandler h : p.toMap().values()) {
        if (h instanceof HttpServer) {
            return (HttpServer) h;
        }
    }

    return null;
}

From source file:net.NettyEngine4.ServerHandler.java

License:Apache License

/**
 * Calls {@link io.netty.channel.ChannelHandlerContext#fireChannelInactive()} to forward
 * to the next {@link io.netty.channel.Channel} in the {@link io.netty.channel.ChannelPipeline}.
 *
 * Sub-classes may override this method to change behavior.
 *
 * ??/*from www . ja  va 2s  .c  o m*/
 */
@Override
public void channelInactive(ChannelHandlerContext ctx) {
    try {
        ctx.channel().close();
        //clear and store data!  channel closed!
        // this.player.saveAndDestory();

        countConnection.decrementAndGet();// -1

        if (logger.isDebugEnabled())
            logger.debug(ctx.channel().remoteAddress() + " channelClosed , Concurrent  connection... "
                    + countConnection.get());

        ChannelPipeline channelPipeline = ctx.channel().pipeline();

        if (null == channelPipeline) { // if null ,will be returned
            return;
        }
        //remove pipeline object
        while (channelPipeline.last() != null) {
            channelPipeline.removeLast();
        }
        if (ctx.isRemoved()) {
            ctx.close();
            // Set to null so the GC can collect them directly
            channelPipeline = null;
            ctx = null;
            player = null;
        }
    } catch (NoSuchElementException ee) {
        //do nothing
    } catch (Exception e) {
        if (logger.isDebugEnabled())
            logger.error("", e);
        //do nothing
    }
}