io.netty.channel.socket.ChannelInputShutdownReadComplete#io.netty.handler.ssl.SslCloseCompletionEvent源码实例Demo

下面列出了io.netty.channel.socket.ChannelInputShutdownReadComplete#io.netty.handler.ssl.SslCloseCompletionEvent 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: armeria   文件: HttpServerHandler.java
@Override
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
    if (evt instanceof SslHandshakeCompletionEvent) {
        final SslHandler sslHandler = ctx.channel().pipeline().get(SslHandler.class);
        sslSession = sslHandler != null ? sslHandler.engine().getSession() : null;
        return;
    }

    if (evt instanceof SslCloseCompletionEvent ||
        evt instanceof ChannelInputShutdownReadComplete) {
        // Expected events
        return;
    }

    logger.warn("{} Unexpected user event: {}", ctx.channel(), evt);
}
 
/**
 * {@inheritDoc}
 *
 * Close the channel if the event is {@link SslCloseCompletionEvent} and the channel is unused.
 * If the channel is being used, it will be closed in {@link ResponseHandler}
 *
 */
@Override
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) {
    boolean channelInUse = getAttribute(ctx.channel(), ChannelAttributeKey.IN_USE).orElse(false);

    if (!channelInUse && evt instanceof SslCloseCompletionEvent) {
        ctx.close();
    } else {
        ctx.fireUserEventTriggered(evt);
    }
}
 
@Test
public void userEventTriggeredUnusedChannel_ClosesChannel() {
    SslCloseCompletionEventHandler handler = SslCloseCompletionEventHandler.getInstance();
    handler.userEventTriggered(ctx, new SslCloseCompletionEvent(new ClosedChannelException()));

    verify(ctx).close();
}
 
@Test
public void userEventTriggered_StaticVariable_ClosesChannel() {
    SslCloseCompletionEventHandler handler = SslCloseCompletionEventHandler.getInstance();
    handler.userEventTriggered(ctx, SslCloseCompletionEvent.SUCCESS);

    verify(ctx).close();
}
 
@Test
public void userEventTriggered_channelInUse_shouldForwardEvent() {
    SslCloseCompletionEventHandler handler = SslCloseCompletionEventHandler.getInstance();
    channel.attr(IN_USE).set(true);
    SslCloseCompletionEvent event = new SslCloseCompletionEvent(new ClosedChannelException());
    handler.userEventTriggered(ctx, event);

    verify(ctx).fireUserEventTriggered(event);
}