审查视图

src/java/com/airport/Main.java 4.1 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.IMFNoDelaySender;
朱兆平 authored
10
import com.airport.core.IMFReader;
朱兆平 authored
11
import com.airport.core.IMFSender;
朱兆平 authored
12 13 14 15 16 17 18
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;
19
import sun.management.Agent;
朱兆平 authored
20 21 22 23

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

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

                //数据仓库给九州的发送程序
朱兆平 authored
54
                Timer timer = new Timer();
55 56 57 58 59

                //从配置文件读取sql语句,发送货运数据
                String sql_select=ConfigUtils.SQl;
                String sqlmax = ConfigUtils.SQlMax;
                IMFNoDelaySender CangKu2Jiuzhou = new IMFNoDelaySender(client,"data/fid_index.txt",sql_select,sqlmax);
朱兆平 authored
60
                CangKu2Jiuzhou.start();
61 62 63 64 65 66

                //发送通关数据
                String sql_select1=ConfigUtils.SQl1;
                String sqlmax1 = ConfigUtils.SQlMax1;
                IMFNoDelaySender CangKu2Jiuzhou_tg = new IMFNoDelaySender(client,"data/fid_index.txt",sql_select1,sqlmax1);
                CangKu2Jiuzhou_tg.start();
朱兆平 authored
67
//                timer.schedule(CangKu2Jiuzhou, 10000L, 1200000L);
68
朱兆平 authored
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 95 96 97 98 99 100 101 102 103 104 105 106
            }
        }

    }

    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();
107
                    isSuc =false;
朱兆平 authored
108 109 110 111 112 113 114 115 116 117 118
                    System.exit(-1);
                }
            }
        }

    }

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