Main.java 3.6 KB
//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.airport;

import com.airport.core.AgentSender;
import com.airport.core.IMFReader;
import com.airport.core.IMFSender;
import com.airport.util.ConfigUtils;
import com.airport.util.SystemBean;
import com.caac.imf.api.IMFClient;
import com.caac.imf.api.IMFClientFactory;
import java.util.Timer;
import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator;
import sun.management.Agent;

public class Main {
    private static final Logger logger = Logger.getLogger(Main.class);
    public static boolean LOGIN_OK = false;
    public static boolean isSuc = true;
    public static IMFClient client = null;


    public Main() {
    }

    private static void start() throws Exception {
        PropertyConfigurator.configure("config/log4j.properties");
        SystemBean.createInstance("config/ApplicationContext.xml");
        ConfigUtils conf = new ConfigUtils();
        conf.Initialize();
        client = IMFClientFactory.createInstance();
        if ("R".equalsIgnoreCase(ConfigUtils.ROLE)) {
            if (client != null) {
                IMFReader reader = new IMFReader(client);
                reader.start();
            }

            loginIMF(client, ConfigUtils.IMF_USERNAME, ConfigUtils.IMF_PASSWORD, "config/imf_config.properties");
        } else if ("S".equalsIgnoreCase(ConfigUtils.ROLE)) {
            loginIMF(client, ConfigUtils.IMF_USERNAME, ConfigUtils.IMF_PASSWORD, "config/imf_config.properties");
            if (LOGIN_OK && client != null) {
                logger.info("start run Timer,client hasocde=" + client.hashCode());

                //代理人发送程序
//                AgentSender send = new AgentSender(client);
//                send.start();

                //数据仓库给九州的发送程序
                Timer timer = new Timer();
                IMFSender CangKu2Jiuzhou = new IMFSender(client,"data/fid_index.txt");
                timer.schedule(CangKu2Jiuzhou, 30000L, 1200000L);

            }
        }

    }

    private static void loginIMF(IMFClient client, String userName, String password, String confFileName) {
        if (client.initial(confFileName)) {
            String message = client.login(userName, password);
            logger.info("message=" + message);
            if (message.indexOf("<CODE>1</CODE>") > 0) {
                logger.info("登陆成功");
                LOGIN_OK = true;
            } else {
                int times = 0;

                while(times <= 3) {
                    logger.info("try connection...");
                    ++times;
                    logger.info("message.=" + message);
                    if (message.indexOf("<CODE>1</CODE>") > 0) {
                        logger.info("登陆成功");
                        LOGIN_OK = true;
                        break;
                    }

                    logger.info("登录失败~~~~");
                    message = client.login(userName, password);

                    try {
                        Thread.sleep(4000L);
                    } catch (InterruptedException var7) {
                        var7.printStackTrace();
                    }
                }

                if (!LOGIN_OK) {
                    logger.info("多次尝试登录失败,退出登陆");
                    client.disconnect();
                    isSuc =false;
                    System.exit(-1);
                }
            }
        }

    }

    public static void main(String[] args) throws Exception {
        start();
    }
}