Example usage for java.lang InterruptedException printStackTrace

List of usage examples for java.lang InterruptedException printStackTrace

Introduction

In this page you can find the example usage for java.lang InterruptedException printStackTrace.

Prototype

public void printStackTrace() 

Source Link

Document

Prints this throwable and its backtrace to the standard error stream.

Usage

From source file:com.logicmonitor.ft.jxmtop.JMXTopMain.java

private static void topJMXValues(JMXMan jmxMan, RunParameter runParameter) {

    // use for general info
    JVMGeneral jvmGeneral = new JVMGeneral();
    List<String> generalPaths = jvmGeneral.getJVMGeneralPaths();
    List<String> memoryPoolUsed = jvmGeneral.getAllMemoryPoolUsed(jmxMan);
    List<String> memmoryPoolCommitted = jvmGeneral.getAllMemoryPoolCommitted(jmxMan);

    List<String> memoryPoolNames = jmxMan.getIndexValues(jvmGeneral.getMemoryPoolUsed(),
            jvmGeneral.getMemoryPoolCommitted());

    int generalInfoCounts = 5 + memoryPoolNames.size();

    int maxMemoryPoolNameLength = 0;
    for (String memoryPoolName : memoryPoolNames) {
        maxMemoryPoolNameLength = maxMemoryPoolNameLength > memoryPoolName.length() ? maxMemoryPoolNameLength
                : memoryPoolName.length();
    }//from w  ww  .  j av a2  s.  com

    // use for user path
    int maxPathLength = 0;
    List<JMXFullPath> fullPaths = jmxMan.getJmxFullPaths();
    if (jmxMan.hasFullPath()) {
        int pathsNumb = fullPaths.size();
        for (JMXFullPath fullPath : fullPaths) {
            if (runParameter.isShowAliasTitle()) {
                maxPathLength = fullPath.getAlias().length() > maxPathLength ? fullPath.getAlias().length()
                        : maxPathLength;
            } else {
                maxPathLength = fullPath.getPath().length() > maxPathLength ? fullPath.getPath().length()
                        : maxPathLength;
            }
        }
    }

    String[] companyInfo = new String[] { " JMXTop was created by LogicMonitor under the BSD3 License.", "",
            " To learn more about LogicMonitor and its automated IT Infrastructure Performance Monitoring Platform, visit www.logicmonitor.com.",
            " For the latest updates, versions and configuration files, please visit our page on GitHub at https://github.com/logicmonitor/jmx-clt." };

    try {
        int pathsNumb = fullPaths.size();
        Label valuesLabels[] = new Label[pathsNumb];
        Label companyInfoLabels[] = new Label[companyInfo.length];
        Label jvmGenLabels[] = new Label[generalInfoCounts];

        long lastCPUTime = Long.valueOf(jmxMan.getValue(jvmGeneral.getCpuUsage()));
        List<String> lastValues = jmxMan.getValues();
        long lastSystemTime = System.currentTimeMillis();

        int duration = runParameter.getInterval() * 1000;

        DefaultLayoutManager mgr = new DefaultLayoutManager();
        JMXWindow preWindow = null, window = null;
        while (true) {
            window = new JMXWindow(0, 0, 1000, 100, false, "");
            window.setShadow(false);
            window.addClosingChar(new InputChar(JMXWindow.KEY_CTRL_C));
            window.addClosingChar(new InputChar(JMXWindow.KEY_LOW_Q));
            window.moveToTheTop();
            mgr.bindToContainer(window.getRootPanel());

            // show company info
            int startLine = 0;
            for (int i = 0; i < companyInfo.length; i++) {
                companyInfoLabels[i] = new Label(companyInfo[i]);
                mgr.addWidget(companyInfoLabels[i], 0, startLine, companyInfo[i].length(), 20,
                        WidgetsConstants.ALIGNMENT_TOP, WidgetsConstants.ALIGNMENT_LEFT);
                startLine++;
            }

            // show general info
            List<String> generalValues = jmxMan.getValues(generalPaths);
            List<String> memoryPoolUsedValues = jmxMan.getValues(memoryPoolUsed);
            List<String> memoryPoolCommittedValues = jmxMan.getValues(memmoryPoolCommitted);
            SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

            Long upTime = Long.valueOf(generalValues.get(0));
            int nHours = (int) (upTime / 3600);
            int nMinis = (int) (upTime - nHours * 3600) / 60;
            int nSeconds = (int) (upTime - nHours * 3600 - nMinis * 60);

            String upTimeString = "" + nSeconds + "s";
            if (nHours != 0) {
                upTimeString = "" + nHours + "h " + nMinis + "m " + upTimeString;
            } else if (nMinis != 0) {
                upTimeString = "" + nMinis + "m " + upTimeString;
            }

            int maxGeneralInfoLength = 0;
            String topString = " JMXtop - " + df.format(new Date()) + " UP " + upTime + " da " + nHours;
            maxGeneralInfoLength = topString.length() > maxGeneralInfoLength ? topString.length()
                    : maxGeneralInfoLength;
            String threadsInfo = " Thread: " + generalValues.get(1) + " live, " + generalValues.get(2)
                    + " peak, " + generalValues.get(3) + " daemon, " + generalValues.get(4) + " total";
            maxGeneralInfoLength = threadsInfo.length() > maxGeneralInfoLength ? threadsInfo.length()
                    : maxGeneralInfoLength;

            long cpuProcessTime = Long.valueOf(generalValues.get(5));
            long cur_Time = System.currentTimeMillis();
            float cpuUsage = (float) ((cpuProcessTime - lastCPUTime)
                    / (1000000.0 * (cur_Time - lastSystemTime) * Integer.valueOf(generalValues.get(6))));
            String cpuInfo = String.format(" CPU: %.3fs, %.2f%% usage", (float) cpuProcessTime / 1000000000,
                    cpuUsage * 100);
            maxGeneralInfoLength = cpuInfo.length() > maxGeneralInfoLength ? cpuInfo.length()
                    : maxGeneralInfoLength;
            lastSystemTime = cur_Time;
            lastCPUTime = cpuProcessTime;

            long heapUsed = Long.valueOf(generalValues.get(7)) / 1024;
            long heapCommitted = Long.valueOf(generalValues.get(8)) / 1024;

            Long nonHeapUsed = Long.valueOf(generalValues.get(9)) / 1024;
            Long nonHeapCommitted = Long.valueOf(generalValues.get(10)) / 1024;
            String heapMemInfo = String.format(" %s : %10dKB used, %10dKB committed, %02.2f%% usage",
                    alignString("Heap", maxMemoryPoolNameLength), heapUsed, heapCommitted,
                    (float) heapUsed * 100 / heapCommitted);
            String nonHeapMemInfo = String.format(" %s : %10dKB used, %10dKB committed, %02.2f%% usage",
                    alignString("NonHeap", maxMemoryPoolNameLength), nonHeapUsed, nonHeapCommitted,
                    (float) nonHeapUsed * 100 / nonHeapCommitted);
            maxGeneralInfoLength = heapMemInfo.length() > maxGeneralInfoLength ? heapMemInfo.length()
                    : maxGeneralInfoLength;
            maxGeneralInfoLength = nonHeapMemInfo.length() > maxGeneralInfoLength ? nonHeapMemInfo.length()
                    : maxGeneralInfoLength;

            jvmGenLabels[0] = new Label(" JMXtop - " + df.format(new Date()) + " up " + upTimeString);
            jvmGenLabels[1] = new Label(threadsInfo);
            jvmGenLabels[2] = new Label(cpuInfo);
            jvmGenLabels[3] = new Label(heapMemInfo);
            jvmGenLabels[4] = new Label(nonHeapMemInfo);
            //                memoryPoolUsedValues
            for (int i = 0; i < memoryPoolNames.size(); i++) {
                Long used = Long.valueOf(memoryPoolUsedValues.get(i)) / 1024;
                Long commited = Long.valueOf(memoryPoolCommittedValues.get(i)) / 1024;
                jvmGenLabels[i + 5] = new Label(
                        String.format(" %s : %10dKB used, %10dKB committed, %02.2f%% usage",
                                alignString(memoryPoolNames.get(i).toString(), maxMemoryPoolNameLength), used,
                                commited, (float) used * 100 / commited));
            }

            startLine++;
            for (int i = 0; i < generalInfoCounts; i++) {
                mgr.addWidget(jvmGenLabels[i], 0, startLine, maxGeneralInfoLength, 20,
                        WidgetsConstants.ALIGNMENT_TOP, WidgetsConstants.ALIGNMENT_LEFT);
                startLine++;
            }

            // show user jmx path
            startLine++;
            int startId = 0, endId = 0;
            if (!fullPaths.isEmpty()) {
                List<String> curValuesOfFullPaths = jmxMan.getValues();
                // support page down and up
                int pageSize = Math.max(window.getHeight() - startLine - 1, 1);
                int pageNum = JMXWindow.getPageNum();
                if (pageNum * pageSize >= curValuesOfFullPaths.size()) {
                    pageNum = Math.max((curValuesOfFullPaths.size() - 1) / pageSize, 0);
                    JMXWindow.setPageNum(pageNum);
                }
                startId = pageNum * pageSize;
                endId = Math.min(curValuesOfFullPaths.size(), (pageNum + 1) * pageSize);

                for (int i = startId; i < endId; i++) {
                    String curValue;
                    if (fullPaths.get(i).isCounter()) {
                        long rst = Long.valueOf(curValuesOfFullPaths.get(i)) - Long.valueOf(lastValues.get(i));
                        curValue = "" + rst;
                    } else {
                        curValue = curValuesOfFullPaths.get(i);
                    }
                    if (fullPaths.get(i).getOperator() != null && fullPaths.get(i).getScale() != 0) {
                        String opt = fullPaths.get(i).getOperator();
                        int scale = fullPaths.get(i).getScale();

                        long v = Long.valueOf(curValue);

                        if (opt.equals("+")) {
                            v += scale;
                        } else if (opt.equals("-")) {
                            v -= scale;
                        } else if (opt.equals("*")) {
                            v *= scale;
                        } else if (opt.equals("/")) {
                            v /= scale;
                        } else {

                        }

                        curValue = String.valueOf(v);
                    }
                    if (fullPaths.get(i).getUnit() != null)
                        curValue = curValue + fullPaths.get(i).getUnit();

                    String tmp = "";
                    if (runParameter.isShowAliasTitle()) {
                        tmp = String.format(" %s\t\t%s",
                                alignString(fullPaths.get(i).getAlias(), maxPathLength), curValue);
                    } else {
                        tmp = String.format(" %s\t\t%s", alignString(fullPaths.get(i).getPath(), maxPathLength),
                                curValue);
                    }
                    valuesLabels[i] = new Label(tmp);
                    mgr.addWidget(valuesLabels[i], 0, startLine, tmp.length(), 20,
                            WidgetsConstants.ALIGNMENT_TOP, WidgetsConstants.ALIGNMENT_LEFT);
                    startLine++;
                }
                lastValues = curValuesOfFullPaths;
            }
            window.show();
            if (preWindow != null) {
                preWindow.close();
            }
            preWindow = window;

            try {
                Thread.sleep(duration);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }

            for (int i = 0; i < companyInfo.length; i++) {
                mgr.removeWidget(companyInfoLabels[i]);
            }
            for (int i = 0; i < generalInfoCounts; i++) {
                mgr.removeWidget(jvmGenLabels[i]);

            }
            for (int i = startId; i < endId; i++) {
                mgr.removeWidget(valuesLabels[i]);
            }

            if (window.isClosed()) {
                System.out.println("Window is closed!");
                exit(-1);
            }

            mgr.unbindFromContainer();
        }
    } catch (IOException e) {
        e.printStackTrace();
    }

}

