Example usage for java.net UnknownHostException getStackTrace

List of usage examples for java.net UnknownHostException getStackTrace

Introduction

In this page you can find the example usage for java.net UnknownHostException getStackTrace.

Prototype

public StackTraceElement[] getStackTrace() 

Source Link

Document

Provides programmatic access to the stack trace information printed by #printStackTrace() .

Usage

From source file:com.cablelabs.fsm.AutoProvState.java

private String autoGenerate(int msgIndexQueue) {
    Properties platform = SystemSettings.getSettings(SettingConstants.PLATFORM);
    Properties dut = SystemSettings.getSettings(SettingConstants.DUT);
    Boolean autoProv = SystemSettings.getBooleanSetting(SettingConstants.AUTO_GENERATE);
    Boolean autoGen = SystemSettings.getBooleanSetting(SettingConstants.AUTO_PROVISION);
    if (autoProv && autoGen) {
        if (pd != null && platform != null && dut != null) {
            String pcscfLabel = dut.getProperty(SettingConstants.PCSCF);
            String macAddr = dut.getProperty(SettingConstants.MAC_ADDRESS);
            String tftpIP = platform.getProperty(SettingConstants.TFTP_SERVER_IP);
            String tftpPort = platform.getProperty(SettingConstants.TFTP_SERVER_PORT);
            String phone1 = dut.getProperty(SettingConstants.PHONE_NUMBER_1);
            String phone2 = dut.getProperty(SettingConstants.PHONE_NUMBER_2);
            String cw = platform.getProperty(SettingConstants.CW_NUMBER);
            if (macAddr != null && pcscfLabel != null && tftpIP != null && tftpPort != null && cw != null) {

                // Next verify the port is not set to zero
                try {
                    int port = Integer.parseInt(tftpPort);
                    if (port > 0 && port <= 65535) {

                        // Next make sure the TFTP Server IP is not set to 0.0.0.0
                        if (tftpIP.equals("0.0.0.0")) {
                            logger.warn(PC2LogCategory.PCSim2, subCat,
                                    "The TFTP Server IP setting in the platform file is not valid. Ending auto generate operation.");
                            return null;
                        }/*from   w ww  .  ja v  a  2s.  co  m*/

                        File input = new File(SettingConstants.AUTO_PROV_FILE_DIRECTORY + File.separator
                                + SettingConstants.CW + cw + File.separator + pd.getProvFileName());
                        if (input != null) {
                            ProvGen pg = new ProvGen(input);
                            if (phone1 != null)
                                pg.changePhoneNum(SettingConstants.AUTO_GENERATE_PHONE_NUMBER_1, phone1);
                            if (phone2 != null)
                                pg.changePhoneNum(SettingConstants.AUTO_GENERATE_PHONE_NUMBER_2, phone2);
                            Properties pcscf = SystemSettings.getSettings(pcscfLabel);
                            if (pcscf != null) {
                                String pcscfIP = pcscf.getProperty(SettingConstants.IP);
                                if (pcscfIP != null)
                                    pg.changePCSCF(pcscfIP);
                            }
                            String newFileName = macAddr + ".bin";
                            if (pg.output(SettingConstants.AUTO_PROV_FILE_DIRECTORY + File.separator
                                    + SettingConstants.CW + cw + File.separator + newFileName)) {
                                // Test system
                                //File output = new File(SettingConstants.AUTO_PROV_FILE_DIRECTORY + newFileName);
                                //File pact = new File(SettingConstants.AUTO_PROV_FILE_DIRECTORY + "chinmaya_base_ph1_pcscf.bin");
                                //pg.compare(pact, output);
                                // Create a data entry of the issued event
                                //ProvisioningData issuePD = new ProvisioningData(macAddr, pd.getPolicyFileName(), newFileName);
                                logger.info(PC2LogCategory.FSM, subCat,
                                        "AutoProvState beginning to TFTP the new provisioning file.");

                                // Next we need to TFTP the file to the server
                                TFTPClient client = new TFTPClient();
                                File binFile = new File(
                                        SettingConstants.AUTO_PROV_FILE_DIRECTORY + File.separator
                                                + SettingConstants.CW + cw + File.separator + newFileName);
                                if (binFile.isFile() && binFile.canRead()) {
                                    FileInputStream istrm = new FileInputStream(binFile);
                                    //InetAddress ia = InetAddress.getByName("10.4.1.37");
                                    client.open(); // client.open(20003, ia);
                                    client.sendFile(newFileName, TFTP.BINARY_MODE, istrm, tftpIP, port);
                                    client.close();
                                    logger.info(PC2LogCategory.FSM, subCat,
                                            "TFTP of the new provisioning file is complete.");
                                    super.processPrelude(msgIndexQueue);
                                } else {
                                    logger.warn(PC2LogCategory.FSM, subCat,
                                            "The " + macAddr + ".bin doesn't appear in the "
                                                    + SettingConstants.AUTO_PROV_FILE_DIRECTORY + File.separator
                                                    + SettingConstants.CW + cw
                                                    + " Ending auto generate operation.");
                                }
                            } else {
                                logger.error(PC2LogCategory.FSM, subCat,
                                        "AutoProvState could not locate provisioning template file["
                                                + input.getAbsolutePath() + "].");
                            }
                        }
                        //                  else {
                        //                     logger.info(PC2LogCategory.FSM, subCat, "AutoProvState is terminating because the input directory is null.");
                        //                  }
                    } else {
                        logger.info(PC2LogCategory.PCSim2, subCat,
                                "AutoProvState is terminating because the port(" + port
                                        + ") is less than 0 or greater than 65535.");
                    }
                } catch (NumberFormatException nfe) {
                    logger.warn(PC2LogCategory.FSM, subCat,
                            "AutoProvState is not auto generating a provisioning file because the "
                                    + "TFTP Server Port setting doesn't appear to be a number.");
                } catch (UnknownHostException uhe) {
                    logger.warn(PC2LogCategory.FSM, subCat,
                            "AutoProvState is not auto generating a provisioning file because the "
                                    + "system encountered an error when attempting to send the file to the TFTP Server.\n"
                                    + uhe.getMessage() + "\n" + uhe.getStackTrace());
                } catch (IOException ioe) {
                    logger.warn(PC2LogCategory.FSM, subCat,
                            "AutoProvState is not auto generating a provisioning file because the "
                                    + "system encountered an error when attempting to send the file to the TFTP Server.\n"
                                    + ioe.getMessage() + "\n" + ioe.getStackTrace());
                }

            } else {
                logger.info(PC2LogCategory.FSM, subCat,
                        "AutoProvState is stopping because one of the values is null.\n" + "macAddr=" + macAddr
                                + " pcscfLabel=" + pcscfLabel + " tftpIP=" + tftpIP + " tftpPort=" + tftpPort);
            }
        } else {
            if (pd != null)
                logger.info(PC2LogCategory.FSM, subCat,
                        "The provisioning data is null, terminating processing.");
            if (platform != null)
                logger.info(PC2LogCategory.FSM, subCat,
                        "The Platform settings is null, terminating processing.");
            if (dut != null)
                logger.info(PC2LogCategory.FSM, subCat, "The DUT settings is null, terminating processing.");
        }
    } else {
        Generate g = new Generate(EventConstants.AUTO_PROV_PROMPT, null, this.owner.getName());
        try {
            g.execute(super.api, 0);
        } catch (PC2Exception pce) {
            logger.error(PC2LogCategory.FSM, subCat,
                    name + " couldn't generate " + EventConstants.AUTO_PROV_PROMPT + " event to the FSM.");
        }
    }

    return null;
}

