Java Code Examples for org.jboss.netty.channel.ChannelFuture#setFailure()
The following examples show how to use
org.jboss.netty.channel.ChannelFuture#setFailure() .
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: NioClientSocketPipelineSink.java From android-netty with Apache License 2.0 | 6 votes |
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
Source File: NioClientSocketPipelineSink.java From android-netty with Apache License 2.0 | 5 votes |
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: Connection.java From nfs-client-java with Apache License 2.0 | 4 votes |
/** * 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 File: AbstractNioWorker.java From android-netty with Apache License 2.0 | 4 votes |
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 File: AbstractNioWorker.java From android-netty with Apache License 2.0 | 4 votes |
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); } }