当前位置: 首页>>代码示例>>Java>>正文


Java ConnectTimeoutException类代码示例

本文整理汇总了Java中io.netty.channel.ConnectTimeoutException的典型用法代码示例。如果您正苦于以下问题:Java ConnectTimeoutException类的具体用法?Java ConnectTimeoutException怎么用?Java ConnectTimeoutException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ConnectTimeoutException类属于io.netty.channel包,在下文中一共展示了ConnectTimeoutException类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testConnectTimeoutFailure

import io.netty.channel.ConnectTimeoutException; //导入依赖的package包/类
@Test
public void testConnectTimeoutFailure() throws Exception {
    NetworkClient<String> client = createClient(f -> f.setConnectTimeout(1));

    repeat(3, i -> {
        NetworkClientCallbackMock<String> callback = new NetworkClientCallbackMock<>();

        assertSame(NetworkClient.State.DISCONNECTED, client.state());

        try {
            get(client.connect(new InetSocketAddress("hekate.io", 81), callback));

            fail("Error was expected");
        } catch (ExecutionException e) {
            assertTrue(e.getCause().toString(), ErrorUtils.isCausedBy(ConnectTimeoutException.class, e));
        }

        assertSame(NetworkClient.State.DISCONNECTED, client.state());
        assertNull(client.remoteAddress());
        assertNull(client.localAddress());
        callback.assertConnects(0);
        callback.assertDisconnects(1);
        callback.assertErrors(1);
        callback.getErrors().forEach(e -> assertTrue(e.toString(), e instanceof ConnectTimeoutException));
    });
}
 
开发者ID:hekate-io,项目名称:hekate,代码行数:27,代码来源:NetworkClientTest.java

示例2: doConnect

import io.netty.channel.ConnectTimeoutException; //导入依赖的package包/类
@Override
protected void doConnect(SocketAddress remoteAddress,
        SocketAddress localAddress) throws Exception {
    if (localAddress != null) {
        socket.bind(localAddress);
    }

    boolean success = false;
    try {
        socket.connect(remoteAddress, config().getConnectTimeoutMillis());
        activate(socket.getInputStream(), socket.getOutputStream());
        success = true;
    } catch (SocketTimeoutException e) {
        ConnectTimeoutException cause = new ConnectTimeoutException("connection timed out: " + remoteAddress);
        cause.setStackTrace(e.getStackTrace());
        throw cause;
    } finally {
        if (!success) {
            doClose();
        }
    }
}
 
开发者ID:wuyinxian124,项目名称:netty4.0.27Learn,代码行数:23,代码来源:OioSocketChannel.java

示例3: exceptionCaught

import io.netty.channel.ConnectTimeoutException; //导入依赖的package包/类
@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
    String message;

    if (!(cause instanceof ConnectTimeoutException) && (!(cause instanceof ConnectException) || !cause.getMessage()
            .contains("connection timed out"))) {
        if (cause instanceof ReadTimeoutException) {
            message = "Read timed out.";
        } else if (cause instanceof WriteTimeoutException) {
            message = "Write timed out.";
        } else {
            message = "Internal network exception.";
        }
    } else {
        message = "Connection timed out.";
    }

    this.disconnect(message, cause);
}
 
开发者ID:InspireNXE,项目名称:Pulse,代码行数:20,代码来源:PCSession.java

示例4: testConnectTimeout

import io.netty.channel.ConnectTimeoutException; //导入依赖的package包/类
@Test(timeout = 1000)
public void testConnectTimeout() {

    SocketOptions socketOptions = SocketOptions.builder().connectTimeout(100, TimeUnit.MILLISECONDS).build();
    client.setOptions(ClientOptions.builder().socketOptions(socketOptions).build());

    try {
        client.connect(RedisURI.create("2:4:5:5::1", 60000));
        fail("Missing RedisConnectionException");
    } catch (RedisConnectionException e) {

        if (e.getCause() instanceof ConnectTimeoutException) {
            assertThat(e).hasRootCauseInstanceOf(ConnectTimeoutException.class);
            assertThat(e.getCause()).hasMessageContaining("connection timed out");
            return;
        }

        if (e.getCause() instanceof SocketException) {
            // Network is unreachable or No route to host are OK as well.
            return;
        }
    }
}
 
开发者ID:lettuce-io,项目名称:lettuce-core,代码行数:24,代码来源:SocketOptionsTest.java

示例5: shouldForceTimeoutOfSocketConnectDoesNotReturn

import io.netty.channel.ConnectTimeoutException; //导入依赖的package包/类
@Test
public void shouldForceTimeoutOfSocketConnectDoesNotReturn() {
    BootstrapAdapter bootstrap = mock(BootstrapAdapter.class);
    when(bootstrap.connect()).thenReturn(channel.newPromise()); // this promise never completes
    Endpoint endpoint = new DummyEndpoint(bootstrap, environment);

    Observable<LifecycleState> observable = endpoint.connect();

    TestSubscriber<LifecycleState> testSubscriber = new TestSubscriber<LifecycleState>();
    observable.subscribe(testSubscriber);
    testSubscriber.awaitTerminalEvent();

    List<Throwable> errors = testSubscriber.getOnErrorEvents();
    assertEquals(1, errors.size());
    assertEquals(ConnectTimeoutException.class, errors.get(0).getClass());

    endpoint.disconnect().subscribe();
}
 
开发者ID:couchbase,项目名称:couchbase-jvm-core,代码行数:19,代码来源:AbstractEndpointTest.java

示例6: testConnectException2

