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

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

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

import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.Setter;
import lombok.ToString;
import org.rx.net.Sockets;
import org.rx.net.transport.StatefulTcpClient;
import org.rx.net.transport.TcpClientConfig;
import org.rx.util.function.TripleAction;

import java.net.InetSocketAddress;

@RequiredArgsConstructor
@Getter
@Setter
@ToString
public class RpcClientConfig {
    private static final long serialVersionUID = -4952694662640163676L;
    public static final int NON_POOL_SIZE = -1;
    public static final int DEFAULT_VERSION = 0;

    public static  RpcClientConfig statefulMode(String serverEndpoint, int eventVersion) {
        return statefulMode(Sockets.parseEndpoint(serverEndpoint), eventVersion);
    }

    public static  RpcClientConfig statefulMode(InetSocketAddress serverEndpoint, int eventVersion) {
        TcpClientConfig tcpClientConfig = new TcpClientConfig();
        tcpClientConfig.setServerEndpoint(serverEndpoint);
        tcpClientConfig.setEnableReconnect(true);
        RpcClientConfig config = new RpcClientConfig<>(tcpClientConfig);
        config.setEventVersion(eventVersion);
        return config;
    }

    public static  RpcClientConfig poolMode(String serverEndpoint, int maxPoolSize) {
        return poolMode(Sockets.parseEndpoint(serverEndpoint), 2, maxPoolSize);
    }

    public static  RpcClientConfig poolMode(InetSocketAddress serverEndpoint, int minPoolSize, int maxPoolSize) {
        TcpClientConfig tcpClientConfig = new TcpClientConfig();
        tcpClientConfig.setServerEndpoint(serverEndpoint);
        tcpClientConfig.setEnableReconnect(false);
        RpcClientConfig config = new RpcClientConfig<>(tcpClientConfig);
        config.setMinPoolSize(minPoolSize);
        config.setMaxPoolSize(maxPoolSize);
        return config;
    }

    private final TcpClientConfig tcpConfig;
    private int eventVersion = DEFAULT_VERSION;
    private int minPoolSize;
    private int maxPoolSize = NON_POOL_SIZE;
    private TripleAction initHandler;

    public boolean isUsePool() {
        return maxPoolSize > NON_POOL_SIZE;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy