io.netty.util.concurrent.Future#cause ( )源码实例Demo

下面列出了io.netty.util.concurrent.Future#cause ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

@Override
public void operationComplete(final Future<? super Void> future) throws Exception {
    if (!future.isSuccess()) {
        final Throwable cause = future.cause();
        if (Exceptions.isConnectionClosedException(cause)) {
            log.trace("Failed to write publish. Client not connected anymore");
            statusFuture.set(PublishStatus.NOT_CONNECTED);

        } else if (cause instanceof EncoderException) {
            Exceptions.rethrowError("Failed to write publish. Encoding Failure.", cause);
            final Throwable rootCause = cause.getCause();
            if (cause != rootCause) {
                Exceptions.rethrowError("Failed to write publish. Encoding Failure, root cause:", rootCause);
            }
            statusFuture.set(PublishStatus.FAILED);
        } else {
            Exceptions.rethrowError("Failed to write publish.", cause);
            statusFuture.set(PublishStatus.FAILED);
        }
    }
}
 
源代码2 项目: arcusplatform   文件: SslBindClientHandler.java
private void onSslHandshakeComplete(Future<? super Channel> result, SslHandler handler) {
   try {
      if(!result.isSuccess()) {
         if (logger.isDebugEnabled()) {
            Throwable cause = result.cause();
            if (!(cause instanceof ClosedChannelException)) {
               logger.debug("SSL handshake failed: {}", (cause == null) ? "unknown" : cause.getMessage(), cause);
            }
         }
         return;
      }

      String clientName = extractClientName(handler);
      if(clientName != null) {
         Channel channel = (Channel) result.get();
         Client.bind(channel, registry.load(clientName));
      }
   }
   catch(Exception e) {
      logger.debug("Unable to determine client auth", e);
   }
}
 
源代码3 项目: netty-4.1.22   文件: SearchDomainTest.java
@Test
public void testExceptionMsgContainsSearchDomain() throws Exception {
    TestDnsServer.MapRecordStoreA store = new TestDnsServer.MapRecordStoreA(Collections.<String>emptySet());
    dnsServer = new TestDnsServer(store);
    dnsServer.start();

    resolver = newResolver().searchDomains(Collections.singletonList("foo.com")).ndots(1).build();

    Future<InetAddress> fut = resolver.resolve("unknown.hostname");
    assertTrue(fut.await(10, TimeUnit.SECONDS));
    assertFalse(fut.isSuccess());
    final Throwable cause = fut.cause();
    assertThat(cause, instanceOf(UnknownHostException.class));
    assertThat("search domain is included in UnknownHostException", cause.getMessage(),
        containsString("foo.com"));
}
 
源代码4 项目: netty-4.1.22   文件: SearchDomainTest.java
@Test
public void testExceptionMsgDoesNotContainSearchDomainIfNdotsIsNotReached() throws Exception {
    TestDnsServer.MapRecordStoreA store = new TestDnsServer.MapRecordStoreA(Collections.<String>emptySet());
    dnsServer = new TestDnsServer(store);
    dnsServer.start();

    resolver = newResolver().searchDomains(Collections.singletonList("foo.com")).ndots(2).build();

    Future<InetAddress> fut = resolver.resolve("unknown.hostname");
    assertTrue(fut.await(10, TimeUnit.SECONDS));
    assertFalse(fut.isSuccess());
    final Throwable cause = fut.cause();
    assertThat(cause, instanceOf(UnknownHostException.class));
    assertThat("search domain is included in UnknownHostException", cause.getMessage(),
            not(containsString("foo.com")));
}
 
源代码5 项目: ftdc   文件: FtdClientPool.java
/**
 * 释放连接
 * @param channel
 * @return
 */
public Future<Void> release(Channel channel) {
	Verify.verifyNotNull(channel, "channel不允许为NULL");
	InetSocketAddress remoteAddress = (InetSocketAddress)channel.remoteAddress();
	if(logger.isDebugEnabled()) {
		logger.debug("{} channel released", remoteAddress);
	}
	FixedChannelPool fixedChannelPool = pollMap.get(remoteAddress);
	Future<Void> releaseFuture = fixedChannelPool.release(channel);
	if(!releaseFuture.isSuccess()) {
		Throwable cause = releaseFuture.cause();
		if(cause != null) {
			logger.error("rlease local channel {}, remote channel {}, happens error {}", channel.localAddress(),
					channel.remoteAddress(), ExceptionUtils.getStackTrace(releaseFuture.cause()));
		}
	}
	return releaseFuture;
}
 
