public void run(Timeout timeout) throws Exception { ChannelFuture future = SslHandler.this.handshakeFuture; if (future != null && future.isDone()) { return; } setHandshakeFailure(channel, new SSLException("Handshake did not complete within " + handshakeTimeoutInMillis + "ms")); } }, handshakeTimeoutInMillis, TimeUnit.MILLISECONDS);
public void operationComplete(ChannelFuture f) throws Exception { if (!cf.isDone()) { cf.setFailure(new ClosedChannelException()); } } });
/** * Works around some Android {@link SSLEngine} implementations that skip {@link HandshakeStatus#FINISHED} and * go straight into {@link HandshakeStatus#NOT_HANDSHAKING} when handshake is finished. * * @return {@code true} if and only if the workaround has been applied and thus {@link #handshakeFuture} has been * marked as success by this method */ private boolean setHandshakeSuccessIfStillHandshaking(Channel channel) { if (handshaking && !handshakeFuture.isDone()) { setHandshakeSuccess(channel); return true; } return false; }
@Override public void writeBuffers(List<ByteBuffer> buffers) throws IOException { ChannelFuture writeFuture; stateLock.readLock().lock(); try { writeFuture = writeDataPack( new NettyDataPack(serialGenerator.incrementAndGet(), buffers)); } finally { stateLock.readLock().unlock(); } if (!writeFuture.isDone()) { try { writeFuture.await(); } catch (InterruptedException e) { Thread.currentThread().interrupt(); // Reset interrupt flag throw new IOException("Interrupted while writing Netty data pack", e); } } if (!writeFuture.isSuccess()) { throw new IOException("Error writing buffers", writeFuture.getCause()); } }
if (handshakeFuture == null || !handshakeFuture.isDone()) { writeBeforeHandshakeDone = true;
if (currentEvent.getFuture().isDone()) {
@Override public boolean isDone() { return future.isDone(); }
@Override public boolean isDone() { return m_future.isDone(); }
@Override public boolean isTrue(ChannelFuture f) { return f.isDone(); } });
synchronized void writeAndClose(ChannelFuture writeFuture) { if (!writeFuture.isDone()) { writeFutures.add(writeFuture); writeFuture.addListener(new ChannelFutureListener() { @Override public void operationComplete(ChannelFuture cf) throws Exception { writeFutures.remove(cf); futureClose(); } }); } }
@Override public void handleDownstream(ChannelHandlerContext ctx, ChannelEvent evt) throws Exception { ChannelFuture pipelineFuture = getPipelineFuture(); ChannelFuture handlerFuture = getHandlerFuture(); // while handler future not complete, queue channel events if (queue != null && pipelineFuture.isDone() && !handlerFuture.isDone()) { queue.add(evt); } else { // TODO: review need for synchronized synchronized (ctx) { ctx.sendDownstream(evt); } } }
@Override public boolean validateObject(ChannelFuture future) { boolean isValid = !future.isDone() || future.isDone() && future.isSuccess() && future.getChannel().isConnected(); if (!isValid) { LOG.debug("connection not valid {}", Integer.toHexString(future.getChannel().getId())); } return isValid; }
@Override public void run(Timer.TimeoutHandle timeoutHandle) { try { if (!channel.isConnected() && !channel.getCloseFuture().isDone()) { LOGGER.warn("{}: connect timeout to {} triggered", selfId, serverId); channel.close(); } } catch (Exception e) { LOGGER.warn("{}: fail close unconnected channel to {}", selfId, serverId, e); } } }, connectTimeout, timeUnit);
@Override public void afterRemove(ChannelHandlerContext ctx) throws Exception { assert handlerFuture != null; if (!handlerFuture.isDone()) { ScriptProgressException exception = new ScriptProgressException(getRegionInfo(), ""); handlerFuture.setFailure(exception); } handlerFuture = null; }
@Override protected void handleUpstream1(ChannelHandlerContext ctx, ChannelEvent evt) throws Exception { ChannelEventKind eventAsKind = asEventKind(evt); ChannelFuture handlerFuture = getHandlerFuture(); assert handlerFuture != null; if (handlerFuture.isDone() || !interestEvents.contains(eventAsKind)) { // Skip events not deemed interesting, such as write // completion events ctx.sendUpstream(evt); } else if (!expectedEvents.contains(eventAsKind)) { handleUnexpectedEvent(ctx, evt); } else { super.handleUpstream1(ctx, evt); } }
@Override public void operationComplete( ChannelFuture future ) { if ( !future.isDone() ) { throw new ComException( "This should not be possible because we waited for the future to be done" ); } if ( !future.isSuccess() || future.isCancelled() ) { future.getChannel().close(); } writeAheadCounter.decrementAndGet(); }
public void connect() { clientBootstrap = new ClientBootstrap(new NioClientSocketChannelFactory(Executors.newCachedThreadPool(), Executors.newCachedThreadPool())); clientBootstrap.setOption("tcpNoDelay", true); clientBootstrap.setPipelineFactory(new ClientPipelineFactory()); while (true) { ChannelFuture future = clientBootstrap.connect(new InetSocketAddress(ip, Integer.parseInt(port))); future.awaitUninterruptibly(5000); if (future.isDone()) { channel = future.getChannel(); if (channel != null && channel.isConnected()) { break; } } } }
@Override public void operationComplete(final ChannelFuture future) throws Exception { if (LOGGER.isDebugEnabled()) { // detect observed script String observedScript = progress.getObservedScript(); LOGGER.debug("Observed script:\n" + observedScript); } if (abortedFuture.isDone()) { // abort complete, trigger finished future finishedFuture.setSuccess(); } else { // execution complete, trigger finished future finishedFuture.setSuccess(); } }
@Override public void channelConnected(ChannelHandlerContext ctx, ChannelStateEvent e) throws Exception { HttpChildChannel httpChannel = (HttpChildChannel) ctx.getChannel(); HttpChannelConfig httpConfig = httpChannel.getConfig(); HttpHeaders httpHeaders = httpConfig.getReadHeaders(); int sequenceNo = getIntHeader(httpHeaders, Names.X_SEQUENCE_NO); ChannelFuture attachFuture = bboshChannelSink.attach(sequenceNo, httpChannel); if (!attachFuture.isDone()) { httpChannel.setReadable(false); attachFuture.addListener(READ_RESUMER); } }
@Override protected void handleUnexpectedEvent(ChannelHandlerContext ctx, ChannelEvent evt) { Channel channel = evt.getChannel(); MessageEvent msg = new UpstreamMessageEvent(channel, copiedBuffer("", UTF_8), channel.getRemoteAddress()); // We create a message with an empty string. We need make sure our decoders get the decoder Last call. messageReceived(ctx, msg, true); // If the above caused a completion we are done. Otherwise we still need to handle the unexpected event if (!getHandlerFuture().isDone()) { super.handleUnexpectedEvent(ctx, evt); } }