 package com.cisdi.data.HJ212.gateway;

import java.util.concurrent.atomic.AtomicBoolean;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.cisdi.data.HJ212.YfHj212SocketGateway;
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;

public class StartHj212Test {
     private static Logger logger = LoggerFactory.getLogger(YfHj212SocketGateway.class);
     
     private static TcpIoService ioService = null;
     @SuppressWarnings("unused")
     private static SessionFactory sessionFactory = null;
     
     public static void main(String[] args) {       
         DefaultTcpIoService defaultIoService = new DefaultTcpIoService();
         SessionFactory factory = new Hj212SessionFactory("10000022");
         
         factory.init(null, null);
         
         Hj212ChannelInitializer<Hj212FrameInputVo> channelInitializer = 
                 new Hj212ChannelInitializer<Hj212FrameInputVo>(factory);
         
         GatewayVo instanceVo = new GatewayVo();
         instanceVo.setByteOrder(ByteOrder.BIGENDIAN);
         instanceVo.setParameter("{\"listenIp\":\"0.0.0.0\",\"listenPort\":9010,\"threadSize\":50,\"timeout\":2000}");
         
         defaultIoService.init(instanceVo, factory, channelInitializer);
         
         ioService = defaultIoService;
         sessionFactory = factory;
         
         boolean open = ioService.open();
         
         if(open == true) {
             
             AtomicBoolean shouldRun = new AtomicBoolean(true);
             AliveCheckTask task = new AliveCheckTask(120, shouldRun, factory);
             
             Thread thread = new Thread(task, "Hj212-alive-check-thread");
             thread.start();
             
             logger.info("Hj212网关启动成功");
         }else {
             logger.info("Hj212网关启动失败");
         }
         
         try {
             Thread.sleep(10000000);
         } catch (InterruptedException e) {
             // TODO Auto-generated catch block
             e.printStackTrace();
         }
     }
}
