Example usage for io.netty.util.internal PromiseNotificationUtil tryFailure

List of usage examples for io.netty.util.internal PromiseNotificationUtil tryFailure

Introduction

In this page you can find the example usage for io.netty.util.internal PromiseNotificationUtil tryFailure.

Prototype

public static void tryFailure(Promise<?> p, Throwable cause, InternalLogger logger) 

Source Link

Document

Try to mark the Promise as failure and log if logger is not null in case this fails.

Usage

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

License:Apache License

public static void reject(ChannelHandlerContext ctx) {
    HttpResponseEncoder encoder = new HttpResponseEncoder();
    ChannelPromise promise = ctx.newPromise();
    promise.addListener(ChannelFutureListener.CLOSE);
    DefaultFullHttpResponse response = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1,
            HttpResponseStatus.SERVICE_UNAVAILABLE);
    try {/*  w w w  .j  a  va 2s . c o m*/
        encoder.write(ctx, response, ctx.voidPromise());
        ctx.writeAndFlush(ctx.alloc().buffer(0), promise);
    } catch (Throwable th) {//NOSONAR
        try {
            LOGGER.log(Level.SEVERE, "Failure during request rejection", th);
        } catch (Throwable loggingFailure) {//NOSONAR
        }
        PromiseNotificationUtil.tryFailure(promise, th, null);
    }
}