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:net.mceoin.cominghome.api.NestUtil.java

public static String getNestAwayStatus(String access_token) {
    String result = getNestAwayStatusCall(access_token);

    if ((result.contains("Error:")) && (!result.contains("Unauthorized"))) {
        // Try again if it was an Error but not an Unauthorized
        try {//  w w w.  ja v a2s  .co m
            Random randomGenerator = new Random();
            int seconds = 5 + randomGenerator.nextInt(10);
            log.info("retry in " + seconds + " seconds");
            Thread.sleep(seconds * 1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        result = getNestAwayStatusCall(access_token);
    }

    return result;
}

From source file:fr.inria.eventcloud.deployment.cli.launchers.EventCloudsManagementServiceDeployer.java

/**
 * Deploys an EventCloudsRegistry and an EventClouds Management Service in a
 * separate JVM according to the specified parameters.
 * //from  w w  w  .ja  v a2s .c om
 * @param onRelease
 *            {@code true} if the lastest release of the EventCloud has to
 *            be used, {@code false} to use the latest snapshot version.
 * @param port
 *            the port used to deploy the EventClouds Management Service and
 *            which will also be used to deploy WS-Notification services.
 * @param urlSuffix
 *            the suffix appended to the end of the URL associated to the
 *            EventClouds Management Service to be deployed.
 * @param activateLoggers
 *            {@code true} if the loggers have to be activated,
 *            {@code false} otherwise.
 * @param properties
 *            additional Java properties set to the new JVM.
 * 
 * @return the endpoint URL of the EventClouds Management Service.
 * 
 * @throws IOException
 *             if an error occurs during the deployment.
 */
public synchronized static String deploy(boolean onRelease, int port, String urlSuffix, boolean activateLoggers,
        String... properties) throws IOException {
    if (eventCloudsManagementServiceProcess == null) {
        String binariesBaseUrl = EVENTCLOUD_BINARIES_URL;

        if (onRelease) {
            binariesBaseUrl += "releases/latest/";
        } else {
            binariesBaseUrl += "snapshots/latest/";
        }

        List<String> cmd = new ArrayList<String>();

        String javaBinaryPath = System.getProperty("java.home") + File.separator + "bin" + File.separator
                + "java";
        if (System.getProperty("os.name").startsWith("Windows")) {
            javaBinaryPath = javaBinaryPath + ".exe";
        }
        cmd.add(javaBinaryPath);

        cmd.add("-cp");
        cmd.add(addClassPath(binariesBaseUrl + "libs/"));

        cmd.addAll(addProperties(binariesBaseUrl + "resources/", activateLoggers));

        Collections.addAll(cmd, properties);

        cmd.add(EventCloudsManagementServiceDeployer.class.getCanonicalName());
        cmd.add(Integer.toString(port));
        cmd.add(urlSuffix);

        final ProcessBuilder processBuilder = new ProcessBuilder(cmd.toArray(new String[cmd.size()]));
        processBuilder.redirectErrorStream(true);
        eventCloudsManagementServiceProcess = processBuilder.start();

        final BufferedReader reader = new BufferedReader(
                new InputStreamReader(eventCloudsManagementServiceProcess.getInputStream()));
        Thread t = new Thread(new Runnable() {
            @Override
            public void run() {
                String line = null;
                try {
                    while ((line = reader.readLine()) != null) {
                        if (!servicesDeployed.getValue() && line.contains(LOG_MANAGEMENT_WS_DEPLOYED)) {
                            servicesDeployed.setValue(true);
                            synchronized (servicesDeployed) {
                                servicesDeployed.notifyAll();
                            }
                        }
                        System.out.println("ECManagement " + line);
                    }
                } catch (IOException ioe) {
                    ioe.printStackTrace();
                }
            }
        });
        t.setDaemon(true);
        t.start();

        synchronized (servicesDeployed) {
            while (!servicesDeployed.getValue()) {
                try {
                    servicesDeployed.wait();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }

        StringBuilder eventCloudsManagementWsEndpoint = new StringBuilder("http://");
        eventCloudsManagementWsEndpoint.append(ProActiveInet.getInstance().getInetAddress().getHostAddress());
        eventCloudsManagementWsEndpoint.append(':');
        eventCloudsManagementWsEndpoint.append(port);
        eventCloudsManagementWsEndpoint.append('/');
        eventCloudsManagementWsEndpoint.append(urlSuffix);
        return eventCloudsManagementWsEndpoint.toString();
    } else {
        throw new IllegalStateException("EventClouds management process already deployed");
    }
}

From source file:eu.smartfp7.foursquare.AttendanceCrawler.java

/**
 * We use the entire hour to do all the calls. This method calculates the
 * amount of time the program has to sleep in order to finish crawling
 * every venue before the end of the current hour.
 * It does not account for already crawled venues: sleep time decreases
 * as the hour progresses./*w w w . j  av  a  2 s.  c  om*/
 * Crawling all venues takes thus approximately 40 minutes.
 * 
 */
public static void intelligentWait(int total_venues, long current_time, long avg_time_spent_crawling) {
    try {
        double time = (DateUtils.truncate(new Date(current_time + 3600000), Calendar.HOUR).getTime()
                - current_time) / (double) total_venues;
        if (Math.round(time) < avg_time_spent_crawling)
            avg_time_spent_crawling = 0;
        Thread.sleep(Math.round(time) - avg_time_spent_crawling);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
}

From source file:com.logicmonitor.ft.jmxstat.JMXStatMain.java

private static void statJMXValues(JMXMan jmxMan, RunParameter runParameter) {
    AnsiConsole.systemInstall();//from   w  w  w.ja v a2 s  . c  o  m

    if (!jmxMan.hasFullPath()) {
        System.err.print("Can not discover any full path for inputted paths, please check the path format!");
        exit(-1);
    }
    List<String> lastValues;
    List<String> values;
    lastValues = jmxMan.getValues();
    List<JMXFullPath> jmxFullPaths = jmxMan.getJmxFullPaths();
    int columnLen[] = new int[jmxFullPaths.size()];

    _showCompanyInfo();
    if (runParameter.isShowAliasTitle()) {
        for (int i = 0; i < jmxFullPaths.size(); i++) {
            int tmp = jmxFullPaths.get(i).getDomain().length() > jmxFullPaths.get(i).getPropertyList().length()
                    ? jmxFullPaths.get(i).getDomain().length()
                    : jmxFullPaths.get(i).getPropertyList().length();
            int tmp2 = jmxFullPaths.get(i).getSelectorStr().length() > jmxFullPaths.get(i).getAlias().length()
                    ? jmxFullPaths.get(i).getSelectorStr().length()
                    : jmxFullPaths.get(i).getAlias().length();

            columnLen[i] = tmp > tmp2 ? tmp : tmp2;
        }
        _showTitles(jmxFullPaths, columnLen);
    } else {
        for (int i = 0; i < jmxFullPaths.size(); i++) {
            columnLen[i] = jmxFullPaths.get(i).getPath().length();
        }
        _showPathTitles(jmxFullPaths);
    }
    int times = runParameter.getTimes();
    int interval = runParameter.getInterval();

    if (times > 0) {

        while (times > 0) {
            values = jmxMan.getValues();
            _showValues(jmxFullPaths, values, lastValues, columnLen);
            times--;
            lastValues = values;
            try {
                Thread.sleep(interval * 1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    } else {
        while (true) {
            values = jmxMan.getValues();
            _showValues(jmxFullPaths, values, lastValues, columnLen);
            lastValues = values;
            try {
                Thread.sleep(interval * 1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }

    AnsiConsole.systemUninstall();
}

From source file:io.Tools.java

public static AlgoParameters generateModifiedAlgoParametersForTestWithTestFoldersWithUltiJmol(int threadCount)
        throws ParsingConfigFileException, IOException {

    AlgoParameters algoParameters = generateModifiedAlgoParametersForTestWithTestFolders();
    algoParameters.setSHAPE_COMPARISON_THREAD_COUNT(threadCount);
    // add a ultiJmol which is needed in the ShapeBuilder

    algoParameters.ultiJMolBuffer = new GenericBuffer<UltiJmol1462>(
            algoParameters.getSHAPE_COMPARISON_THREAD_COUNT() * 2);

    for (int i = 0; i < (algoParameters.getSHAPE_COMPARISON_THREAD_COUNT() * 2); i++) {

        UltiJmol1462 ultiJMol = new UltiJmol1462();
        try {//  w  w  w.j  a v a2s .c  om
            algoParameters.ultiJMolBuffer.put(ultiJMol);
        } catch (InterruptedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
    algoParameters.procrustesAnalysisBuffer = new GenericBuffer<ProcrustesAnalysisIfc>(
            algoParameters.getSHAPE_COMPARISON_THREAD_COUNT());

    for (int i = 0; i < algoParameters.getSHAPE_COMPARISON_THREAD_COUNT(); i++) {

        ProcrustesAnalysisIfc procrustesAnalysisIfc = new ProcrustesAnalysis();
        try {
            algoParameters.procrustesAnalysisBuffer.put(procrustesAnalysisIfc);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
    return algoParameters;
}

From source file:com.frostwire.AzureusStarter.java

private static synchronized void azureusInit() {

    try {// w  w w . j a  v a  2s . com
        if (isAzureusCoreStarted()) {
            LOG.debug("azureusInit(): core already started. skipping.");
            return;
        }
    } catch (Exception ignore) {
    }

    Application.setApplication(
            CommonUtils.getUserSettingsDir().getAbsolutePath() + File.separator + "appwork" + File.separator);
    File jdHome = new File(
            CommonUtils.getUserSettingsDir().getAbsolutePath() + File.separator + "jd_home" + File.separator);
    if (!jdHome.exists()) {
        jdHome.mkdir();
    }
    JDUtilities.setJDHomeDirectory(jdHome);
    JDUtilities.getConfiguration().setProperty("DOWNLOAD_DIRECTORY",
            SharingSettings.TORRENT_DATA_DIR_SETTING.getValue().getAbsolutePath());

    File azureusUserPath = new File(
            CommonUtils.getUserSettingsDir() + File.separator + "azureus" + File.separator);
    if (!azureusUserPath.exists()) {
        azureusUserPath.mkdirs();
    }

    System.setProperty("azureus.loadplugins", "0"); // disable third party azureus plugins
    System.setProperty("azureus.config.path", azureusUserPath.getAbsolutePath());
    System.setProperty("azureus.install.path", azureusUserPath.getAbsolutePath());

    if (!AzureusCoreFactory.isCoreAvailable()) {
        //This does work
        org.gudy.azureus2.core3.util.SystemProperties.APPLICATION_NAME = "azureus";

        org.gudy.azureus2.core3.util.SystemProperties.setUserPath(azureusUserPath.getAbsolutePath());

        if (!SharingSettings.TORRENTS_DIR_SETTING.getValue().exists()) {
            SharingSettings.TORRENTS_DIR_SETTING.getValue().mkdirs();
        }

        COConfigurationManager.setParameter("Auto Adjust Transfer Defaults", false);
        COConfigurationManager.setParameter("General_sDefaultTorrent_Directory",
                SharingSettings.TORRENTS_DIR_SETTING.getValue().getAbsolutePath());

        try {
            AZUREUS_CORE = AzureusCoreFactory.create();
        } catch (AzureusCoreException coreException) {
            //so we already had one eh...
            if (AZUREUS_CORE == null) {
                AZUREUS_CORE = AzureusCoreFactory.getSingleton();
            }
        }

        //to guarantee a synchronous start
        final CountDownLatch signal = new CountDownLatch(1);

        AZUREUS_CORE.addLifecycleListener(new AzureusCoreLifecycleListener() {

            @Override

            public boolean syncInvokeRequired() {
                return false;
            }

            @Override
            public void stopping(AzureusCore core) {
                core.getGlobalManager().pauseDownloads();
            }

            @Override
            public void stopped(AzureusCore core) {
            }

            @Override
            public boolean stopRequested(AzureusCore core) throws AzureusCoreException {
                return false;
            }

            @Override
            public void started(AzureusCore core) {
                signal.countDown();
            }

            @Override
            public boolean restartRequested(AzureusCore core) throws AzureusCoreException {
                return false;
            }

            @Override
            public boolean requiresPluginInitCompleteBeforeStartedEvent() {
                return false;
            }

            @Override
            public void componentCreated(AzureusCore core, AzureusCoreComponent component) {
            }
        });

        if (!AZUREUS_CORE.isStarted() && !AZUREUS_CORE.isRestarting()) {
            AZUREUS_CORE.start();
        }

        AZUREUS_CORE.getGlobalManager().resumeDownloads();

        LOG.debug("azureusInit(): core.start() waiting...");
        try {
            signal.await();
            LOG.debug("azureusInit(): core started...");
        } catch (InterruptedException e) {

            e.printStackTrace();
        }
    }
}

From source file:com.github.chenxiaolong.dualbootpatcher.CommandUtils.java

public static void waitForCommand(CommandRunner cmd) {
    try {/*from  w  w w  . j  a  v a 2s. c  om*/
        cmd.join();
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
}

From source file:com.github.chenxiaolong.dualbootpatcher.CommandUtils.java

public static void waitForRootCommand(RootCommandRunner cmd) {
    try {/*from w  w  w  . ja va 2  s . co  m*/
        cmd.join();
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
}

From source file:com.robin.utilities.Utilities.java

/**
 * A utility that waits for a specific amount of time.
 * @param timeToWait Time to wait in ms.
 *//*w  ww  . j av a2s  .co  m*/
public static void waitTime(final long timeToWait) {
    try {
        Thread.sleep(timeToWait);
    } catch (InterruptedException e) {
        Reporter.log(e.getMessage());
        e.printStackTrace();
    }
}

From source file:com.jktsoftware.amazondownloader.download.Application.java

public static void processQueue() {
    //load spring.xml configuration file
    ApplicationContext context = new ClassPathXmlApplicationContext(new String[] { "spring.xml" });

    //create an s3 bucket type repository object
    IObjectRepo repo = (IObjectRepo) context.getBean("s3bucket");

    if (!_awsS3accesskey.isEmpty() && !_awsS3secretkey.isEmpty()) {
        //if the aws S3 command line parameters are present then
        //override them
        ICredentials overridecredentials = (ICredentials) new AwsCredentials(_awsS3accesskey, _awsS3secretkey);
        repo.setCredentials(overridecredentials);
    }/*w w w  .  j  a  va  2s .  co m*/

    System.out.println(repo.getCredentials().getAccessKey());

    //setup the amazon sqs based queue manager
    IQueueManager queuemanager = (IQueueManager) context.getBean("queuemanager");

    if (!_awsSQSaccesskey.isEmpty() && !_awsSQSsecretkey.isEmpty()) {
        //if the aws SQS command line parameters are present then
        //override them
        ICredentials overridecredentials = (ICredentials) new AwsCredentials(_awsSQSaccesskey,
                _awsSQSsecretkey);
        queuemanager.setCredentials(overridecredentials);
    }

    //if success queue name is specified in commandline use it instead
    if (!_awsSQSsuccessqueue.isEmpty()) {
        queuemanager.setSuccessQueueName(_awsSQSsuccessqueue);
    }

    //if fail queue name is specified in commandline use it instead
    if (!_awsSQSfailqueue.isEmpty()) {
        queuemanager.setFailQueueName(_awsSQSfailqueue);
    }

    //create queues on the cloud platform
    queuemanager.CreateQueues();

    System.out.println(queuemanager.getCredentials().getAccessKey());

    //set the repository id if it has been overridden by commandline
    if (!_argrepoid.isEmpty()) {
        repo.setRepoId(_argrepoid);
    }

    //get a list of all objects in the repository
    List<IObject> objectsinrepo = repo.getObjectsInRepo();

    //if the listobject option has been specified print a list
    //of objects and the associate properties to the console
    if (_arglistobjects) {
        listObjects(objectsinrepo);
    }

    //if the -download option has been specified then commence
    //downloading the objects from the repository
    if (_argstartdownloads) {
        //loop throught the objects in the repository
        for (IObject objecttodownload : objectsinrepo) {
            if (_argobjectidtodownload.contentEquals("")
                    || objecttodownload.getObjectKey().contentEquals(_argobjectidtodownload)) {
                //download the object
                downloadObject(objecttodownload, queuemanager);
                //print the pause message
                System.out.println("Pausing for " + _argwaittime + " milliseconds");
                try {
                    //sleep for the specified amount of time
                    Thread.sleep(_argwaittime);
                } catch (InterruptedException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
        }
    }
}