Java Code Examples for org.jboss.netty.channel.ChannelFuture#setSuccess()

The following examples show how to use org.jboss.netty.channel.ChannelFuture#setSuccess() . 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: Connection.java    From nfs-client-java with Apache License 2.0 5 votes vote down vote up
/**
 * Update the response map with the response and notify the thread waiting for the
 * response. Do nothing if the future has been removed.
 * 
 * @param xid
 * @param response
 */
protected void notifySender(Integer xid, Xdr response) {
    ChannelFuture future = _futureMap.get(xid);
    if (future != null) {
        _responseMap.put(xid, response);
        future.setSuccess();
    }
}
 
Example 2
Source File: NioClientSocketPipelineSink.java    From android-netty with Apache License 2.0 5 votes vote down vote up
private static void bind(
        NioClientSocketChannel channel, ChannelFuture future,
        SocketAddress localAddress) {
    try {
        channel.channel.socket().bind(localAddress);
        channel.boundManually = true;
        channel.setBound();
        future.setSuccess();
        fireChannelBound(channel, channel.getLocalAddress());
    } catch (Throwable t) {
        future.setFailure(t);
        fireExceptionCaught(channel, t);
    }
}
 
Example 3
Source File: AbstractNioWorker.java    From android-netty with Apache License 2.0 4 votes vote down vote up
protected void close(AbstractNioChannel<?> channel, ChannelFuture future) {
    boolean connected = channel.isConnected();
    boolean bound = channel.isBound();
    boolean iothread = isIoThread(channel);

    try {
        channel.channel.close();
        increaseCancelledKeys();

        if (channel.setClosed()) {
            future.setSuccess();
            if (connected) {
                if (iothread) {
                    fireChannelDisconnected(channel);
                } else {
                    fireChannelDisconnectedLater(channel);
                }
            }
            if (bound) {
                if (iothread) {
                    fireChannelUnbound(channel);
                } else {
                    fireChannelUnboundLater(channel);
                }
            }

            cleanUpWriteBuffer(channel);
            if (iothread) {
                fireChannelClosed(channel);
            } else {
                fireChannelClosedLater(channel);
            }
        } else {
            future.setSuccess();
        }
    } catch (Throwable t) {
        future.setFailure(t);
        if (iothread) {
            fireExceptionCaught(channel, t);
        } else {
            fireExceptionCaughtLater(channel, t);
        }
    }
}
 
Example 4
Source File: AbstractNioWorker.java    From android-netty with Apache License 2.0 4 votes vote down vote up
void setInterestOps(final AbstractNioChannel<?> channel, final ChannelFuture future, final int interestOps) {
    boolean iothread = isIoThread(channel);
    if (!iothread) {
        channel.getPipeline().execute(new Runnable() {
            public void run() {
                setInterestOps(channel, future, interestOps);
            }
        });
        return;
    }

    boolean changed = false;
    try {
        Selector selector = this.selector;
        SelectionKey key = channel.channel.keyFor(selector);

        // Override OP_WRITE flag - a user cannot change this flag.
        int newInterestOps = interestOps & ~Channel.OP_WRITE | channel.getRawInterestOps() & Channel.OP_WRITE;

        if (key == null || selector == null) {
            if (channel.getRawInterestOps() != newInterestOps) {
                changed = true;
            }

            // Not registered to the worker yet.
            // Set the rawInterestOps immediately; RegisterTask will pick it up.
            channel.setRawInterestOpsNow(newInterestOps);

            future.setSuccess();
            if (changed) {
                if (iothread) {
                    fireChannelInterestChanged(channel);
                } else {
                    fireChannelInterestChangedLater(channel);
                }
            }

            return;
        }

        if (channel.getRawInterestOps() != newInterestOps) {
            key.interestOps(newInterestOps);
            if (Thread.currentThread() != thread &&
                wakenUp.compareAndSet(false, true)) {
                selector.wakeup();
            }
            channel.setRawInterestOpsNow(newInterestOps);
        }

        future.setSuccess();
        if (changed) {
            fireChannelInterestChanged(channel);
        }
    } catch (CancelledKeyException e) {
        // setInterestOps() was called on a closed channel.
        ClosedChannelException cce = new ClosedChannelException();
        future.setFailure(cce);
        fireExceptionCaught(channel, cce);
    } catch (Throwable t) {
        future.setFailure(t);
        fireExceptionCaught(channel, t);
    }
}