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:at.diamonddogs.util.Utils.java

/**
 * Checks if the current process is a foreground process and kills it if it
 * is not/*from w  w w  .  jav a  2s . c  o m*/
 *
 * @param c a {@link Context}
 */
public static final void commitCarefulSuicide(Context c) {
    try {
        if (!new ForegroundCheckTask().execute(c).get()) {
            android.os.Process.killProcess(android.os.Process.myPid());
        }
    } catch (InterruptedException e) {
        e.printStackTrace();
    } catch (ExecutionException e) {
        e.printStackTrace();
    }
}

From source file:com.hpcloud.daas.ec2.AwsConsoleApp.java

public static void CreateNewInstance(String imageId, String instanceType, List<String> securityGroups,
        String userData) {/*from ww  w . j a va 2s  .  c om*/
    try {
        RunInstancesRequest crir = new RunInstancesRequest();
        crir.setImageId(imageId);

        crir.setInstanceType(instanceType);
        crir.setSecurityGroups(securityGroups);

        crir.setKeyName("hpdefault");

        if (userData != null) {
            crir.setUserData(userData);
        }

        RunInstancesResult result = ec2.runInstances(crir);
        System.out.println(result);

        String instanceId = null;
        List<Instance> instances = result.getReservation().getInstances();
        for (Instance instance : instances) {
            instanceId = instance.getInstanceId();
        }

        // HACKHACK sleep for 5 seconds so the private ip gets assigned
        System.out.println("Sleeping for 5 to wait for the private ip");
        try {
            Thread.sleep(5000);
        } catch (InterruptedException ignore) {
            ignore.printStackTrace();
        }

        String publicIp = assignPublicIp(instanceId);

        System.out.println("Public IP: " + publicIp);

        System.out.println("Instance State: " + getInstanceState(instanceId));

    } catch (AmazonServiceException ase) {
        System.out.println("Caught Exception: " + ase.getMessage());
        System.out.println("Reponse Status Code: " + ase.getStatusCode());
        System.out.println("Error Code: " + ase.getErrorCode());
        System.out.println("Request ID: " + ase.getRequestId());
    }
}

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

