Package io.netty.channel

Examples of io.netty.channel.ChannelPromise


                    success = false;
                    logger.warn(ChunkedInput.class.getSimpleName() + ".isEndOfInput() failed", e);
                }
                closeInput(in);
            } else if (currentEvent instanceof ChannelPromise) {
                ChannelPromise f = (ChannelPromise) currentEvent;
                if (!success) {
                    fireExceptionCaught = true;
                    if (cause == null) {
                        cause = new ClosedChannelException();
                    }
                    f.setFailure(cause);
                } else {
                    f.setSuccess();
                }
            }
        }

        if (fireExceptionCaught) {
View Full Code Here


    }

    private ChannelFuture doBind(final SocketAddress localAddress) {
        final ChannelFuture regPromise = initAndRegister();
        final Channel channel = regPromise.channel();
        final ChannelPromise promise = channel.newPromise();
        if (regPromise.isDone()) {
            doBind0(regPromise, channel, localAddress, promise);
        } else {
            regPromise.addListener(new ChannelFutureListener() {
                @Override
View Full Code Here

        } catch (Throwable t) {
            channel.unsafe().closeForcibly();
            return channel.newFailedFuture(t);
        }

        ChannelPromise regPromise = channel.newPromise();
        group().register(channel, regPromise);
        if (regPromise.cause() != null) {
            if (channel.isRegistered()) {
                channel.close();
            } else {
                channel.unsafe().closeForcibly();
            }
View Full Code Here

                        int connectTimeoutMillis = config().getConnectTimeoutMillis();
                        if (connectTimeoutMillis > 0) {
                            connectTimeoutFuture = eventLoop().schedule(new Runnable() {
                                @Override
                                public void run() {
                                    ChannelPromise connectPromise = AbstractNioChannel.this.connectPromise;
                                    ConnectTimeoutException cause =
                                            new ConnectTimeoutException("connection timed out: " + remoteAddress);
                                    if (connectPromise != null && connectPromise.tryFailure(cause)) {
                                        close(voidFuture());
                                    }
                                }
                            }, connectTimeoutMillis, TimeUnit.MILLISECONDS);
                        }
View Full Code Here

                    int connectTimeoutMillis = config().getConnectTimeoutMillis();
                    if (connectTimeoutMillis > 0) {
                        connectTimeoutFuture = eventLoop().schedule(new Runnable() {
                            @Override
                            public void run() {
                                ChannelPromise connectPromise = EpollSocketChannel.this.connectPromise;
                                ConnectTimeoutException cause =
                                        new ConnectTimeoutException("connection timed out: " + remoteAddress);
                                if (connectPromise != null && connectPromise.tryFailure(cause)) {
                                    close(voidPromise());
                                }
                            }
                        }, connectTimeoutMillis, TimeUnit.MILLISECONDS);
                    }
View Full Code Here

            }

            // depending on if we need to flush or not we can use a voidPromise or
            // use a normal promise
            final ByteBuf buf = buffer.byteBuf();
            final ChannelPromise promise;
            if (flush)
            {
               promise = channel.newPromise();
            }
            else
            {
               promise = channel.voidPromise();
            }

            EventLoop eventLoop = channel.eventLoop();
            boolean inEventLoop = eventLoop.inEventLoop();
            if (!inEventLoop)
            {
               channel.writeAndFlush(buf, promise);
            }
            else
            {
                // create a task which will be picked up by the eventloop and trigger the write.
                // This is mainly needed as this method is triggered by different threads for the same channel.
                // if we not do this we may produce out of order writes.
                final Runnable task = new Runnable()
                {
                    @Override
                    public void run()
                    {
                        channel.writeAndFlush(buf, promise);
                    }
                };
                // execute the task on the eventloop
                eventLoop.execute(task);
            }


            // only try to wait if not in the eventloop otherwise we will produce a deadlock
            if (flush && !inEventLoop)
            {
               while (true)
               {
                  try
                  {
                     boolean ok = promise.await(10000);

                     if (!ok)
                     {
                        HornetQClientLogger.LOGGER.timeoutFlushingPacket();
                     }
View Full Code Here

        ctx.fireChannelRead(msg);
    }

    @Override
    public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception {
        ChannelPromise unvoid = promise.unvoid();
        unvoid.addListener(new ChannelFutureListener() {
            @Override
            public void operationComplete(ChannelFuture future) throws Exception {
                lastWriteTime = System.nanoTime();
                firstWriterIdleEvent = firstAllIdleEvent = true;
            }
View Full Code Here

     *            termination.
     */
    protected final void sendGoAway(ChannelHandlerContext ctx, ChannelPromise promise,
            Http2Exception cause) {
        ChannelFuture future = null;
        ChannelPromise closePromise = promise;
        if (!connection.isGoAway()) {
            int errorCode = cause != null ? cause.error().code() : NO_ERROR.code();
            ByteBuf debugData = toByteBuf(ctx, cause);

            int lastKnownStream = connection.remote().lastStreamCreated();
View Full Code Here

     * If not already created, creates a new listener for the given promise which, when complete,
     * closes the connection and frees any resources.
     */
    private ChannelFutureListener getOrCreateCloseListener(final ChannelHandlerContext ctx,
            ChannelPromise promise) {
        final ChannelPromise closePromise = promise == null? ctx.newPromise() : promise;
        if (closeListener == null) {
            // If no promise was provided, create a new one.
            closeListener = new ChannelFutureListener() {
                @Override
                public void operationComplete(ChannelFuture future) throws Exception {
                    ctx.close(closePromise);
                    freeResources();
                }
            };
        } else {
            closePromise.setSuccess();
        }

        return closeListener;
    }
View Full Code Here

        ctx.flush();
    }

    private void wrap(ChannelHandlerContext ctx, boolean inUnwrap) throws SSLException {
        ByteBuf out = null;
        ChannelPromise promise = null;
        try {
            for (;;) {
                Object msg = pendingUnencryptedWrites.current();
                if (msg == null) {
                    break;
View Full Code Here

TOP

Related Classes of io.netty.channel.ChannelPromise

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.