From source file:com.cablelabs.sim.PCSim2.java

/**
 * This method creates the T.I.M results file for the a specific
 * test case./*w  w w . j  a v a  2  s .  c  o m*/
 */
private void generateResults(TSDocument doc) {
    String fileName = doc.getLogFileName();
    int index = fileName.lastIndexOf("_ss.log");
    String timFileName = fileName.substring(0, index) + "_ss.res";
    File tim = new File(timFileName);
    if (!tim.exists()) {
        Properties platform = SystemSettings.getSettings(SettingConstants.PLATFORM);
        Properties dut = SystemSettings.getSettings("DUT");
        try {
            FileOutputStream output = null;
            if (tim.createNewFile()) {
                output = new FileOutputStream(tim);
            } else {
                output = new FileOutputStream((timFileName + "_" + System.currentTimeMillis()));
            }

            String testerName = platform.getProperty(SettingConstants.TESTER_NAME);
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
            Date stop = new Date();
            String cw = platform.getProperty(SettingConstants.CW_NUMBER);
            if (!cw.startsWith("CW"))
                cw = "CW" + cw;
            String result = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
                    + "<res-document xmlns=\"http://cablelabs.com/TEPResultDocument\" version=\"1.0\">\n\t"
                    + "<execution method=\"automatic\" start=\"" + sdf.format(doc.getStart()) + "\" stop=\""
                    + sdf.format(stop) + "\" />\n\t" + "<tester username=\"" + testerName + "\" />\n\t"
                    + "<certwave name=\"" + cw + "\" />\n\t" + "<test-result type=\""
                    + platform.getProperty(SettingConstants.DUT_SUBGROUP) + "\" name=\"" + doc.getNumber()
                    + "\"\n\tproduct=\"" + dut.getProperty(SettingConstants.DUT_VENDOR) + "\" result=\""
                    + ((testPassed == null || testPassed) ? "PASS" : "FAIL") + "\"\n\tunit=\""
                    + dut.getProperty(SettingConstants.PRODUCT_UNIT) + "\"/>\n" + "</res-document>";
            if (output != null) {
                output.write(result.getBytes());
                output.close();
            }
            //            else 
            //               logger.fatal(PC2LogCategory.Parser, subCat,
            //                     "Couldn't write TIM file! Writing to log file for preservation!\n" + result);
        } catch (IOException ioe) {
            logger.error(PC2LogCategory.Parser, subCat, "Could not create new TIM file[" + timFileName + "].");
        }

        String tftpIP = platform.getProperty(SettingConstants.TFTP_SERVER_IP);
        String tftpPort = platform.getProperty(SettingConstants.TFTP_SERVER_PORT);

        if (tftpIP != null && tftpPort != null) {
            boolean recProv = SystemSettings
                    .resolveBooleanSetting(platform.getProperty(SettingConstants.RECORD_PROVISIONING_FILE));
            if (recProv && dut != null)
                try {
                    RecordProvFileListener rpfl = new RecordProvFileListener();
                    boolean success = rpfl.run();
                    String provFile = rpfl.getValue();
                    if (success) {

                        int port = Integer.parseInt(tftpPort);
                        if (port > 0 && port <= 65535) {

                            // Next make sure the TFTP Server IP is not set to 0.0.0.0
                            if (tftpIP.equals("0.0.0.0")) {
                                logger.warn(PC2LogCategory.PCSim2, subCat,
                                        "The TFTP Server IP setting in the platform file is not valid. Ending auto generate operation.");
                            } else {
                                // Next we need to TFTP the file from the server
                                TFTPClient client = new TFTPClient();
                                int dirIndex = fileName.lastIndexOf("/", index);
                                File dir = new File(fileName.substring(0, dirIndex) + PROV_FILE_DIRECTORY);
                                if (dir.exists() && !dir.isDirectory()) {
                                    logger.error(PC2LogCategory.PCSim2, subCat, "The path " + dir.getPath()
                                            + " is not a directory. Terminating the recording of the provisioning file.");
                                }
                                File binFile = new File(fileName.substring(0, dirIndex + 1)
                                        + PROV_FILE_DIRECTORY + File.separator
                                        + fileName.substring(dirIndex + 1, index) + "_prov.bin");
                                boolean exists = false;
                                if (!binFile.exists())
                                    exists = binFile.createNewFile();
                                if (exists && binFile.canWrite()) {
                                    FileOutputStream ostrm = new FileOutputStream(binFile);
                                    //InetAddress ia = InetAddress.getByName("10.4.1.37");
                                    client.open(); // client.open(20003, ia);
                                    client.receiveFile(provFile, TFTP.BINARY_MODE, ostrm, tftpIP, port);
                                    client.close();
                                    logger.info(PC2LogCategory.PCSim2, subCat,
                                            "TFTP of the record provisioning file is complete.");
                                } else {
                                    logger.warn(PC2LogCategory.PCSim2, subCat,
                                            "The system could not TFTP the provisioning file because TFTP address is "
                                                    + tftpIP + ".");
                                }
                            }
                        } else {
                            logger.warn(PC2LogCategory.PCSim2, subCat,
                                    "Recording of the provisioning file is terminating because the port(" + port
                                            + ") is less than 0 or greater than 65535.");
                        }
                    } else {
                        logger.warn(PC2LogCategory.PCSim2, subCat,
                                "Recording of the provisioning file is terminating because PACT returned an error string of \""
                                        + provFile + "\".");
                    }
                } catch (NumberFormatException nfe) {
                    logger.warn(PC2LogCategory.PCSim2, subCat,
                            "PCSim2 is not auto generating a provisioning file because the "
                                    + "TFTP Server Port setting doesn't appear to be a number.");
                } catch (UnknownHostException uhe) {
                    logger.warn(PC2LogCategory.PCSim2, subCat,
                            "PCSim2 is not auto generating a provisioning file because the "
                                    + "system encountered an error when attempting to send the file to the TFTP Server.\n"
                                    + uhe.getMessage() + "\n" + uhe.getStackTrace());
                } catch (IOException ioe) {
                    logger.warn(PC2LogCategory.PCSim2, subCat,
                            "PCSim2 is not auto generating a provisioning file because the "
                                    + "system encountered an error when attempting to send the file to the TFTP Server.\n"
                                    + ioe.getMessage() + "\n" + ioe.getStackTrace());
                }
        }
    }
}