@Override
public void close() {
    if (closed.compareAndSet(false, true)) {
        Future<?> closeCompleteFuture = doClose();

        try {
            if (!closeCompleteFuture.await(10, TimeUnit.SECONDS)) {
                throw new RuntimeException("Event loop didn't close after 10 seconds.");
            }
        } catch (InterruptedException e) {
            Thread.currentThread().interrupt();
            throw new RuntimeException(e);
        }

        Throwable exception = closeCompleteFuture.cause();
        if (exception != null) {
            throw new RuntimeException("Failed to close channel pool.", exception);
        }
    }
}
 
源代码7 项目: ambry   文件: Http2MultiplexedChannelPool.java
@Override
public void close() {
  if (closed.compareAndSet(false, true)) {
    Future<?> closeCompleteFuture = doClose();

    try {
      if (!closeCompleteFuture.await(10, TimeUnit.SECONDS)) {
        throw new RuntimeException("Event loop didn't close after 10 seconds.");
      }
    } catch (InterruptedException e) {
      Thread.currentThread().interrupt();
      throw new RuntimeException(e);
    }

    Throwable exception = closeCompleteFuture.cause();
    if (exception != null) {
      throw new RuntimeException("Failed to close channel pool.", exception);
    }
  }
}
 
源代码8 项目: Bats   文件: ConnectionMultiListener.java
@Override
public void operationComplete(Future<Channel> future) throws Exception {
  if(parent != null){
    if(future.isSuccess()) {
      Channel c = future.get();
      parent.sslConnectionHandler.operationComplete(future);
      parent.parent.setSslChannel(c);
    } else {
      throw new DrillException("SSL handshake failed.", future.cause());
    }
  } else {
    throw new RpcException("RPC Setup error. SSL handshake complete handler is not set up.");
  }
}
 
源代码9 项目: netty-4.1.22   文件: AbstractSniHandler.java
private void fireSniCompletionEvent(ChannelHandlerContext ctx, String hostname, Future<T> future) {
    Throwable cause = future.cause();
    if (cause == null) {
        ctx.fireUserEventTriggered(new SniCompletionEvent(hostname));
    } else {
        ctx.fireUserEventTriggered(new SniCompletionEvent(hostname, cause));
    }
}
 
源代码10 项目: spring-boot-protocol   文件: AbstractNettyServer.java
protected void stopAfter(Future future){
    //有异常抛出
    Throwable cause = future.cause();
    if(cause != null){
        logger.error("stopAfter error={}",cause.toString(),cause);
    }
    logger.info("{} stop [port = {} , cause = {}]...",getName(),getPort(),cause);
}
 
源代码11 项目: armeria   文件: RefreshingAddressResolverTest.java
@Test
void negativeTtl() {
    // TimeoutHandler times out only the first query.
    try (TestDnsServer server = new TestDnsServer(ImmutableMap.of(), new TimeoutHandler())) {
        final EventLoop eventLoop = eventLoopExtension.get();
        final DnsResolverGroupBuilder builder = builder(server).negativeTtl(60).queryTimeoutMillis(1000);
        try (RefreshingAddressResolverGroup group = builder.build(eventLoop)) {
            final AddressResolver<InetSocketAddress> resolver = group.getResolver(eventLoop);

            final Future<InetSocketAddress> future = resolver.resolve(
                    InetSocketAddress.createUnresolved("foo.com", 36462));
            await().until(future::isDone);

            final Throwable cause = future.cause();
            assertThat(cause).isInstanceOfAny(UnknownHostException.class,
                                              DnsTimeoutException.class);
            if (cause instanceof UnknownHostException) {
                assertThat(cause).hasCauseInstanceOf(DnsNameResolverTimeoutException.class);
            }

            // Because it's timed out, the result is not cached.
            final ConcurrentMap<String, CompletableFuture<CacheEntry>> cache = group.cache();
            assertThat(cache.size()).isZero();

            final Future<InetSocketAddress> future2 = resolver.resolve(
                    InetSocketAddress.createUnresolved("foo.com", 36462));
            await().until(future2::isDone);
            assertThat(future2.cause()).isInstanceOf(UnknownHostException.class)
                                       .hasNoCause();
            // Because it is NXDOMAIN, the result is cached.
            assertThat(cache.size()).isOne();
        }
    }
}
 
@Override
public void operationComplete(Future<? super Void> future) throws Exception {
    if (future.isSuccess()) {
        logger.debug("Successfully disconnected connection...");
    } else {
        final Throwable t = future.cause();
        logger.warn(t.getMessage(), t);
    }

}