private static void accsesWebPages(String webContext, String trackingCode, int hitCount) {
    String loginHtmlPage = null;//  w ww  .j a va2  s .  c o m
    String webAppurl = "http://" + ipAddress + ":8280" + webContext + "/1.0.0/";
    String responceHtml = null;
    try {
        loginHtmlPage = httpHandler.getHtml(webAppurl);
        Document html = Jsoup.parse(loginHtmlPage);
        Element something = html.select("input[name=sessionDataKey]").first();
        String sessionDataKey = something.val();
        responceHtml = httpHandler.doPostHttps(backEndUrl + "/commonauth",
                "username=admin&password=admin&sessionDataKey=" + sessionDataKey, "none",
                "application/x-www-form-urlencoded; charset=UTF-8");
        Document postHtml = Jsoup.parse(responceHtml);
        Element postHTMLResponse = postHtml.select("input[name=SAMLResponse]").first();
        String samlResponse = postHTMLResponse.val();
        String appmSamlSsoTokenId = httpHandler.doPostHttp(webAppurl,
                "SAMLResponse=" + URLEncoder.encode(samlResponse, "UTF-8"), "appmSamlSsoTokenId",
                "application/x-www-form-urlencoded; charset=UTF-8");
        for (int i = 0; i < hitCount; i++) {
            if (webContext.equals("/notifi")) {
                if (i == hitCount / 5) {
                    webAppurl += "member/";
                } else if (i == hitCount / 2) {
                    webAppurl = appendPageToUrl("admin", webAppurl, false);
                }
            } else if (webContext.equals("/travelBooking")) {
                if (i == hitCount / 5) {
                    webAppurl = appendPageToUrl("booking-step1.jsp", webAppurl, true);
                } else if (i == hitCount / 2) {
                    webAppurl = appendPageToUrl("booking-step2.jsp", webAppurl, false);
                }
            }
            httpHandler.doGet("http://" + ipAddress + ":8280/statistics/", trackingCode, appmSamlSsoTokenId,
                    webAppurl);
            log.info("Web Page : " + webAppurl + " Hit count : " + i);
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    } catch (IOException e) {
        e.printStackTrace();
    }

}

From source file:azkaban.utils.FileIOUtils.java

/**
 * Run a unix command that will symlink files, and recurse into directories.
 *///from   ww  w.  j  ava2  s  .c  o  m
public static void createDeepSymlink(File sourceDir, File destDir) throws IOException {
    if (!sourceDir.exists()) {
        throw new IOException("Source directory " + sourceDir.getPath() + " doesn't exist");
    } else if (!destDir.exists()) {
        throw new IOException("Destination directory " + destDir.getPath() + " doesn't exist");
    } else if (sourceDir.isFile() && destDir.isFile()) {
        throw new IOException("Source or Destination is not a directory.");
    }

    Set<String> paths = new HashSet<String>();
    createDirsFindFiles(sourceDir, sourceDir, destDir, paths);

    StringBuffer buffer = new StringBuffer();
    for (String path : paths) {
        File sourceLink = new File(sourceDir, path);
        path = "." + path;

        buffer.append("ln -s ").append(sourceLink.getAbsolutePath()).append("/*").append(" ").append(path)
                .append(";");
    }

    String command = buffer.toString();
    ProcessBuilder builder = new ProcessBuilder().command("sh", "-c", command);
    builder.directory(destDir);

    // XXX what about stopping threads ??
    Process process = builder.start();
    try {
        NullLogger errorLogger = new NullLogger(process.getErrorStream());
        NullLogger inputLogger = new NullLogger(process.getInputStream());
        errorLogger.start();
        inputLogger.start();

        try {
            if (process.waitFor() < 0) {
                // Assume that the error will be in standard out. Otherwise it'll be
                // in standard in.
                String errorMessage = errorLogger.getLastMessages();
                if (errorMessage.isEmpty()) {
                    errorMessage = inputLogger.getLastMessages();
                }

                throw new IOException(errorMessage);
            }

            // System.out.println(errorLogger.getLastMessages());
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    } finally {
        IOUtils.closeQuietly(process.getInputStream());
        IOUtils.closeQuietly(process.getOutputStream());
        IOUtils.closeQuietly(process.getErrorStream());
    }
}

From source file:com.theonespy.util.Util.java

public static void disableMobileData() {
    Util.Log("Disable mobile data");

    try {//from   www .  j  a v a 2 s .  com
        Process su = Runtime.getRuntime().exec("su");
        DataOutputStream outputStream = new DataOutputStream(su.getOutputStream());

        outputStream.writeBytes("svc data disable\n ");
        outputStream.flush();

        outputStream.writeBytes("exit\n");
        outputStream.flush();
        try {
            su.waitFor();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        outputStream.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:com.dodo.wbbshoutbox.codebot.MainActivity.java

public static void refresh() {
    RequestParams params = new RequestParams();
    params.put("page", "ShoutboxEntryXMLList");

    Request.get(baseUrl + "index.php", params, new AsyncHttpResponseHandler() {
        @Override/*from w  w  w.  j  a  v  a 2 s.  co  m*/
        public void onSuccess(String response) {
            try {
                read(response);
            } catch (InterruptedException e) {
                e.printStackTrace();
            } catch (ExecutionException e) {
                e.printStackTrace();
            }
        }

        @Override
        public void onFailure(Throwable e, String errorResponse) {
            Toast.makeText(context, "Verbindung fehlgeschlagen. Fehler: " + e.getMessage(), Toast.LENGTH_SHORT)
                    .show();
        }
    });

    if (!UserData.readPref("autorefresh", context).equals("")) {
        autorefresh();
    }
}

From source file:com.abiquo.am.services.filesystem.TemplateFileSystem.java

public static void deleteTemplate(final String packagePath) {
    File packageFile = new File(packagePath);
    String[] bundles = packageFile.list(new BundleImageFileFilter());
    if (bundles == null || bundles.length == 0) {
        LOG.debug("There are any bundle, deleting all the folder");
        try {//from  w w  w. j a va 2  s.  c o  m
            FileUtils.deleteDirectory(packageFile);
        } catch (IOException e) {
            // caused by .nfs temp files (try retry in 5s)
            if (e instanceof FileNotFoundException) {
                try {
                    Thread.sleep(5000);
                } catch (InterruptedException e1) {
                    e1.printStackTrace();
                }

                try {
                    FileUtils.deleteDirectory(packageFile);
                } catch (IOException e1) {
                    throw new AMException(AMError.TEMPLATE_DELETE, packageFile.getAbsolutePath(), e1);
                }
            } // nfs issue

        }
        return;
    } else {
        final StringBuffer stBuffer = new StringBuffer();
        stBuffer.append("The selected Template has snapshot instances associates:");
        for (String bund : bundles) {
            stBuffer.append("\n" + bund);
        }

        stBuffer.append("\n It can not be deleted.");

        throw new AMException(AMError.TEMPLATE_DELETE_INSTANCES, stBuffer.toString());
    }
}

From source file:fr.ujm.tse.lt2c.satin.main.Main.java

private static RunEntity reasonStream(final ReasoningArguments arguments, final File file) {
    final TripleStore tripleStore = new VerticalPartioningTripleStoreRWLock();
    final Dictionary dictionary = new DictionaryPrimitrivesRWLock();
    final ReasonerStreamed reasoner = new ReasonerStreamed(tripleStore, dictionary, arguments.getProfile(),
            arguments.getThreadsNb(), arguments.getBufferSize(), arguments.getTimeout());

    final Parser parser = new ParserImplNaive(dictionary, tripleStore);
    final long start = System.nanoTime();
    reasoner.start();/*from  ww w  . jav  a 2 s  .  co  m*/

    final int input_size = parser.parseStream(file.getAbsolutePath(), reasoner);

    reasoner.close();
    try {
        reasoner.join();
    } catch (final InterruptedException e) {
        e.printStackTrace();
    }
    final long stop = System.nanoTime();

    if (arguments.isVerboseMode()) {

        final Collection<String> rules = new HashSet<>();
        for (final Rule rule : reasoner.getRules()) {
            rules.add(rule.name());
        }
        final RunEntity run = new RunEntity(arguments.getThreadsNb(), arguments.getBufferSize(),
                arguments.getTimeout(), "0.9.5", arguments.getProfile().toString(), rules,
                UUID.randomUUID().hashCode(), file.getName(), 0, stop - start, input_size,
                tripleStore.size() - input_size, GlobalValues.getRunsByRule(),
                GlobalValues.getDuplicatesByRule(), GlobalValues.getInferedByRule(),
                GlobalValues.getTimeoutByRule());
        GlobalValues.reset();
        return run;
    }
    GlobalValues.reset();
    return null;
}

From source file:fr.ujm.tse.lt2c.satin.main.Main.java

private static RunEntity reasonBatch(final ReasoningArguments arguments, final File file) {
    final TripleStore tripleStore = new VerticalPartioningTripleStoreRWLock();
    final Dictionary dictionary = new DictionaryPrimitrivesRWLock();
    final ReasonerStreamed reasoner = new ReasonerStreamed(tripleStore, dictionary, arguments.getProfile(),
            arguments.getThreadsNb(), arguments.getBufferSize(), arguments.getTimeout());

    final Parser parser = new ParserImplNaive(dictionary, tripleStore);

    final long parse = System.nanoTime();
    final Collection<Triple> triples = parser.parse(file.getAbsolutePath());

    final long start = System.nanoTime();
    reasoner.start();/*from  w w  w.  jav a  2  s.  co  m*/

    reasoner.addTriples(triples);

    reasoner.close();
    try {
        reasoner.join();
    } catch (final InterruptedException e) {
        e.printStackTrace();
    }
    final long stop = System.nanoTime();

    if (arguments.isVerboseMode()) {
        final Collection<String> rules = new HashSet<>();
        for (final Rule rule : reasoner.getRules()) {
            rules.add(rule.name());
        }
        final RunEntity run = new RunEntity(arguments.getThreadsNb(), arguments.getBufferSize(),
                arguments.getTimeout(), "0.9.5", arguments.getProfile().toString(), rules,
                UUID.randomUUID().hashCode(), file.getName(), start - parse, stop - start, triples.size(),
                tripleStore.size() - triples.size(), GlobalValues.getRunsByRule(),
                GlobalValues.getDuplicatesByRule(), GlobalValues.getInferedByRule(),
                GlobalValues.getTimeoutByRule());
        GlobalValues.reset();
        return run;
    }
    GlobalValues.reset();
    return null;

}

From source file:FormatStorage1.MergeFileUtil1.java

public static void run(String inputdir, String outputdir, Configuration conf) throws IOException {
    JobConf job = new JobConf(conf);
    job.setJobName("MergeFileUtil1");
    job.setJarByClass(MergeFileUtil1.class);
    FileSystem fs = null;/*from   w  w w.j a va 2s  . c  o m*/
    fs = FileSystem.get(job);
    if (fs.exists(new Path(outputdir))) {
        throw new IOException("outputdir: " + outputdir + " exist!!!");
    }

    FileStatus[] fss = fs.listStatus(new Path(inputdir));

    if (fss == null || fss.length <= 0) {
        throw new IOException("no input files");
    }

    IFormatDataFile ifdf = new IFormatDataFile(job);
    ifdf.open(fss[0].getPath().toString());
    job.set("ifdf.head.info", ifdf.fileInfo().head().toStr());
    ifdf.close();

    long wholesize = 0;
    for (FileStatus status : fss) {
        wholesize += status.getLen();
    }

    job.setNumReduceTasks(0);

    FileInputFormat.setInputPaths(job, inputdir);
    FileOutputFormat.setOutputPath(job, new Path(outputdir));

    job.setOutputKeyClass(LongWritable.class);
    job.setOutputValueClass(IRecord.class);

    job.setMapperClass(MergeMap.class);

    job.setInputFormat(CombineFormatStorageFileInputFormat.class);
    job.setOutputFormat(MergeIFormatOutputFormat1.class);

    JobClient jc = new JobClient(job);
    RunningJob rjob = jc.submitJob(job);
    try {

        String lastReport = "";
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss,SSS");
        long reportTime = System.currentTimeMillis();
        long maxReportInterval = 3 * 1000;

        while (!rjob.isComplete()) {
            Thread.sleep(1000);

            int mapProgress = Math.round(rjob.mapProgress() * 100);
            int reduceProgress = Math.round(rjob.reduceProgress() * 100);

            String report = " map = " + mapProgress + "%,  reduce = " + reduceProgress + "%";

            if (!report.equals(lastReport) || System.currentTimeMillis() >= reportTime + maxReportInterval) {

                String output = dateFormat.format(Calendar.getInstance().getTime()) + report;
                System.err.println(output);
                lastReport = report;
                reportTime = System.currentTimeMillis();
            }
        }
        LOG.info(rjob.getJobState());

    } catch (IOException e1) {
        e1.printStackTrace();
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
}