Java Code Examples for io.netty.channel.ChannelPromise#isDone()

The following examples show how to use io.netty.channel.ChannelPromise#isDone() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TokenClientPromiseHolder.java    From Sentinel-Dashboard-Nacos with Apache License 2.0 6 votes vote down vote up
public static <T> boolean completePromise(int xid, ClusterResponse<T> response) {
    if (!PROMISE_MAP.containsKey(xid)) {
        return false;
    }
    SimpleEntry<ChannelPromise, ClusterResponse> entry = PROMISE_MAP.get(xid);
    if (entry != null) {
        ChannelPromise promise = entry.getKey();
        if (promise.isDone() || promise.isCancelled()) {
            return false;
        }
        entry.setValue(response);
        promise.setSuccess();
        return true;
    }
    return false;
}
 
Example 2
Source File: GatewayHandler.java    From arcusplatform with Apache License 2.0 6 votes vote down vote up
@Override
@SuppressWarnings("null")
public void exceptionCaught(@Nullable ChannelHandlerContext ctx, @Nullable Throwable cause) throws Exception {
   if (cause != null) {
      log.warn("hub gateway exception: {}", cause.getMessage(), cause);
   } else {
      log.warn("hub gateway exception: unknown cause");
   }

   ChannelPromise hsf = handshakeFuture;
   if (hsf != null && !hsf.isDone()) {
      hsf.setFailure(cause);
   }

   ctx.close();
}
 
Example 3
Source File: TokenClientPromiseHolder.java    From Sentinel with Apache License 2.0 6 votes vote down vote up
public static <T> boolean completePromise(int xid, ClusterResponse<T> response) {
    if (!PROMISE_MAP.containsKey(xid)) {
        return false;
    }
    SimpleEntry<ChannelPromise, ClusterResponse> entry = PROMISE_MAP.get(xid);
    if (entry != null) {
        ChannelPromise promise = entry.getKey();
        if (promise.isDone() || promise.isCancelled()) {
            return false;
        }
        entry.setValue(response);
        promise.setSuccess();
        return true;
    }
    return false;
}
 
Example 4
Source File: HttpServerLifecycleChannelHandler.java    From zuul with Apache License 2.0 5 votes vote down vote up
@Override
public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception
{
    if (msg instanceof HttpResponse) {
        ctx.channel().attr(ATTR_HTTP_RESP).set((HttpResponse) msg);
    }
    
    try {
        super.write(ctx, msg, promise);
    }
    finally {
        if (msg instanceof LastHttpContent) {

            boolean dontFireCompleteYet = false;
            if (msg instanceof HttpResponse) {
                // Handle case of 100 CONTINUE, where server sends an initial 100 status response to indicate to client
                // that it can continue sending the initial request body.
                // ie. in this case we don't want to consider the state to be COMPLETE until after the 2nd response.
                if (((HttpResponse) msg).status() == HttpResponseStatus.CONTINUE) {
                    dontFireCompleteYet = true;
                }
            }

            if (!dontFireCompleteYet)
                if (promise.isDone()) {
                    fireCompleteEventIfNotAlready(ctx, CompleteReason.SESSION_COMPLETE);
                } else {
                    promise.addListener(future -> {
                        fireCompleteEventIfNotAlready(ctx, CompleteReason.SESSION_COMPLETE);
                    });
                }
        }
    }
}