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

The following examples show how to use org.jboss.netty.channel.ChannelFuture#setFailure() . These examples are extracted from open source projects. 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 want to check out the right sidebar which shows the related API usage.
Example 1
private void connect(
        final NioClientSocketChannel channel, final ChannelFuture cf,
        SocketAddress remoteAddress) {
    try {
        if (channel.channel.connect(remoteAddress)) {
            channel.worker.register(channel, cf);
        } else {
            channel.getCloseFuture().addListener(new ChannelFutureListener() {
                public void operationComplete(ChannelFuture f)
                        throws Exception {
                    if (!cf.isDone()) {
                        cf.setFailure(new ClosedChannelException());
                    }
                }
            });
            cf.addListener(ChannelFutureListener.CLOSE_ON_FAILURE);
            channel.connectFuture = cf;
            nextBoss().register(channel, cf);
        }

    } catch (Throwable t) {
        cf.setFailure(t);
        fireExceptionCaught(channel, t);
        channel.worker.close(channel, succeededFuture(channel));
    }
}
 
Example 2
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 Project: nfs-client-java   File: Connection.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * Notify all the senders of all pending requests
 */
protected void notifyAllPendingSenders(String message) {
    for (ChannelFuture future : _futureMap.values()) {
        future.setFailure(new Error(message));
    }
}
 
Example 4
Source Project: android-netty   File: AbstractNioWorker.java    License: 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 5
Source Project: android-netty   File: AbstractNioWorker.java    License: 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);
    }
}