From source file:com.cablelabs.sim.PCSim2.java

/**
 * This method determines if the provisioning file used to conduct a test needs to
 * be generated from one of the templates prior to starting the test.
 * @return - the MAC address used for the name of the file
 *//*from   w  w w .  ja v  a2  s  .c  om*/
private String autoGenerate(ProvisioningData pd) {
    Properties platform = SystemSettings.getSettings(SettingConstants.PLATFORM);
    Properties dut = SystemSettings.getSettings(SettingConstants.DUT);
    if (pd != null && platform != null && dut != null) {
        String pcscfLabel = dut.getProperty(SettingConstants.PCSCF);
        String macAddr = dut.getProperty(SettingConstants.MAC_ADDRESS);
        String tftpIP = platform.getProperty(SettingConstants.TFTP_SERVER_IP);
        String tftpPort = platform.getProperty(SettingConstants.TFTP_SERVER_PORT);
        String phone1 = dut.getProperty(SettingConstants.PHONE_NUMBER_1);
        String phone2 = dut.getProperty(SettingConstants.PHONE_NUMBER_2);
        String cw = platform.getProperty(SettingConstants.CW_NUMBER);
        if (macAddr != null && pcscfLabel != null && tftpIP != null && tftpPort != null && cw != null) {
            // First see if we have already issued a generated file.
            if (!provDB.issued(macAddr, pd)) {
                // Next verify the port is not set to zero
                try {
                    int port = Integer.parseInt(tftpPort);
                    if (port > 0 && port <= 65535) {

                        // Next make sure the TFTP Server IP is not set to 0.0.0.0
                        if (tftpIP.equals("0.0.0.0")) {
                            logger.warn(PC2LogCategory.PCSim2, subCat,
                                    "The TFTP Server IP setting in the platform file is not valid. Ending auto generate operation.");
                            return null;
                        }

                        File input = new File(SettingConstants.AUTO_PROV_FILE_DIRECTORY + File.separator
                                + SettingConstants.CW + cw + File.separator + pd.getProvFileName());
                        if (input != null) {
                            ProvGen pg = new ProvGen(input);
                            if (phone1 != null)
                                pg.changePhoneNum(SettingConstants.AUTO_GENERATE_PHONE_NUMBER_1, phone1);
                            if (phone2 != null)
                                pg.changePhoneNum(SettingConstants.AUTO_GENERATE_PHONE_NUMBER_2, phone2);
                            Properties pcscf = SystemSettings.getSettings(pcscfLabel);
                            if (pcscf != null) {
                                String pcscfIP = pcscf.getProperty(SettingConstants.IP);
                                if (pcscfIP != null)
                                    pg.changePCSCF(pcscfIP);
                            }
                            String newFileName = macAddr + ".bin";
                            if (pg.output(SettingConstants.AUTO_PROV_FILE_DIRECTORY + File.separator
                                    + SettingConstants.CW + cw + File.separator + newFileName)) {
                                // Test system
                                //File output = new File(SettingConstants.AUTO_PROV_FILE_DIRECTORY + newFileName);
                                //File pact = new File(SettingConstants.AUTO_PROV_FILE_DIRECTORY + "chinmaya_base_ph1_pcscf.bin");
                                //pg.compare(pact, output);
                                // Create a data entry of the issued event
                                //ProvisioningData issuePD = new ProvisioningData(macAddr, pd.getPolicyFileName(), newFileName);
                                logger.info(PC2LogCategory.PCSim2, subCat,
                                        "Beginning to TFTP the new provisioning file.");
                                provDB.setIssuedData(macAddr, pd);

                                // Next we need to TFTP the file to the server
                                TFTPClient client = new TFTPClient();
                                File binFile = new File(
                                        SettingConstants.AUTO_PROV_FILE_DIRECTORY + File.separator
                                                + SettingConstants.CW + cw + File.separator + newFileName);
                                if (binFile.isFile() && binFile.canRead()) {
                                    FileInputStream istrm = new FileInputStream(binFile);
                                    //InetAddress ia = InetAddress.getByName("10.4.1.37");
                                    client.open(); // client.open(20003, ia);
                                    client.sendFile(newFileName, TFTP.BINARY_MODE, istrm, tftpIP, port);
                                    client.close();
                                    logger.info(PC2LogCategory.PCSim2, subCat,
                                            "TFTP of the new provisioning file is complete.");
                                    return macAddr;
                                } else {
                                    logger.warn(PC2LogCategory.PCSim2, subCat,
                                            "The " + macAddr + ".bin doesn't appear in the "
                                                    + SettingConstants.AUTO_PROV_FILE_DIRECTORY + File.separator
                                                    + SettingConstants.CW + cw
                                                    + " Ending auto generate operation.");
                                }
                            } else {
                                logger.error(PC2LogCategory.PCSim2, subCat,
                                        "PCSim2 could not locate provisioning template file["
                                                + input.getAbsolutePath() + "].");
                            }
                        }
                        //                     else {
                        //                        logger.info(PC2LogCategory.PCSim2, subCat, "Auto provisioning is terminating because the input directory is null.");
                        //                     }
                    } else {
                        logger.info(PC2LogCategory.PCSim2, subCat,
                                "Auto provisioning is terminating because the port(" + port
                                        + ") is less than 0 or greater than 65535.");
                    }
                } catch (NumberFormatException nfe) {
                    logger.warn(PC2LogCategory.PCSim2, subCat,
                            "PCSim2 is not auto generating a provisioning file because the "
                                    + "TFTP Server Port setting doesn't appear to be a number.");
                } catch (UnknownHostException uhe) {
                    logger.warn(PC2LogCategory.PCSim2, subCat,
                            "PCSim2 is not auto generating a provisioning file because the "
                                    + "system encountered an error when attempting to send the file to the TFTP Server.\n"
                                    + uhe.getMessage() + "\n" + uhe.getStackTrace());
                } catch (IOException ioe) {
                    logger.warn(PC2LogCategory.PCSim2, subCat,
                            "PCSim2 is not auto generating a provisioning file because the "
                                    + "system encountered an error when attempting to send the file to the TFTP Server.\n"
                                    + ioe.getMessage() + "\n" + ioe.getStackTrace());
                }
            } else {
                logger.info(PC2LogCategory.PCSim2, subCat,
                        "Auto provisioning detected the same same provisioning template is already in use, skipping operation.");

            }
        } else {
            logger.info(PC2LogCategory.PCSim2, subCat,
                    "Auto provisioning is stopping because one of the values is null.\n" + "macAddr=" + macAddr
                            + " pcscfLabel=" + pcscfLabel + " tftpIP=" + tftpIP + " tftpPort=" + tftpPort);
        }
    } else {
        if (pd != null)
            logger.info(PC2LogCategory.PCSim2, subCat,
                    "The provisioning data is null, terminating processing.");
        if (platform != null)
            logger.info(PC2LogCategory.PCSim2, subCat,
                    "The Platform settings is null, terminating processing.");
        if (dut != null)
            logger.info(PC2LogCategory.PCSim2, subCat, "The DUT settings is null, terminating processing.");
    }

    return null;
}