import io.netty.channel.ConnectTimeoutException; //导入依赖的package包/类
@Test
public void testConnectException2() throws Exception {
    HttpClientBuilder<ByteBuf, ByteBuf> clientBuilder = new HttpClientBuilder<ByteBuf, ByteBuf>("www.google.com", 81);
    HttpClient<ByteBuf, ByteBuf> client = clientBuilder.channelOption(ChannelOption.CONNECT_TIMEOUT_MILLIS, 10).build();
    Observable<HttpClientResponse<ByteBuf>> response = client.submit(HttpClientRequest.createGet("/"));
    final CountDownLatch latch = new CountDownLatch(1);
    final AtomicReference<Throwable> ex = new AtomicReference<Throwable>();
    response.subscribe(new Observer<HttpClientResponse<ByteBuf>>() {
        @Override
        public void onCompleted() {
            latch.countDown();
        }

        @Override
        public void onError(Throwable e) {
            ex.set(e);
            latch.countDown();
        }

        @Override
        public void onNext(HttpClientResponse<ByteBuf> args) {
        }
    });
    latch.await(10, TimeUnit.SECONDS);
    assertTrue(ex.get() instanceof ConnectTimeoutException);
}
 
开发者ID:allenxwang,项目名称:RxNetty,代码行数:27,代码来源:HttpClientTest.java

示例7: isRetryException

import io.netty.channel.ConnectTimeoutException; //导入依赖的package包/类
public static boolean isRetryException(Throwable exception) {
  if (exception instanceof ConnectException
      || exception instanceof ConnectTimeoutException
      || exception instanceof UnknownHostException) {
    return true;
  }
  return false;
}
 
开发者ID:Nordstrom,项目名称:xrpc,代码行数:9,代码来源:RetryLoop.java

示例8: testNegativeConnectCall

import io.netty.channel.ConnectTimeoutException; //导入依赖的package包/类
@Test
public void testNegativeConnectCall() throws Exception {
    asyncCall(new ClientBuilder() {
        @Override
        public PbrpcClient getClient() {
            return PbrpcClientFactory.buildShortLiveConnection("9.9.9.9", 9999);
        }
    }, new ConnectTimeoutException(), false);
}
 
开发者ID:neoremind,项目名称:navi-pbrpc,代码行数:10,代码来源:ShortAliveConnectionPbrpcClientTest.java

示例9: exceptionCaught

import io.netty.channel.ConnectTimeoutException; //导入依赖的package包/类
@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
    if (cause instanceof ConnectTimeoutException) {
        Log.d(TAG, "connection timeout exception");
        return; // no finish, fall through to listener
    }

    mSession.finish(cause);
}
 
开发者ID:bbqsrc,项目名称:robust-android,代码行数:10,代码来源:MessengerChannelHandler.java

示例10: exceptionCaught

import io.netty.channel.ConnectTimeoutException; //导入依赖的package包/类
@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
    String message = null;
    if(cause instanceof ConnectTimeoutException || (cause instanceof ConnectException && cause.getMessage().contains("connection timed out"))) {
        message = "Connection timed out.";
    } else if(cause instanceof ReadTimeoutException) {
        message = "Read timed out.";
    } else if(cause instanceof WriteTimeoutException) {
        message = "Write timed out.";
    } else {
        message = cause.toString();
    }

    this.disconnect(message, cause);
}
 
开发者ID:Steveice10,项目名称:PacketLib,代码行数:16,代码来源:TcpSession.java

示例11: userEventTriggered

import io.netty.channel.ConnectTimeoutException; //导入依赖的package包/类
@Override
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
    if (evt instanceof SslHandshakeCompletionEvent) {
        if (((SslHandshakeCompletionEvent)evt).isSuccess()) {
            if (debug) {
                log.debug("SSL connection established [to={}]", id);
            }

            handshake(ctx);
        }

        super.userEventTriggered(ctx, evt);
    } else if (evt instanceof AutoReadChangeEvent) {
        if (evt == AutoReadChangeEvent.PAUSE) {
            // Completely ignore read timeouts.
            ignoreTimeouts = -1;
        } else {
            // Ignore next timeout.
            ignoreTimeouts = 1;
        }
    } else if (evt instanceof IdleStateEvent) {
        if (state == CONNECTING || state == CONNECTED) {
            IdleStateEvent idle = (IdleStateEvent)evt;

            if (idle.state() == IdleState.WRITER_IDLE) {
                if (hbFlushed) {
                    // Make sure that we don't push multiple heartbeats to the network buffer simultaneously.
                    // Need to perform this check since remote peer can hang and stop reading
                    // while this channel will still be trying to put more and more heartbeats on its send buffer.
                    hbFlushed = false;

                    ctx.writeAndFlush(Heartbeat.INSTANCE).addListener(hbOnFlush);
                }
            } else {
                // Reader idle.
                // Ignore if auto-reading was disabled since in such case we will not read any heartbeats.
                if (ignoreTimeouts != -1 && ctx.channel().config().isAutoRead()) {
                    // Check if timeout should be ignored.
                    if (ignoreTimeouts > 0) {
                        // Decrement the counter of ignored timeouts.
                        ignoreTimeouts--;
                    } else {
                        if (state == CONNECTING) {
                            ctx.fireExceptionCaught(new ConnectTimeoutException("Timeout while connecting to " + id));
                        } else if (state == CONNECTED) {
                            ctx.fireExceptionCaught(new SocketTimeoutException("Timeout while reading data from " + id));
                        }
                    }
                }
            }
        }
    } else {
        super.userEventTriggered(ctx, evt);
    }
}
 
开发者ID:hekate-io,项目名称:hekate,代码行数:56,代码来源:NettyClientHandler.java


注:本文中的io.netty.channel.ConnectTimeoutException类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。