All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.rx.net.rpc.NonClientPool Maven / Gradle / Ivy

There is a newer version: 3.0.0
Show newest version
package org.rx.net.rpc;

import lombok.RequiredArgsConstructor;
import org.rx.core.Sys;
import org.rx.exception.InvalidException;
import org.rx.net.transport.StatefulTcpClient;
import org.rx.net.transport.TcpClientConfig;

import java.util.concurrent.TimeoutException;

@RequiredArgsConstructor
class NonClientPool implements TcpClientPool {
    private final TcpClientConfig template;

    @Override
    public StatefulTcpClient borrowClient() {
        TcpClientConfig config = Sys.deepClone(template);
        StatefulTcpClient client = new StatefulTcpClient(config);
        try {
            client.connect(config.getServerEndpoint());
        } catch (TimeoutException e) {
            if (!config.isEnableReconnect()) {
                throw InvalidException.sneaky(e);
            }
        }
        return client;
    }

    @Override
    public StatefulTcpClient returnClient(StatefulTcpClient client) {
        return client;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy