protected int initiateConnect()

in gflog-core/src/main/java/com/epam/deltix/gflog/core/appender/TcpAppender.java [109:143]


    protected int initiateConnect() {
        final long now = System.currentTimeMillis();
        int workDone = 0;

        if (now >= connectTime + reconnectPeriod) {
            try {
                connectTime = now;
                state = STATE_CONNECTING;

                final InetSocketAddress address = new InetSocketAddress(host, port);

                channel = SocketChannel.open();
                channel.setOption(StandardSocketOptions.TCP_NODELAY, socketTcpNoDelay);

                if (socketSendBufferCapacity > 0) {
                    channel.setOption(StandardSocketOptions.SO_SNDBUF, socketSendBufferCapacity);
                }

                if (socketReceiveBufferCapacity > 0) {
                    channel.setOption(StandardSocketOptions.SO_RCVBUF, socketReceiveBufferCapacity);
                }

                channel.configureBlocking(false);
                channel.connect(address);

                workDone++;
            } catch (final Throwable e) {
                reconnectPeriod = Math.min(2 * reconnectPeriod, reconnectMaxPeriod);
                disconnect();
                LogDebug.warn("can't connect to: " + host + ":" + port + ". Error: " + e.getMessage());
            }
        }

        return workDone;
    }