From source file:rems.Global.java

public static void upldImgsFTP(int folderTyp, String locfolderNm, String locfileNm) {
    String subdir = "";
    String[] srvr = Global.getFTPServerDet();
    if (srvr[5].equals("0") || locfileNm.equals("")) {
        return;/*from  www .  j av  a 2 s.  c o m*/
    }
    if (folderTyp == 0) {
        subdir = "/Org";
    } else if (folderTyp == 1) {
        subdir = "/Divs";
    } else if (folderTyp == 2) {
        subdir = "/Person";
    } else if (folderTyp == 3) {
        subdir = "/Inv";
    } else if (folderTyp == 4) {
        subdir = "/PrsnDocs";
    } else if (folderTyp == 5) {
        subdir = "/Accntn";
    } else if (folderTyp == 6) {
        subdir = "/Prchs";
    } else if (folderTyp == 7) {
        subdir = "/Sales";
    } else if (folderTyp == 8) {
        subdir = "/Rcpts";
    } else if (folderTyp == 9) {
        subdir = "/Rpts";
    } else if (folderTyp == 15) {
        subdir = "/Rpts/jrxmls";
    } else if (folderTyp == 10) {
        subdir = "/AttnDocs";
    } else if (folderTyp == 11) {
        subdir = "/AssetDocs";
    } else if (folderTyp == 12) {
        subdir = "/PyblDocs";
    } else if (folderTyp == 13) {
        subdir = "/RcvblDocs";
    } else if (folderTyp == 14) {
        subdir = "/FirmsDocs";
    }

    try {
        //            Global.UploadFile(
        //                    InetAddress.getByName(srvr[0]), srvr[1] + subdir + "/", locfileNm,
        //                    locfolderNm + "/" + locfileNm, srvr[2],
        //                    Global.decrypt(srvr[3], Global.AppKey));
        String srvrIP = srvr[0].replace("ftp://", "");
        srvrIP = srvrIP.replace("/", "");
        Program.thread9 = new Uploadfunc("ThreadNine", InetAddress.getByName(srvrIP), srvr[1] + subdir + "/",
                locfileNm, locfolderNm + "/" + locfileNm, srvr[2], Global.decrypt(srvr[3], Global.AppKey));
        Program.thread9.setDaemon(true);
        Program.thread9.setName("ThreadNine");
        Program.thread9.setPriority(Thread.MIN_PRIORITY);
        Program.thread9.start();
    } catch (UnknownHostException ex) {
        Global.errorLog = ex.getMessage() + "\r\n" + Arrays.toString(ex.getStackTrace()) + "\r\n";
        Global.updateLogMsg(Global.logMsgID,
                "\r\n\r\n\r\nThe Program has Errored Out ==>\r\n\r\n" + Global.errorLog, Global.logTbl,
                Global.gnrlDateStr, Global.rnUser_ID);
        Global.writeToLog();
    }
}

