Logo Search packages:      
Sourcecode: acgvision-agent version File versions  Download package

static boolean com::acgvision::agent::run::Main::init (  )  [inline, static, private]

Logs user and registers a server.

Returns:
true on success

Definition at line 124 of file Main.java.

References getConfigFile(), com::acgvision::agent::action::Send::getHost(), com::acgvision::core::ws::Host::getId(), com::acgvision::agent::action::Send::init(), com::acgvision::agent::action::Send::log(), logger, com::acgvision::core::ws::User::setEmail(), and com::acgvision::core::ws::Host::setId().

Referenced by main().

                                  {
        final String SERVERSECTIONNAME = "Server";
        final String SERVERKEYIDNAME = "address";
        final String SERVERKEYPROTOCOLENAME = "protocole";
        final String SERVERKEYPORTNAME = "port";
        final String HOSTMEASURETIMEBUFFER = "measurebuffer";
        final String SERVERKEYPROXYHOST = "proxyhost";
        final String SERVERKEYPROXYPORT = "proxyport";
        final String SERVERKEYPROXYUSER = "proxyuser";
        final String SERVERKEYPROXYPASSWORD = "proxypassword";

        String server =getConfigFile().getSection(SERVERSECTIONNAME).getString(SERVERKEYIDNAME,"localhost");
        if(server.isEmpty()){
            logger.info("Web service Server invalid");
            return false;
        }
        String port =getConfigFile().getSection(SERVERSECTIONNAME).getString(SERVERKEYPORTNAME,"8080");
        if(port.isEmpty()){
            logger.info("Web service port invalid");
            return false;
        }
        String protocole =getConfigFile().getSection(SERVERSECTIONNAME).getString(SERVERKEYPROTOCOLENAME,"http");
        if(protocole.isEmpty()){
            logger.info("Web service protocole invalid");
            return false;
        }
        
        //******************** PROXY

        String proxyhost =getConfigFile().getSection(SERVERSECTIONNAME).getString(SERVERKEYPROXYHOST,"");
        if(!protocole.isEmpty()){
            String proxyport =getConfigFile().getSection(SERVERSECTIONNAME).getString(SERVERKEYPROXYPORT,"3128");
            String proxyuser =getConfigFile().getSection(SERVERSECTIONNAME).getString(SERVERKEYPROXYUSER,"");
            String proxypassword =getConfigFile().getSection(SERVERSECTIONNAME).getString(SERVERKEYPROXYPASSWORD,"");
            if(logger.isInfoEnabled()){
                logger.info("Using proxy with values :"+
                        "\n host: "+proxyhost+
                        "\n port: "+proxyport +
                        "\n proxyuser: "+proxyuser +
                        "\n proxyport: "+proxypassword);
            }
            System.setProperty("proxySet", "true");
            System.setProperty("http.proxyHost", proxyhost);
            System.setProperty("http.proxyPort",proxyport);
            if(!proxyuser.isEmpty()){
            System.setProperty("http.proxyUser",proxyuser);
            System.setProperty("http.proxyPassword", proxypassword);
            }
        }
        sender.init(protocole +"://"+server+":"+port+"/corews/AgentService?wsdl");
        String useremail = getConfigFile().getSection("User").getString("email", null);
        if (useremail == null) {
            logger.fatal("Please Initialize User email in configuration file.");
            return false;
        }
       if(logger.isInfoEnabled()) logger.info("Read email: " + useremail);
        User user = new User();
        user.setEmail(useremail);
        user = sender.log(user);
        if (user == null){
            return false;
        }
        host = new Host();
        host.setId(getConfigFile().getSection(HOSTSECTIONNAME).getLong(HOSTKEYIDNAME,-1));

        if (host.getId() == -1) {
            logger.warn("Registering new host");
            RegisterNewHost(user);
        } else {
           if(logger.isInfoEnabled()) logger.info("Getting host" + host.getId() +" informations");
            host = sender.getHost(host.getId());
            if (host == null) {
                logger.info("Host id is not valid, trying to get new one.");
                RegisterNewHost(user);
            }
        }
        if (host == null) {
            logger.fatal("Error while getting host.");
            return false;
        }
        Main.measuresSpooler = new MeasureSpooler (sender);
        Main.measuresSpooler.setSendingFrequence(getConfigFile().getSection(HOSTSECTIONNAME).getLong(HOSTMEASURETIMEBUFFER,60000L));
        if (logger.isInfoEnabled()){
            logger.info("Send measures every " + Main.measuresSpooler.getSendingFrequence()/1000 + " seconds.");
        }
        Main.measuresSpooler.generateNextTimeToSend();
        return true;
    }


Generated by  Doxygen 1.6.0   Back to index