Example usage for io.netty.channel ConnectTimeoutException ConnectTimeoutException

List of usage examples for io.netty.channel ConnectTimeoutException ConnectTimeoutException

Introduction

In this page you can find the example usage for io.netty.channel ConnectTimeoutException ConnectTimeoutException.

Prototype

public ConnectTimeoutException(String msg) 

Source Link

Usage

From source file:io.grpc.netty.UtilsTest.java

License:Apache License

@Test
public void testStatusFromThrowable() {
    Status s = Status.CANCELLED.withDescription("msg");
    assertSame(s, Utils.statusFromThrowable(new Exception(s.asException())));
    Throwable t;/*from ww w.  j a v a2 s  .  c  o  m*/
    t = new ConnectTimeoutException("msg");
    assertStatusEquals(Status.UNAVAILABLE.withCause(t), Utils.statusFromThrowable(t));
    t = new Http2Exception(Http2Error.INTERNAL_ERROR, "msg");
    assertStatusEquals(Status.INTERNAL.withCause(t), Utils.statusFromThrowable(t));
    t = new Exception("msg");
    assertStatusEquals(Status.UNKNOWN.withCause(t), Utils.statusFromThrowable(t));
}

From source file:io.hekate.network.netty.NettyClientTimeoutHandler.java

License:Apache License

@Override
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
    if (evt instanceof NettyClientHandshakeEvent) {
        NettyClientHandshakeEvent handshake = (NettyClientHandshakeEvent) evt;

        handshakeDone = true;/*from  w  ww  .  j a  va2 s .  c  o  m*/

        // Unregister connect timeout handler.
        if (ctx.pipeline().get(CONNECT_TIMEOUT_HANDLER_ID) != null) {
            ctx.pipeline().remove(CONNECT_TIMEOUT_HANDLER_ID);
        }

        // Register heartbeat handler.
        mayBeRegisterHeartbeatHandler(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;
        }

        super.userEventTriggered(ctx, evt);
    } else if (evt instanceof IdleStateEvent) {
        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 (handshakeDone) {
                        ctx.fireExceptionCaught(
                                new SocketTimeoutException("Timeout while reading data from " + id));
                    } else {
                        ctx.fireExceptionCaught(
                                new ConnectTimeoutException("Timeout while connecting to " + id));
                    }
                }
            }
        }
    } else {
        super.userEventTriggered(ctx, evt);
    }
}

From source file:org.apache.tajo.rpc.RpcConnectionPool.java

License:Apache License

public NettyClientBase getConnection(InetSocketAddress addr, Class<?> protocolClass, boolean asyncMode,
        long timeout, long interval)
        throws NoSuchMethodException, ClassNotFoundException, ConnectTimeoutException {
    RpcConnectionKey key = new RpcConnectionKey(addr, protocolClass, asyncMode);

    RpcUtils.Timer timer = new RpcUtils.Timer(timeout);
    for (; !timer.isTimedOut(); timer.elapsed()) {
        NettyClientBase client;/*from  w ww  .  jav a 2  s.com*/
        synchronized (lockObject) {
            client = connections.get(key);
            if (client == null) {
                connections.put(key, client = makeConnection(key));
            }
        }
        if (client.acquire(timer.remaining())) {
            return client;
        }
        timer.interval(interval);
    }

    throw new ConnectTimeoutException("Failed to get connection for " + timeout + " msec");
}

From source file:org.openremote.agent.protocol.NrJavaSerialChannel.java

License:Open Source License

@Override
protected void doConnect(SocketAddress remoteAddress, SocketAddress localAddress) throws Exception {
    NrJavaSerialAddress remote = (NrJavaSerialAddress) remoteAddress;
    final NRSerialPort serial = new NRSerialPort(remote.value(), remote.getBaudRate());
    serial.connect();/*  www  .j  ava2s . c  om*/
    serialPort = serial.getSerialPortInstance();
    if (serialPort == null) {
        // No exception is thrown on connect failure so throw one
        throw new ConnectTimeoutException("Failed to establish connection to COM port: " + remote.value());
    }
    serialPort.enableReceiveTimeout(config().getOption(io.netty.channel.rxtx.RxtxChannelOption.READ_TIMEOUT));
    deviceAddress = remote;
}