From source file:rems.Global.java

public static void dwnldImgsFTP(int folderTyp, String locfolderNm, String locfileNm) {
    String[] srvr = Global.getFTPServerDet();
    String subdir = "";
    if (srvr[5].equals("0") || locfileNm.equals("")) {
        return;/*from w  w  w  .j  a  v a  2 s  .  c  o m*/
    }
    if (folderTyp == 0) {
        subdir = "/Org";
    } else if (folderTyp == 1) {
        subdir = "/Divs";
    } else if (folderTyp == 2) {
        subdir = "/Person";
    } else if (folderTyp == 3) {
        subdir = "/Inv";
    } else if (folderTyp == 4) {
        subdir = "/PrsnDocs";
    } else if (folderTyp == 5) {
        subdir = "/Accntn";
    } else if (folderTyp == 6) {
        subdir = "/Prchs";
    } else if (folderTyp == 7) {
        subdir = "/Sales";
    } else if (folderTyp == 8) {
        subdir = "/Rcpts";
    } else if (folderTyp == 9) {
        subdir = "/Rpts";
    } else if (folderTyp == 15) {
        subdir = "/Rpts/jrxmls";
    } else if (folderTyp == 10) {
        subdir = "/AttnDocs";
    } else if (folderTyp == 11) {
        subdir = "/AssetDocs";
    } else if (folderTyp == 12) {
        subdir = "/PyblDocs";
    } else if (folderTyp == 13) {
        subdir = "/RcvblDocs";
    } else if (folderTyp == 14) {
        subdir = "/FirmsDocs";
    }
    try {
        String srvrIP = srvr[0].replace("ftp://", "");
        srvrIP = srvrIP.replace("/", "");
        Program.thread10 = new Downloadfunc("ThreadNine", InetAddress.getByName(srvrIP), srvr[1] + subdir + "/",
                locfileNm, locfolderNm + "/" + locfileNm, srvr[2], Global.decrypt(srvr[3], Global.AppKey));
        Program.thread10.setDaemon(true);
        Program.thread10.setName("ThreadNine");
        Program.thread10.setPriority(Thread.MIN_PRIORITY);
        Program.thread10.start();
    } catch (UnknownHostException ex) {
        Global.errorLog = ex.getMessage() + "\r\n" + Arrays.toString(ex.getStackTrace()) + "\r\n";
        Global.updateLogMsg(Global.logMsgID,
                "\r\n\r\n\r\nThe Program has Errored Out ==>\r\n\r\n" + Global.errorLog, Global.logTbl,
                Global.gnrlDateStr, Global.rnUser_ID);
        Global.writeToLog();
    }
    //        try {
    //            Global.DownloadFile(InetAddress.getByName(srvr[0]), 
    //                    srvr[1] + subdir + "/", 
    //                    locfileNm,
    //                    locfolderNm + "/" + locfileNm, 
    //                    srvr[2],
    //                    Global.decrypt(srvr[3], Global.AppKey));
    //        } catch (UnknownHostException ex) {
    //            Logger.getLogger(Global.class.getName()).log(Level.SEVERE, null, ex);
    //        }
}

