List of usage examples for io.netty.channel ChannelPromise tryFailure
boolean tryFailure(Throwable cause);
From source file:org.dcache.xrootd.protocol.messages.ZeroCopyReadResponse.java
License:Open Source License
@Override public void writeTo(ChannelHandlerContext ctx, final ChannelPromise promise) { ByteBuf header = ctx.alloc().buffer(8); header.writeShort(request.getStreamId()); header.writeShort(kXR_ok);//from w ww. j a v a 2 s . com header.writeInt(count); ctx.write(header).addListener(new ChannelFutureListener() { @Override public void operationComplete(ChannelFuture future) throws Exception { if (!future.isSuccess()) { promise.tryFailure(future.cause()); } } }); ctx.write(new DefaultFileRegion(file, request.getReadOffset(), count)) .addListener(new ChannelFutureListener() { @Override public void operationComplete(ChannelFuture future) throws Exception { if (future.isSuccess()) { promise.trySuccess(); } else { promise.tryFailure(future.cause()); } } }); }
From source file:org.redisson.client.handler.CommandEncoder.java
License:Apache License
@Override public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception { try {/* ww w . ja v a2 s. co m*/ super.write(ctx, msg, promise); } catch (Exception e) { promise.tryFailure(e); throw e; } }
From source file:reactor.io.net.impl.netty.http.NettyHttpClientHandler.java
License:Open Source License
@Override protected void doOnTerminate(ChannelHandlerContext ctx, ChannelFuture last, final ChannelPromise promise) { if (request.method() == Method.WS) { return;/* w w w .j av a2 s . c o m*/ } ByteBuffer byteBuffer = body.flip().byteBuffer(); if (request.checkHeader()) { HttpRequest req = new DefaultFullHttpRequest(request.getNettyRequest().getProtocolVersion(), request.getNettyRequest().getMethod(), request.getNettyRequest().getUri(), byteBuffer != null ? Unpooled.wrappedBuffer(byteBuffer) : Unpooled.EMPTY_BUFFER); req.headers().add(request.headers().delegate()); if (byteBuffer != null) { HttpHeaders.setContentLength(req, body.limit()); } ctx.writeAndFlush(req).addListener(new ChannelFutureListener() { @Override public void operationComplete(ChannelFuture future) throws Exception { if (future.isSuccess()) { promise.trySuccess(); } else { promise.tryFailure(future.cause()); } } }); } else { ctx.write(new DefaultHttpContent( byteBuffer != null ? Unpooled.wrappedBuffer(byteBuffer) : Unpooled.EMPTY_BUFFER)); } body.reset(); }
From source file:reactor.io.net.impl.netty.http.NettyHttpWSClientHandler.java
License:Open Source License
@Override protected void doOnTerminate(ChannelHandlerContext ctx, ChannelFuture last, final ChannelPromise promise) { if (ctx.channel().isOpen()) { ChannelFutureListener listener = new ChannelFutureListener() { @Override//from w ww .j a v a2 s .c o m public void operationComplete(ChannelFuture future) throws Exception { if (future.isSuccess()) { promise.trySuccess(); } else { promise.tryFailure(future.cause()); } } }; if (last != null) { ctx.flush(); last.addListener(listener); } else { ctx.writeAndFlush(Unpooled.EMPTY_BUFFER).addListener(listener); } } else { promise.trySuccess(); } }
From source file:reactor.io.net.impl.netty.NettyChannelHandlerBridge.java
License:Apache License
protected void doOnTerminate(ChannelHandlerContext ctx, ChannelFuture last, final ChannelPromise promise) { if (ctx.channel().isOpen()) { ChannelFutureListener listener = new ChannelFutureListener() { @Override//ww w. j a v a 2 s . c o m public void operationComplete(ChannelFuture future) throws Exception { if (future.isSuccess()) { promise.trySuccess(); } else { promise.tryFailure(future.cause()); } } }; if (last != null) { ctx.flush(); last.addListener(listener); } else { ctx.writeAndFlush(Unpooled.EMPTY_BUFFER).addListener(listener); } } else { promise.trySuccess(); } }
From source file:reactor.ipc.netty.channel.ChannelOperationsHandler.java
License:Open Source License
void discard() { for (;;) {//from w w w . j a va 2 s.com if (pendingWrites == null || pendingWrites.isEmpty()) { return; } ChannelPromise promise; Object v = pendingWrites.poll(); try { promise = (ChannelPromise) v; } catch (Throwable e) { ctx.fireExceptionCaught(e); return; } v = pendingWrites.poll(); if (log.isDebugEnabled()) { log.debug("Terminated ChannelOperation. Dropping: {}", v); } ReferenceCountUtil.release(v); promise.tryFailure(ContextHandler.ABORTED); } }
From source file:reactor.ipc.netty.channel.NettyOperations.java
License:Open Source License
/** * Callback when a writer {@link Subscriber} has effectively terminated listening * on further {@link Publisher} signals. * * @param ctx the actual {@link ChannelHandlerContext} * @param last an optional callback for the last written payload * @param promise the promise to fulfil for acknowledging termination success * @param exception non null if the writer has terminated with a failure *///from w w w . j a va 2 s .co m protected void doOnTerminatedWriter(ChannelHandlerContext ctx, ChannelFuture last, final ChannelPromise promise, final Throwable exception) { if (ctx.channel().isOpen()) { ChannelFutureListener listener = future -> { if (exception != null) { promise.tryFailure(exception); } else if (future.isSuccess()) { promise.trySuccess(); } else { promise.tryFailure(future.cause()); } }; if (last != null) { last.addListener(listener); ctx.flush(); } } else { if (exception != null) { promise.tryFailure(exception); } else { promise.trySuccess(); } } }