package com.cisdi.data.OBLF.test;

import com.cisdi.data.OBLF.impl.OBLFChannelInitializer;
import com.cisdi.data.OBLF.impl.OBLFSessionFactory;
import com.cisdi.data.sdk.enums.ByteOrder;
import com.cisdi.data.sdk.gateway.netty.SessionFactory;
import com.cisdi.data.sdk.gateway.netty.TcpIoService;
import com.cisdi.data.sdk.gateway.netty.impl.DefaultTcpIoService;
import com.cisdi.data.sdk.vo.GatewayVo;
import io.netty.handler.ssl.OpenSsl;
import lombok.extern.slf4j.Slf4j;

/**
 * @author cuianbing
 * @version 1.0
 * @description: TODO
 * @date 2021/7/7 19:28
 */
@Slf4j
public class StartTest {

    private static TcpIoService ioService = null;

    private static SessionFactory sessionFactory = null;

    public static void main(String[] args) {
        boolean available = OpenSsl.isAvailable();
        log.info("openssl available={}", available);

        DefaultTcpIoService defaultIoService = new DefaultTcpIoService();

        SessionFactory factory = new OBLFSessionFactory(null);

        ServiceProviderTest testServiceProvider = new ServiceProviderTest();

        factory.init(testServiceProvider, null);

        OBLFChannelInitializer channelInitializer =
                new OBLFChannelInitializer(factory, ByteOrder.BIGENDIAN, null);

        GatewayVo instanceVo = new GatewayVo();
        instanceVo.setByteOrder(ByteOrder.BIGENDIAN);
        instanceVo.setParameter("{\"listenIp\":\"0.0.0.0\",\"listenPort\":8888,\"threadSize\":50,\"timeout\":2000}");

        defaultIoService.init(instanceVo, factory, channelInitializer);

        ioService = defaultIoService;
        sessionFactory = factory;

        boolean open = ioService.open();

        if (open == true) {
            log.info("plc网关启动成功");
        } else {
            log.info("plc网关启动失败");
        }

        try {
            Thread.sleep(10000000);
        } catch (InterruptedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
}