From source file:voldemort.performance.benchmark.VoldemortWrapper.java

static public void startMeasurementListener() {
    // dump any warmup values
    partition_usage.reset();//from w  w w.  ja v  a  2  s .com

    // open TCP connection to the controller
    try {
        // TODO: get ip port from property file
        clientSocket = new Socket("lakka-6.it.kth.se", 27960);
        in = new DataInputStream(clientSocket.getInputStream());
        out = new DataOutputStream(clientSocket.getOutputStream());
    } catch (UnknownHostException e) {
        System.err.println("Elastore server not available!");
        return;
    } catch (IOException e) {
        System.err.println("Elastore server IO error!");
        return;
    }

    // create a thread to receive/reply to controller measurement pull
    // requests
    new Thread() {

        @Override
        public void run() {
            // loop until quit
            while (!VoldemortWrapper.halt_measurement) {
                // catch io exceptions
                try {
                    // await pull request from controller
                    // which will be a single byte
                    if (in.available() == 0) {
                        try {
                            Thread.sleep(2000);
                        } catch (InterruptedException e) {
                            logger.error(e);
                        }
                    } else {
                        // read data from socket
                        int read = in.readUnsignedByte();
                        if (read != 42) {
                            logger.error("Unexpected ping value: " + read);
                        }

                        // sync-free since updates are threadsafe atomic +
                        // struct isn't changed otherwise
                        String measurement = dumpPartitionAccessHistogram();
                        partition_usage.reset();
                        out.writeUTF(measurement + "\n");
                        logger.info("Sent histogram: " + measurement);

                        HashMap<String, String> readStats = new HashMap<String, String>(7);

                        synchronized (statsR) {
                            readStats.put("n", ((Long) statsR.getN()).toString());
                            readStats.put("mean", ((Double) ns_to_ms(statsR.getMean())).toString());
                            readStats.put("s.d.",
                                    ((Double) ns_to_ms(statsR.getStandardDeviation())).toString());
                            readStats.put("min", ((Double) ns_to_ms(statsR.getMin())).toString());
                            readStats.put("max", ((Double) ns_to_ms(statsR.getMax())).toString());
                            readStats.put("95th%", ((Double) ns_to_ms(statsR.getPercentile(95))).toString());
                            readStats.put("99th%", ((Double) ns_to_ms(statsR.getPercentile(99))).toString());
                            statsR.clear();
                        }

                        ObjectMapper mapper = new ObjectMapper();
                        try {
                            String timing = mapper.writeValueAsString(readStats);
                            out.writeUTF(timing + "\n");
                            logger.info("Sent timing: " + timing);
                        } catch (JsonGenerationException e) {
                            logger.error(e.getStackTrace());
                        } catch (JsonMappingException e) {
                            logger.error(e.getStackTrace());
                        } catch (IOException e) {
                            logger.error(e.getStackTrace());
                        }
                    }
                } catch (IOException e) {
                    System.out.println("Measurer disconnected!!: " + e);
                    break;
                }
            }
            System.out.println("Halting pull listener");
        }
    }.start();
}