package com.gyee.edge.gateway.client;

import com.gyee.edge.gateway.config.cache.CacheService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 通过Endpoint，创建Client对象，并将Client对象放入ClientManager
 */
@Component
public class ClientFactory {

    @Autowired
    CacheService cacheService;

    @Autowired
    ClientManager clientManager;


    public void CreateClients() {
        List<EndPoint> endPoints = cacheService.getEndPointList();
        for(EndPoint endPoint : endPoints) {
            if (endPoint.getDirection() == 0) {
                IClient iClient = createClient(endPoint);
                clientManager.addClient(iClient);
            }
        }

    }

    public IClient createClient(EndPoint endPoint) {
        //todo: 通过endpoint生成不同的IClient
        return new IEC102TcpClient();
    }






}
