@Override public boolean isDone() { return delegate.isDone(); }
@Override public boolean isDone() { return delegate.isDone(); }
SimpleChannelPromiseAggregator(ChannelPromise promise, Channel c, EventExecutor e) { super(c, e); assert promise != null && !promise.isDone(); this.promise = promise; }
@Override public boolean isOpen() { return !closePromise.isDone(); }
@Override public boolean isDone() { return delegate.isDone(); }
@Override public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) { if (!handshakeFuture.isDone()) { LOGGER.debug("Handshake failed : " + cause.getMessage(), cause); handshakeFuture.setFailure(cause); isConnected = false; } ctx.close(); } }
void success(long total) { if (promise.isDone()) { // No need to notify the progress or fulfill the promise because it's done already. return; } progress(total, total); promise.trySuccess(); }
@Override public void run() { // Was not written yet so issue a write timeout // The promise itself will be failed with a ClosedChannelException once the close() was issued // See https://github.com/netty/netty/issues/2159 if (!promise.isDone()) { try { writeTimedOut(ctx); } catch (Throwable t) { ctx.fireExceptionCaught(t); } } removeWriteTimeoutTask(this); }
void success(long total) { if (promise.isDone()) { // No need to notify the progress or fulfill the promise because it's done already. return; } progress(total, total); promise.trySuccess(); }
@Override public void exceptionCaught(final ChannelHandlerContext ctx, final Throwable cause) { if (!handshakeFuture.isDone()) { handshakeFuture.setFailure(cause); } super.exceptionCaught(ctx, cause); }
@Override public void run() { // Was not written yet so issue a write timeout // The promise itself will be failed with a ClosedChannelException once the close() was issued // See https://github.com/netty/netty/issues/2159 if (!promise.isDone()) { try { writeTimedOut(ctx); } catch (Throwable t) { ctx.fireExceptionCaught(t); } } removeWriteTimeoutTask(this); }
if (promise.isDone()) {
public static <T> boolean completePromise(int xid, ClusterResponse<T> response) { if (!PROMISE_MAP.containsKey(xid)) { return false; } SimpleEntry<ChannelPromise, ClusterResponse> entry = PROMISE_MAP.get(xid); if (entry != null) { ChannelPromise promise = entry.getKey(); if (promise.isDone() || promise.isCancelled()) { return false; } entry.setValue(response); promise.setSuccess(); return true; } return false; }
@Test(timeout = 60000) public void testOnStart() throws Exception { assertThat("Unexpected promise completion state.", subscriberRule.channelPromise.isDone(), is(false)); subscriberRule.start(); assertThat("Unexpected promise completion state.", subscriberRule.channelPromise.isDone(), is(false)); assertThat("Unexpected request made to the producer.", subscriberRule.mockProducer.getRequested(), is(subscriberRule.defaultRequestN())); }
protected void sendMessagesAndAssert(int count) { String[] msgs = new String[count]; for (int i = 0; i < count; i++) { msgs[i] = "msg" + i; } writeAndFlushMessages(msgs); assertThat("Unexpected promise completion state.", channelPromise.isDone(), is(false)); assertMessagesWritten(msgs); }
@Test(timeout = 60000) public void testWriteFailed() throws Exception { subscriberRule.start(); String msg1 = "msg1"; subscriberRule.writeMessages(msg1); assertThat("Unexpected promise completion state.", subscriberRule.channelPromise.isDone(), is(false)); subscriberRule.channel.close(); assertThat("Unexpected promise completion state.", subscriberRule.channelPromise.isDone(), is(true)); assertThat("Unexpected promise result.", subscriberRule.channelPromise.isSuccess(), is(false)); }
@Test(timeout = 60000) public void testWriteCompleteBeforeStream() throws Exception { subscriberRule.start(); String msg1 = "msg1"; subscriberRule.writeAndFlushMessages(msg1); subscriberRule.assertMessagesWritten(msg1); assertThat("Unexpected promise completion state.", subscriberRule.channelPromise.isDone(), is(false)); subscriberRule.subscriber.onCompleted(); assertThat("Unexpected promise completion state.", subscriberRule.channelPromise.isDone(), is(true)); assertThat("Unexpected promise result.", subscriberRule.channelPromise.isSuccess(), is(true)); }
@Test(timeout = 60000) public void testStreamError() throws Exception { subscriberRule.start(); subscriberRule.sendMessagesAndAssert(1); subscriberRule.subscriber.onError(new IOException()); assertThat("Unexpected promise completion state.", subscriberRule.channelPromise.isDone(), is(true)); assertThat("Unexpected promise result.", subscriberRule.channelPromise.isSuccess(), is(false)); }
public void setEventLoopThread() { ChannelPromise deregisterPromise = channel.newPromise(); channel.deregister(deregisterPromise); channel.runPendingTasks(); assertThat("failed to deregister", deregisterPromise.isDone() && deregisterPromise.isSuccess()); ThreadAwareEmbeddedEventLoop loop = new ThreadAwareEmbeddedEventLoop(Thread.currentThread()); ChannelFuture registerPromise = loop.register(channel); assertThat("failed to register", registerPromise.isDone() && registerPromise.isSuccess()); }
public void finishOverarchingWritePromiseIfAllPromisesFinished() { for (ChannelPromise aPromise : allPromises) { if (aPromise.isDone()) { if (!aPromise.isSuccess()) { overarchingPromise.tryFailure(aPromise.cause()); return; } } else { overarchingPromise.tryFailure(new IllegalStateException("A write promise did not complete.")); return; } } overarchingPromise.trySuccess(); }