From source file:org.house.service.spider.WebSpider.java

private static synchronized String doHttpRequest(final HttpRequestBase httpRequestBase) {
    if (lastCallTime == -1) {
        lastCallTime = System.currentTimeMillis();
    }/* w w  w  .  j a  v  a2  s  . com*/
    while (true) {
        if (System.currentTimeMillis() - lastCallTime < 300) {
            try {
                Thread.sleep(200);
            } catch (final InterruptedException e) {
                e.printStackTrace();
            }
        } else {
            lastCallTime = System.currentTimeMillis();
            break;
        }
    }
    try {
        final CloseableHttpResponse theResponse = client.execute(httpRequestBase);
        return EntityUtils.toString(theResponse.getEntity());
    } catch (final Exception e) {
        e.printStackTrace();
        return null;
    }
}

From source file:org.wso2.carbon.appmgt.sampledeployer.main.ApplicationPublisher.java

private static void configure() {
    LoginAdminServiceClient login = null;
    try {/* w  ww. j  a  v a 2  s.  c o  m*/
        try {
            Thread.sleep(10000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        login = new LoginAdminServiceClient(backEndUrl);
        String normal_session = login.authenticate(username, password);
        ClaimManagementServiceClient claimManagementServiceClient = new ClaimManagementServiceClient(
                normal_session, backEndUrl);
        RemoteUserStoreManagerServiceClient remoteUserStoreManagerServiceClient = new RemoteUserStoreManagerServiceClient(
                normal_session, backEndUrl);
        //add claim dialects
        log.info("Add claim mapping");
        claimManagementServiceClient.addClaim("FrequentFlyerID", "http://wso2.org/ffid", true);
        claimManagementServiceClient.addClaim("zipcode", "http://wso2.org/claims/zipcode", true);
        claimManagementServiceClient.addClaim("Credit card number", "http://wso2.org/claims/card_number", true);
        claimManagementServiceClient.addClaim("Credit cArd Holder Name", "http://wso2.org/claims/card_holder",
                true);
        claimManagementServiceClient.addClaim("Credit card expiration date",
                "http://wso2.org/claims/expiration_date", true);
        //set values for claims
        log.info("Updating claim values");
        remoteUserStoreManagerServiceClient.updateClaims("admin", "http://wso2.org/ffid", "12345151");
        remoteUserStoreManagerServiceClient.updateClaims("admin", "http://wso2.org/claims/streetaddress",
                "21/5");
        remoteUserStoreManagerServiceClient.updateClaims("admin", "http://wso2.org/claims/zipcode", "GL");
        remoteUserStoreManagerServiceClient.updateClaims("admin", "http://wso2.org/claims/card_number",
                "001012676878");
        remoteUserStoreManagerServiceClient.updateClaims("admin", "http://wso2.org/claims/card_holder",
                "Admin");
        remoteUserStoreManagerServiceClient.updateClaims("admin", "http://wso2.org/claims/telephone",
                "091222222");
        remoteUserStoreManagerServiceClient.updateClaims("admin", "http://wso2.org/claims/givenname",
                "Sachith");
        remoteUserStoreManagerServiceClient.updateClaims("admin", "http://wso2.org/claims/lastname", "Ushan");
        remoteUserStoreManagerServiceClient.updateClaims("admin", "http://wso2.org/claims/emailaddress",
                "wso2@wso2.com");
        remoteUserStoreManagerServiceClient.updateClaims("admin", "http://wso2.org/claims/country", "SriLanka");
        remoteUserStoreManagerServiceClient.updateClaims("admin", "http://wso2.org/claims/expiration_date",
                "31/12/2015");
        //publish application
        log.info("Creating application DTO");
        try {
            String publisher_session = httpHandler.doPostHttps(backEndUrl + "/publisher/api/authenticate",
                    "username=" + username + "&password=" + password + "&action=login", "",
                    "application/x-www-form-urlencoded");
            String store_session = httpHandler.doPostHttp(backEndNonSecureUrl + "/store/apis/user/login",
                    "{\"username\":\"admin\"" + ",\"password\":\"admin\"}", "header", "application/json");
            AppCreateRequest appCreateRequest = new AppCreateRequest();
            //requesting policy ID
            String policyIDResponce = httpHandler.doPostHttps(
                    backEndUrl + "/publisher/api/entitlement/policy/partial" + "/policyGroup/save",
                    "anonymousAccessToUrlPattern=false&policyGroupName"
                            + "=test&throttlingTier=Unlimited&objPartialMappings=[]&policyGroupDesc=null&userRoles=",
                    publisher_session, "application/x-www-form-urlencoded; charset=UTF-8").split(":")[3];
            String policyId = policyIDResponce.substring(1, (policyIDResponce.length() - 2)).trim();
            appCreateRequest.setUritemplate_policyGroupIds("[" + policyId + "]");
            appCreateRequest.setUritemplate_policyGroupId4(policyId);
            appCreateRequest.setUritemplate_policyGroupId3(policyId);
            appCreateRequest.setUritemplate_policyGroupId2(policyId);
            appCreateRequest.setUritemplate_policyGroupId1(policyId);
            appCreateRequest.setUritemplate_policyGroupId0(policyId);
            appCreateRequest.setClaimPropertyName0("http://wso2.org/claims/streetaddress,http://wso2.org/ffid"
                    + ",http://wso2.org/claims/telephone");
            appCreateRequest.setClaimPropertyCounter("3");
            //publishing travelWebapp
            log.info("publishing travleWebapp");
            appCreateRequest.setOverview_name("travelWebapp");
            appCreateRequest.setOverview_displayName("travelWebapp");
            appCreateRequest.setOverview_context("/travel");
            appCreateRequest.setOverview_version("1.0.0");
            appCreateRequest.setOverview_trackingCode(appCreateRequest.generateTrackingID());
            appCreateRequest.setOverview_transports("http");
            appCreateRequest.setOverview_webAppUrl("http://localhost:" + tomcatPort + "/plan-your-trip-1.0/");
            String payload = appCreateRequest.generateRequestParameters();
            publishApplication(appCreateRequest.getOverview_name(), "webapp", normal_session, publisher_session,
                    appCreateRequest, "application/x-www-form-urlencoded", "");
            httpHandler.doPostHttps(backEndUrl + "/store/resources/webapp/v1/subscription/app",
                    "apiName=" + appCreateRequest.getOverview_name() + "" + "&apiVersion="
                            + appCreateRequest.getOverview_version() + "&apiTier="
                            + appCreateRequest.getOverview_tier()
                            + "&subscriptionType=INDIVIDUAL&apiProvider=admin&appName=DefaultApplication",
                    store_session, "application/x-www-form-urlencoded; charset=UTF-8");
            //publishing travel booking application
            log.info("publishing travleWebapp");
            appCreateRequest.setOverview_name("TravelBooking");
            appCreateRequest.setOverview_displayName("TravelBooking");
            appCreateRequest.setOverview_context("/travelBooking");
            appCreateRequest.setOverview_version("1.0.0");
            appCreateRequest.setOverview_transports("http");
            appCreateRequest.setOverview_trackingCode(appCreateRequest.generateTrackingID());
            appCreateRequest
                    .setClaimPropertyName0("http://wso2.org/claims/givenname,http://wso2.org/claims/lastname"
                            + ",http://wso2.org/claims/emailaddress,http://wso2.org/claims/streetaddress"
                            + ",http://wso2.org/claims/zipcode,http://wso2.org/claims/country"
                            + ",http://wso2.org/claims/card_number,http://wso2.org/claims/card_holder"
                            + ",http://wso2.org/claims/expiration_date");
            appCreateRequest.setClaimPropertyCounter("9");
            appCreateRequest.setOverview_webAppUrl("http://localhost:" + tomcatPort + "/travel-booking-1.0/");
            publishApplication(appCreateRequest.getOverview_name(), "webapp", normal_session, publisher_session,
                    appCreateRequest, "application/x-www-form-urlencoded", "");
            httpHandler.doPostHttps(backEndUrl + "/store/resources/webapp/v1/subscription/app",
                    "apiName=" + appCreateRequest.getOverview_name() + "" + "&apiVersion="
                            + appCreateRequest.getOverview_version() + "&apiTier="
                            + appCreateRequest.getOverview_tier()
                            + "&subscriptionType=INDIVIDUAL&apiProvider=admin&appName=DefaultApplication",
                    store_session, "application/x-www-form-urlencoded; charset=UTF-8");
            log.info("publishing notifi web application");
            //publishing notifi webapplication
            appCreateRequest.setOverview_name("notifi");
            appCreateRequest.setOverview_context("/notifi");
            appCreateRequest.setOverview_displayName("notifi");
            appCreateRequest.setOverview_version("1.0.0");
            appCreateRequest.setOverview_transports("http");
            appCreateRequest.setClaimPropertyName0("http://wso2.org/claims/card_number");
            appCreateRequest.setClaimPropertyCounter("1");
            appCreateRequest.setOverview_trackingCode(appCreateRequest.generateTrackingID());
            appCreateRequest.setOverview_webAppUrl("http://localhost/notifi/");
            publishApplication(appCreateRequest.getOverview_name(), "webapp", normal_session, publisher_session,
                    appCreateRequest, "application/x-www-form-urlencoded", "");
            httpHandler.doPostHttps(backEndUrl + "/store/resources/webapp/v1/subscription/app",
                    "apiName=" + appCreateRequest.getOverview_name() + "" + "&apiVersion="
                            + appCreateRequest.getOverview_version() + "&apiTier="
                            + appCreateRequest.getOverview_tier()
                            + "&subscriptionType=INDIVIDUAL&apiProvider=admin&appName=DefaultApplication",
                    store_session, "application/x-www-form-urlencoded; charset=UTF-8");
            //publish mobile application clean calc
            log.info("publishing CleanCalc mobile application");
            MobileApplicationBean mobileApplicationBean = new MobileApplicationBean();
            mobileApplicationBean.setApkFile(
                    appmPath + "/repository/resources/mobileapps/CleanCalc" + "/Resources/CleanCalc.apk");
            String appMeta = httpHandler.doPostMultiData(backEndUrl + "/publisher/api/mobileapp/upload",
                    "upload", mobileApplicationBean, publisher_session);
            mobileApplicationBean.setVersion("1.0.0");
            mobileApplicationBean.setProvider("1WSO2Mobile");
            mobileApplicationBean.setMarkettype("Enterprise");
            mobileApplicationBean.setPlatform("android");
            mobileApplicationBean.setName("CleanCalc");
            mobileApplicationBean.setDescription("this is a clean calucultor");
            mobileApplicationBean.setBannerFilePath(
                    appmPath + "/repository/resources/mobileapps/" + "CleanCalc/Resources/banner.png");
            mobileApplicationBean.setIconFile(
                    appmPath + "/repository/resources/mobileapps/CleanCalc" + "/Resources/icon.png");
            mobileApplicationBean.setScreenShot1File(
                    appmPath + "/repository/resources/mobileapps/CleanCalc" + "/Resources/screen1.png");
            mobileApplicationBean.setScreenShot2File(
                    appmPath + "/repository/resources/mobileapps/CleanCalc" + "/Resources/screen2.png");
            mobileApplicationBean.setScreenShot3File(
                    appmPath + "/repository/resources/mobileapps/CleanCalc" + "/Resources/screen3.png");
            mobileApplicationBean.setMobileapp("mobileapp");
            mobileApplicationBean.setAppmeta(appMeta);
            String ID = httpHandler.doPostMultiData(backEndUrl + "/publisher/api/asset/mobileapp", "none",
                    mobileApplicationBean, publisher_session);
            publishApplication("", "mobileapp", normal_session, publisher_session, null, "", ID);
            //wso2Con mobile application
            log.info("publishing WSO2Con mobile application");
            mobileApplicationBean.setAppmeta("{\"package\":\"com.wso2.wso2con.mobile\",\"version\":\"1.0.0\"}");
            mobileApplicationBean.setVersion("1.0.0");
            mobileApplicationBean.setProvider("1WSO2Mobile");
            mobileApplicationBean.setMarkettype("Market");
            mobileApplicationBean.setPlatform("android");
            mobileApplicationBean.setName("Wso2Con");
            mobileApplicationBean.setDescription("WSO2Con mobile app provides the agenda and meeting tool for "
                    + "WSO2Con. Get the app to follow the agenda, find out about the sessions and speakers, provide "
                    + "feedback on the sessions, and get more information on the venue and sponsors. Join us at "
                    + "WSO2Con, where we will place emerging technology, best practices, and WSO2 product features "
                    + "in the perspective of accelerating development and building a connected business. We hope you "
                    + "enjoy WSO2Con!");
            mobileApplicationBean.setBannerFilePath(
                    appmPath + "/repository/resources/mobileapps/WSO2Con" + "/Resources/banner.png");
            mobileApplicationBean
                    .setIconFile(appmPath + "/repository/resources/mobileapps/WSO2Con" + "/Resources/icon.png");
            mobileApplicationBean.setScreenShot1File(
                    appmPath + "/repository/resources/mobileapps/WSO2Con" + "/Resources/screen1.png");
            mobileApplicationBean.setScreenShot2File(
                    appmPath + "/repository/resources/mobileapps" + "/WSO2Con/Resources/screen2.png");
            mobileApplicationBean.setMobileapp("mobileapp");
            ID = httpHandler.doPostMultiData(backEndUrl + "/publisher/api/asset/mobileapp", "none",
                    mobileApplicationBean, publisher_session);
            publishApplication("", "mobileapp", normal_session, publisher_session, null, "", ID);
            //MyTrack mobile application
            log.info("publishing MyTrack mobile application");
            mobileApplicationBean.setAppmeta(
                    "{\"package\":\"com.google.android.maps.mytracks\",\"version\":\"1.0" + ".0\"}");
            mobileApplicationBean.setVersion("1.0.0");
            mobileApplicationBean.setProvider("1WSO2Mobile");
            mobileApplicationBean.setMarkettype("Market");
            mobileApplicationBean.setPlatform("android");
            mobileApplicationBean.setName("MyTracks");
            mobileApplicationBean
                    .setDescription("My Tracks records your path, speed, distance, and elevation while "
                            + "you walk, run, bike, or do anything else outdoors. While recording, you can view your data live"
                            + ", annotate your path, and hear periodic voice announcements of your progress.\n"
                            + "With My Tracks, you can sync and share your tracks via Google Drive. For sharing, you can share"
                            + " tracks with friends, see the tracks your friends have shared with you, or make tracks public "
                            + "and share their URLs via Google+, Facebook, Twitter, etc. In addition to Google Drive, you can "
                            + "also export your tracks to Google My Maps, Google Spreadsheets, or external storage.\n"
                            + "My Tracks also supports Android Wear. For watches with GPS, My Tracks can perform GPS recording"
                            + " of tracks without a phone and sync tracks to the phone. For watches without GPS, you can see "
                            + "your current distance and time, and control the recording of your tracks from your wrist.");
            mobileApplicationBean.setBannerFilePath(
                    appmPath + "/repository/resources/" + "mobileapps/MyTracks/Resources/banner.png");
            mobileApplicationBean.setIconFile(
                    appmPath + "/repository/resources/mobileapps" + "/MyTracks/Resources/icon.png");
            mobileApplicationBean.setScreenShot1File(
                    appmPath + "/repository/resources/mobileapps/MyTracks" + "/Resources/screen1.png");
            mobileApplicationBean.setScreenShot2File(
                    appmPath + "/repository/resources/mobileapps/MyTracks" + "/Resources/screen2.png");
            mobileApplicationBean.setMobileapp("mobileapp");
            ID = httpHandler.doPostMultiData(backEndUrl + "/publisher/api/asset/mobileapp", "none",
                    mobileApplicationBean, publisher_session);
            publishApplication("", "mobileapp", normal_session, publisher_session, null, "", ID);
        } catch (IOException e) {
            log.error(e.getMessage());
        } catch (Exception e) {
            log.error(e.getMessage());
        }
    } catch (AxisFault axisFault) {
        configure();
    } catch (RemoteException e) {
        log.error(e.getMessage());
    } catch (LoginAuthenticationExceptionException e) {
        log.error(e.getMessage());
    } catch (ClaimManagementServiceException e) {
        log.error(e.getMessage());
    } catch (RemoteUserStoreManagerServiceUserStoreExceptionException e) {
        log.error(e.getMessage());
    }
    startServers();

}

From source file:loci.apps.SlideScannerImport.VentanaScannerInterpreter.java

private static double[] getUserEnteredStartPoint(ImagePlus imp) {

    imp.show();/*from  www .java 2 s.  co m*/

    MouseClickListener mouse = new MouseClickListener(imp);
    while (!mouse.getMouseClicked()) {
        try {
            Thread.sleep(500);
        } catch (InterruptedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
    imp.close();
    return mouse.getClickCoordinates();
}

From source file:cn.kk.exia.MangaDownloader.java

private final static void checkAndDump(final String line, final Logger log, final String targetDir) {
    if (line.contains("An Error Has Occurred")) {
        try {/*w ww . j a va  2s .  c o  m*/
            Thread.sleep(
                    (60 * MangaDownloader.sleepBase) + (int) (Math.random() * 120 * MangaDownloader.sleepBase));
        } catch (final InterruptedException e) {
            e.printStackTrace();
        }
    }
    if (line.contains("your IP address")) {
        log.err("??" + line);
        try {
            Thread.sleep(
                    (60 * MangaDownloader.sleepBase) + (int) (Math.random() * 120 * MangaDownloader.sleepBase));
        } catch (final InterruptedException e) {
            e.printStackTrace();
        }
    }
    if (MangaDownloader.dump) {
        try {
            final File dumpFile = new File(targetDir + File.separator + "exia-dump.xml");
            if (!dumpFile.isFile()) {
                log.err("dump: " + dumpFile.getAbsolutePath());
            }
            final FileWriter writer = new FileWriter(dumpFile, true);

            writer.append(line);
            writer.append('\n');
            writer.close();
        } catch (final IOException e) {
            e.printStackTrace();
        }
    }
}

From source file:cn.kk.exia.MangaDownloader.java

public final static HttpURLConnection getUrlConnection(final String url, final boolean post,
        final String output) throws IOException {
    int retries = 0;
    HttpURLConnection conn;/*  w w w  .  ja  va 2s  .c o m*/
    while (true) {
        try {
            final URL urlObj = new URL(url);
            conn = (HttpURLConnection) urlObj.openConnection();
            conn.setConnectTimeout(15000);
            conn.setReadTimeout(30000);
            if (post) {
                conn.setRequestMethod("POST");
            }
            final String referer;
            final int pathIdx;
            if ((pathIdx = url.lastIndexOf('/')) > "https://".length()) {
                referer = url.substring(0, pathIdx);
            } else {
                referer = url;
            }
            conn.setRequestProperty("Referer", referer);
            final Set<String> keys = MangaDownloader.DEFAULT_CONN_HEADERS.keySet();
            for (final String k : keys) {
                final String value = MangaDownloader.DEFAULT_CONN_HEADERS.get(k);
                if (value != null) {
                    conn.setRequestProperty(k, value);
                }
            }
            // conn.setUseCaches(false);
            if (output != null) {
                conn.setDoOutput(true);
                final BufferedOutputStream out = new BufferedOutputStream(conn.getOutputStream());
                out.write(output.getBytes(MangaDownloader.CHARSET_UTF8));
                out.close();
            }
            if (MangaDownloader.appendCookies(MangaDownloader.cookie, conn)) {
                MangaDownloader.putConnectionHeader("Cookie", MangaDownloader.cookie.toString());
            }
            break;
        } catch (final Throwable e) {
            // 
            System.err.println(e.toString());
            if (retries++ > 10) {
                throw new IOException(e);
            } else {
                try {
                    Thread.sleep((60 * retries * MangaDownloader.sleepBase)
                            + ((int) Math.random() * MangaDownloader.sleepBase * 60 * retries));
                } catch (final InterruptedException e1) {
                    e1.printStackTrace();
                }
            }
        }
    }
    return conn;
}

From source file:msi.gama.application.workspace.WorkspaceModelsManager.java

/**
 * @param plugin//  w  w  w .  j  a va 2 s. co  m
 * @param core
 * @param workspace
 * @param project
 */
private static void importBuiltInProjects(final String plugin, final boolean core, final IWorkspace workspace,
        final Map<File, IPath> projects) {

    for (final Map.Entry<File, IPath> entry : projects.entrySet()) {
        final File project = entry.getKey();
        final IPath location = entry.getValue();
        final WorkspaceModifyOperation operation = new WorkspaceModifyOperation() {

            @Override
            protected void execute(final IProgressMonitor monitor)
                    throws CoreException, InvocationTargetException, InterruptedException {
                IProject proj = workspace.getRoot().getProject(project.getName());
                if (!proj.exists()) {
                    proj.create(workspace.loadProjectDescription(location), monitor);
                } else {
                    // project exists but is not accessible
                    if (!proj.isAccessible()) {
                        proj.delete(true, null);
                        proj = workspace.getRoot().getProject(project.getName());
                        proj.create(workspace.loadProjectDescription(location), monitor);
                    }
                }
                proj.open(IResource.NONE, monitor);
                setValuesProjectDescription(proj, true, !core, plugin);
            }
        };
        try {
            operation.run(null);
        } catch (final InterruptedException e) {
            e.printStackTrace();
        } catch (final InvocationTargetException e) {
            e.printStackTrace();
        }
    }

}

From source file:cn.kk.exia.MangaDownloader.java

private static String analyzeAndDownload(final String line, final int num, final Logger log,
        final boolean first, final String targetDir) throws IOException {
    String pageTitle = Helper.substringBetweenNarrow(line, "<h1>", "</h1>");
    if (Helper.isNotEmptyOrNull(pageTitle)) {
        if (Helper.isNotEmptyOrNull(MangaDownloader.mangaTitle)) {
            // System.out.println("??-title: " + MangaDownloader.mangaTitle);
            pageTitle = Helper.escapeFileName(StringEscapeUtils.unescapeHtml4(MangaDownloader.mangaTitle));
        } else {/*from   w w  w. j  a  va2 s.co  m*/
            // System.out.println("??-h1: " + pageTitle);
            pageTitle = Helper.escapeFileName(StringEscapeUtils.unescapeHtml4(pageTitle));
        }
        final File dir = new File(targetDir + File.separator + pageTitle);
        if (first) {
            log.log("??" + pageTitle);
        }
        dir.mkdirs();
        MangaDownloader.nextUrl = Helper.substringBetweenNarrow(line, "<a href=\"", "-" + num + "\"><img");
        if (Helper.isNotEmptyOrNull(MangaDownloader.nextUrl)) {
            MangaDownloader.nextUrl += "-" + num;
            final String img = Helper.substringBetweenNarrow(line.substring(line.indexOf("<iframe")),
                    "<img src=\"", "\" style=\"");
            if (Helper.isNotEmptyOrNull(img)) {
                try {
                    String imgName = img.substring(img.lastIndexOf('/'));
                    if (imgName.indexOf('=') != -1) {
                        imgName = imgName.substring(imgName.lastIndexOf('=') + 1);
                    }
                    imgName = Helper.escapeFileName(imgName);
                    String ext = ".jpg";
                    final int idx = imgName.lastIndexOf('.');
                    if (idx != -1) {
                        ext = imgName.substring(idx);
                    }
                    if (null != MangaDownloader.download(img,
                            new File(dir, pageTitle + "_" + num + ext).getAbsolutePath(), false, log)) {
                        log.log("?" + img);
                        try {
                            if (MangaDownloader.lineCounter++ >= 5) {
                                MangaDownloader.lineCounter = 0;
                                Thread.sleep((40 * MangaDownloader.sleepBase)
                                        + (int) (Math.random() * 12 * MangaDownloader.sleepBase)); // 12000
                            } else {
                                Thread.sleep((8 * MangaDownloader.sleepBase)
                                        + (int) (Math.random() * 5 * MangaDownloader.sleepBase));
                            }
                        } catch (final InterruptedException e) {
                            e.printStackTrace();
                            log.err("" + e.toString());
                        }
                    } else {
                        log.log("" + img);
                        try {
                            Thread.sleep((5 * MangaDownloader.sleepBase)
                                    + (int) (Math.random() * 5 * MangaDownloader.sleepBase));
                        } catch (final InterruptedException e) {
                            e.printStackTrace();
                            log.err("" + e.toString());
                        }
                    }
                } catch (final IOException e) {
                    // e.printStackTrace();
                    log.err("" + e.toString());
                    throw e;
                }
                return MangaDownloader.nextUrl;
            }
        }
    }
    return null;
}

From source file:edu.ucsd.sbrg.escher.EscherConverter.java

/**
 * Extracts CoBRA from {@link SBMLDocument} if it is FBC compliant. cobrapy must be present for
 * this.//from   w w  w.jav a2s.  com
 *
 * @param file Input file.
 * @return Result of extraction.
 * @throws IOException Thrown if there are problems in reading the {@code input} file(s).
 * @throws XMLStreamException Thrown if there are problems in parsing XML file(s).
 */
public static boolean extractCobraModel(File file) throws IOException, XMLStreamException {
    if (false) {
        logger.warning(format(bundle.getString("SBMLFBCNotAvailable"), file.getName()));
        return false;
    } else {
        logger.info(format(bundle.getString("SBMLFBCInit"), file.getName()));
        // Execute: py3 -c "from cobra import io;
        // io.save_json_model(model=io.read_sbml_model('FILENAME'), file_name='FILENAME')"

        String[] command;
        command = new String[] { "python3", "-c",
                "\"print('yo');from cobra import io;" + "io.save_json_model(model=io.read_sbml_model('"
                        + file.getAbsolutePath() + "'), file_name='" + file.getAbsolutePath() + ".json"
                        + "');print('yo')\"",
                "> /temp/log" };
        // command = new String[] {"/usr/local/bin/python3", "-c", "\"print('yo')\""};
        command = new String[] { "python3" };
        Process p;
        try {
            // p = new ProcessBuilder(command).redirectErrorStream(true).start();
            p = Runtime.getRuntime().exec(command);
            p.waitFor();
            if (p.exitValue() == 0) {
                logger.info(format(bundle.getString("SBMLFBCExtractionSuccessful"), file.getAbsolutePath(),
                        file.getAbsolutePath()));
                InputStream is = p.getErrorStream();
                is = p.getInputStream();
                OutputStream os = p.getOutputStream();
                BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream()));
                String cobrapy_output = "";
                cobrapy_output = reader.readLine();
                while (cobrapy_output != null) {
                    logger.warning(cobrapy_output);
                    cobrapy_output = reader.readLine();
                }
                return true;
            } else {
                logger.info(format(bundle.getString("SBMLFBCExtractionFailed")));
                BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream()));
                String cobrapy_output = "";
                cobrapy_output = reader.readLine();
                while (cobrapy_output != null) {
                    logger.warning(cobrapy_output);
                    cobrapy_output = reader.readLine();
                }
                return false;
            }
        } catch (InterruptedException e) {
            e.printStackTrace();
            return false;
        }
    }
}

From source file:com.grarak.kerneladiutor.utils.kernel.cpu.CPUFreq.java

public static String getGovernor(int cpu, boolean forceRead) {
    boolean offline = forceRead && isOffline(cpu);
    if (offline) {
        onlineCpu(cpu, true, false, null);
        try {/*from  w ww .jav  a  2  s.co m*/
            Thread.sleep(200);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

    String value = "";
    if (Utils.existFile(Utils.strFormat(CPU_SCALING_GOVERNOR, cpu))) {
        value = Utils.readFile(Utils.strFormat(CPU_SCALING_GOVERNOR, cpu));
    }

    if (offline) {
        onlineCpu(cpu, false, false, null);
    }
    return value;
}