Search in sources :

Example 1 with ServerListFactory

use of com.alibaba.nacos.common.remote.client.ServerListFactory in project nacos by alibaba.

the class ClusterRpcClientProxy method createRpcClientAndStart.

private void createRpcClientAndStart(Member member, ConnectionType type) throws NacosException {
    Map<String, String> labels = new HashMap<String, String>(2);
    labels.put(RemoteConstants.LABEL_SOURCE, RemoteConstants.LABEL_SOURCE_CLUSTER);
    String memberClientKey = memberClientKey(member);
    RpcClient client = buildRpcClient(type, labels, memberClientKey);
    if (!client.getConnectionType().equals(type)) {
        Loggers.CLUSTER.info(",connection type changed,destroy client of member - > : {}", member);
        RpcClientFactory.destroyClient(memberClientKey);
        client = buildRpcClient(type, labels, memberClientKey);
    }
    if (client.isWaitInitiated()) {
        Loggers.CLUSTER.info("start a new rpc client to member - > : {}", member);
        // one fixed server
        client.serverListFactory(new ServerListFactory() {

            @Override
            public String genNextServer() {
                return member.getAddress();
            }

            @Override
            public String getCurrentServer() {
                return member.getAddress();
            }

            @Override
            public List<String> getServerList() {
                return CollectionUtils.list(member.getAddress());
            }
        });
        client.start();
    }
}
Also used : ServerListFactory(com.alibaba.nacos.common.remote.client.ServerListFactory) HashMap(java.util.HashMap) List(java.util.List) RpcClient(com.alibaba.nacos.common.remote.client.RpcClient)

Aggregations

RpcClient (com.alibaba.nacos.common.remote.client.RpcClient)1 ServerListFactory (com.alibaba.nacos.common.remote.client.ServerListFactory)1 HashMap (java.util.HashMap)1 List (java.util.List)1