审查视图

src/java/com/airport/Main.java 3.6 KB
朱兆平 authored
1 2 3 4 5 6 7
//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.airport;
8
import com.airport.core.AgentSender;
朱兆平 authored
9
import com.airport.core.IMFReader;
朱兆平 authored
10
import com.airport.core.IMFSender;
朱兆平 authored
11 12 13 14 15 16 17
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;
18
import sun.management.Agent;
朱兆平 authored
19 20 21 22

public class Main {
    private static final Logger logger = Logger.getLogger(Main.class);
    public static boolean LOGIN_OK = false;
23
    public static boolean isSuc = true;
朱兆平 authored
24 25
    public static IMFClient client = null;
26
朱兆平 authored
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
    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());
47 48 49 50 51 52

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

                //数据仓库给九州的发送程序
朱兆平 authored
53
                Timer timer = new Timer();
54 55 56
                IMFSender CangKu2Jiuzhou = new IMFSender(client,"data/fid_index.txt");
                timer.schedule(CangKu2Jiuzhou, 30000L, 1200000L);
朱兆平 authored
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
            }
        }

    }

    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();
95
                    isSuc =false;
朱兆平 authored
96 97 98 99 100 101 102 103 104 105 106
                    System.exit(-1);
                }
            }
        }

    }

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