Example usage for java.lang StackTraceElement toString

List of usage examples for java.lang StackTraceElement toString

Introduction

In this page you can find the example usage for java.lang StackTraceElement toString.

Prototype

public String toString() 

Source Link

Document

Returns a string representation of this stack trace element.

Usage

From source file:luceneprueba.Reader.java

public void searchOnIndex(String wordQuery, String date) {
    // Parse a simple query that searches for "text":
    QueryParser parser = new QueryParser("review", analyzer);
    Query query;//ww  w  .j  a  v a2s. c  o m
    try {
        query = parser.parse("date: \"+" + date + "\" AND " + cleanInput(wordQuery));
        ScoreDoc[] hits = indexSearcher.search(query, 60).scoreDocs;

        if (hits.length == 0) {
            //System.out.println("[Search] No se han encontrado coincidencias.");
        } else {
            //System.out.println("[Search] Se han encontrado: " + hits.length + " coincidencias.");
            JSONArray reviews = new JSONArray();
            for (ScoreDoc hit : hits) {
                Document hitDoc = indexSearcher.doc(hit.doc);
                //System.out.println(i+".- Score: " + hit.score + ", Doc: " + hitDoc.get("movieId") + ", path: " + hitDoc.get("path") + ", Tile review: " + hitDoc.get("title"));
                JSONObject json = new JSONObject();
                json.put("date", hitDoc.get("date"));
                json.put("genre", hitDoc.get("genre"));
                json.put("review", hitDoc.get("review"));
                json.put("score", hitDoc.get("score"));
                reviews.add(json);
            }
            try (FileWriter file = new FileWriter(
                    "files/output/top-k/reviews_" + date.replace(" ", "") + ".json")) {
                file.write(reviews.toJSONString());
                file.flush();
                //indexReader.close();
            }
        }

    } catch (ParseException | IOException ex) {
        Logger.getLogger(Reader.class.getName()).log(Level.SEVERE, null, ex);
        for (StackTraceElement st : ex.getStackTrace()) {
            System.out.println(st.toString());
        }
        System.out.println(ex.getLocalizedMessage());
    }

}

From source file:org.obiba.opal.shell.commands.ImportCommand.java

private void printThrowable(Throwable ex, boolean withStack, int depth) {
    //only prints message for the top exception
    if (depth == 0 && !Strings.isNullOrEmpty(ex.getMessage()))
        getShell().printf(ex.getMessage());

    StringBuilder sb = new StringBuilder();
    if (depth > 0) {
        sb.append("Caused by: ");
        sb.append(ex.toString()).append("\n");
    }/*  w w w  .j a  v a 2s . c o  m*/

    if (withStack) {
        for (StackTraceElement elem : ex.getStackTrace()) {
            sb.append(elem.toString()).append("\n");
        }
        getShell().printf(sb.toString());
    }

    Throwable cause = ex.getCause();
    //we only recurse if there is a cause and not the exception itself (quite common cause of endless loops)
    if (cause != null && cause != ex) {
        printThrowable(cause, withStack, depth + 1);
    }
}

From source file:luceneprueba.Reader.java

public List<Review> getListBySearchOnIndex(String wordQuery, String date) {
    List<Review> reviews = new ArrayList();
    // Parse a simple query that searches for "text":
    QueryParser parser = new QueryParser("review", analyzer);
    Query query;/*from   w  w  w.ja va  2s. co  m*/
    Review nullReview = new Review();
    try {
        //If para parchar el error de la fecha 21 Enero 2015
        if (date.equals("20150122")) {
            //wordQuery = wordQuery.substring(7, wordQuery.length());
            System.out.println(">>>>>>>>WORD QUERY: " + wordQuery);
        }
        query = parser.parse("date: \"+" + date + "\" AND " + cleanInput(wordQuery));
        ScoreDoc[] hits = indexSearcher.search(query, 60).scoreDocs;

        if (hits.length == 0) {
            //System.out.println("[Search] No se han encontrado coincidencias.");
        } else {
            System.out.println(
                    "[Search] Dia " + date + ": Se han encontrado: " + hits.length + " coincidencias.");
            for (ScoreDoc hit : hits) {
                Document hitDoc = indexSearcher.doc(hit.doc);

                String[] c1 = hitDoc.get("clasif1").split(", ");
                String[] c2 = hitDoc.get("clasif2").split(", ");

                double[] clasif1 = { Double.parseDouble(c1[0]), Double.parseDouble(c1[1]),
                        Double.parseDouble(c1[2]) };
                double[] clasif2 = { Double.parseDouble(c2[0]), Double.parseDouble(c2[1]),
                        Double.parseDouble(c2[2]) };

                reviews.add(new Review(Integer.parseInt(hitDoc.get("date")),
                        Double.parseDouble(hitDoc.get("score")), hitDoc.get("genre").split(", "), clasif1,
                        clasif2));
            }
        }

    } catch (ParseException | IOException ex) {
        for (StackTraceElement st : ex.getStackTrace()) {
            System.out.println(st.toString());
        }
        System.out.println(ex.getLocalizedMessage());
    }
    return reviews;
}

From source file:luceneprueba.Reader.java

public void searchOnIndexByDate() {
    // Parse a simple query that searches for "text":
    QueryParser parser = new QueryParser("review", analyzer);
    Query query;//from  www.  j a  va 2 s . c  o  m
    try {
        BufferedReader br = new BufferedReader(new FileReader("files/dates_reviews"));
        String date;

        JSONArray reviews = new JSONArray();

        while ((date = br.readLine()) != null) {
            query = parser.parse("date: \"+" + date + "\"");
            ScoreDoc[] hits = indexSearcher.search(query, 1).scoreDocs;

            if (hits.length == 0) {
                System.out.println("No se encontraron reviews para la fecha " + date);
            } else {
                System.out.println("Guardando review de la fecha " + date);
                Document hitDoc = indexSearcher.doc(hits[0].doc);

                JSONObject json = new JSONObject();
                json.put("date", hitDoc.get("date"));
                //json.put("genre", hitDoc.get("genre"));
                json.put("review", hitDoc.get("review"));
                //json.put("score", hitDoc.get("score"));
                reviews.add(json);

            }
        }

        try (FileWriter file = new FileWriter("files/output/review_date.json")) {
            file.write(reviews.toJSONString());
            file.flush();
        }
        //indexReader.close();

    } catch (ParseException | IOException ex) {
        Logger.getLogger(Reader.class.getName()).log(Level.SEVERE, null, ex);
        for (StackTraceElement st : ex.getStackTrace()) {
            System.out.println(st.toString());
        }
        System.out.println(ex.getLocalizedMessage());
    }

}

From source file:FullThreadDump.java

private void printThreadInfo(ThreadInfo ti) {
    // print thread information
    printThread(ti);//from  w  ww .java 2  s  . c  o m

    // print stack trace with locks
    StackTraceElement[] stacktrace = ti.getStackTrace();
    MonitorInfo[] monitors = ti.getLockedMonitors();
    for (int i = 0; i < stacktrace.length; i++) {
        StackTraceElement ste = stacktrace[i];
        System.out.println(INDENT + "at " + ste.toString());
        for (MonitorInfo mi : monitors) {
            if (mi.getLockedStackDepth() == i) {
                System.out.println(INDENT + "  - locked " + mi);
            }
        }
    }
    System.out.println();
}

From source file:luceneprueba.Reader.java

public List<Review> getListFromSearchOnIndexByDate() {
    List<Review> reviews = new ArrayList();
    // Parse a simple query that searches for "text":
    QueryParser parser = new QueryParser("review", analyzer);
    Query query;/*w  w w .j  ava2s.c o m*/
    Review nullReview = new Review();
    try {
        BufferedReader br = new BufferedReader(new FileReader("files/dates_reviews"));
        String date;

        while ((date = br.readLine()) != null) {
            query = parser.parse("date: \"+" + nullReview.convertDate(date) + "\"");
            ScoreDoc[] hits = indexSearcher.search(query, 1).scoreDocs;

            if (hits.length == 0) {
                System.out.println("No se encontraron reviews para la fecha " + date);
            } else {
                //System.out.println("Guardando review de la fecha " + date);
                Document hitDoc = indexSearcher.doc(hits[0].doc);

                String[] c1 = hitDoc.get("clasif1").split(", ");
                String[] c2 = hitDoc.get("clasif2").split(", ");

                double[] clasif1 = { Double.parseDouble(c1[0]), Double.parseDouble(c1[1]),
                        Double.parseDouble(c1[2]) };
                double[] clasif2 = { Double.parseDouble(c2[0]), Double.parseDouble(c2[1]),
                        Double.parseDouble(c2[2]) };

                reviews.add(new Review(Integer.parseInt(hitDoc.get("date")), hitDoc.get("review"),
                        Double.parseDouble(hitDoc.get("score")), hitDoc.get("genre").split(", "), clasif1,
                        clasif2));

                /*
                if(nullReview.convertDate(date) == 20150121){
                if(hitDoc.get("review").substring(0, 1).equals(" ")){
                    System.out.println(">>>>>>>> EL error es un espacio");
                }
                System.out.println(">>>>>>>REVIEW CON ERROR: "+Integer.parseInt(hitDoc.get("date")) + 
                                   hitDoc.get("review") +
                                   Double.parseDouble(hitDoc.get("score")) + 
                                   Arrays.toString(hitDoc.get("genre").split(", ")) + 
                                   Arrays.toString(clasif1) + 
                                   Arrays.toString(clasif2));
                }
                */
            }
        }

        //indexReader.close();

    } catch (ParseException | IOException ex) {
        Logger.getLogger(Reader.class.getName()).log(Level.SEVERE, null, ex);
        for (StackTraceElement st : ex.getStackTrace()) {
            System.out.println(st.toString());
        }
        System.out.println(ex.getLocalizedMessage());

    }
    return reviews;
}

From source file:org.apache.nutch.fetcher.FetcherReducer.java

private void checkAndReportNativeFetcherStatus(Context context) throws IOException {
    // Used for threshold check, holds pages and bytes processed in the last sec
    int throughputThresholdCurrentSequence = 0;

    int throughputThresholdPages = conf.getInt("fetcher.throughput.threshold.pages", -1);
    if (LOG.isInfoEnabled()) {
        LOG.info("Fetcher: throughput threshold: " + throughputThresholdPages);
    }/*  www  . jav  a  2s  . c  o  m*/
    int throughputThresholdSequence = conf.getInt("fetcher.throughput.threshold.sequence", 5);
    if (LOG.isInfoEnabled()) {
        LOG.info("Fetcher: throughput threshold sequence: " + throughputThresholdSequence);
    }
    long throughputThresholdTimeLimit = conf.getLong("fetcher.throughput.threshold.check.after", -1);

    do {
        float pagesLastSec = fetchManager.waitAndReport(context, reportIntervalSec, isFeederAlive());

        // if throughput threshold is enabled
        if (throughputThresholdTimeLimit < System.currentTimeMillis() && throughputThresholdPages != -1) {
            // Check if we're dropping below the threshold
            if (pagesLastSec < throughputThresholdPages) {
                throughputThresholdCurrentSequence++;

                LOG.warn(Integer.toString(throughputThresholdCurrentSequence)
                        + ": dropping below configured threshold of "
                        + Integer.toString(throughputThresholdPages) + " pages per second");

                // Quit if we dropped below threshold too many times
                if (throughputThresholdCurrentSequence > throughputThresholdSequence) {
                    LOG.warn("Dropped below threshold too many times in a row, killing!");

                    // Disable the threshold checker
                    throughputThresholdPages = -1;

                    // Empty the queues cleanly and get number of items that were dropped
                    int hitByThrougputThreshold = fetchManager.clearFetchItemQueues();

                    if (hitByThrougputThreshold != 0) {
                        context.getCounter("FetcherStatus", "hitByThrougputThreshold")
                                .increment(hitByThrougputThreshold);
                    }
                }
            } else {
                throughputThresholdCurrentSequence = 0;
            }
        }

        // some requests seem to hang, despite all intentions
        if ((System.currentTimeMillis() - fetchManager.getLastTaskStartTime()) > fetchJobTimeout) {
            if (fetchManager.activeFetcherThreads.get() > 0) {
                LOG.warn("Aborting with " + fetchManager.activeFetcherThreads.get() + " hung threads.");

                for (int i = 0; i < fetchThreads.size(); i++) {
                    FetchThread thread = fetchThreads.get(i);
                    if (thread.isAlive()) {
                        LOG.warn("Thread #" + i + " hung while processing " + thread.reprUrl());

                        if (LOG.isDebugEnabled()) {
                            StackTraceElement[] stack = thread.getStackTrace();
                            StringBuilder sb = new StringBuilder();
                            sb.append("Stack of thread #").append(i).append(":\n");
                            for (StackTraceElement s : stack) {
                                sb.append(s.toString()).append('\n');
                            }

                            LOG.debug(sb.toString());
                        }
                    }
                } // for
            } // if

            return;
        } // if
    } while (fetchManager.activeFetcherThreads.get() > 0);
}

From source file:org.esa.cci.sst.tools.BasicTool.java

public final ErrorHandler getErrorHandler() {
    if (errorHandler == null) {
        synchronized (this) {
            if (errorHandler == null) {
                errorHandler = new ErrorHandler() {
                    @Override//from   ww  w .  j  ava  2  s .c  o  m
                    public void terminate(ToolException e) {
                        final Logger localLogger = SstLogging.getLogger();
                        localLogger.log(Level.SEVERE, e.getMessage(), e);
                        if (e.getCause() != null) {
                            if (localLogger.isLoggable(Level.FINEST)) {
                                for (final StackTraceElement element : e.getCause().getStackTrace()) {
                                    localLogger.log(Level.FINEST, element.toString());
                                }
                            }
                            e.getCause().printStackTrace(System.err);
                        }
                        System.exit(e.getExitCode());
                    }

                    @Override
                    public void warn(Throwable t, String message) {
                        final Logger localLogger = SstLogging.getLogger();
                        localLogger.log(Level.WARNING, message, t);
                        if (localLogger.isLoggable(Level.FINEST)) {
                            for (final StackTraceElement element : t.getStackTrace()) {
                                localLogger.log(Level.FINEST, element.toString());
                            }
                        }
                    }
                };
            }
        }
    }
    return errorHandler;
}

From source file:export.notes.view.to.excel.ExportAction.java

private void error(final Throwable t) {
    UIJob uijob = new UIJob(Messages.ExportAction_5) {
        public IStatus runInUIThread(IProgressMonitor arg0) {
            // build the error message and include the current stack trace
            MultiStatus status = createMultiStatus(t.getMessage(), t);
            // show error dialog
            ErrorDialog.openError(PlatformUI.getWorkbench().getDisplay().getActiveShell(),
                    Messages.ExportAction_11, t.getLocalizedMessage(), status);

            return Status.OK_STATUS;
        }//from  ww  w .  jav  a  2 s .c om

        private MultiStatus createMultiStatus(String msg, Throwable t) {

            List<Status> childStatuses = new ArrayList<Status>();
            StackTraceElement[] stackTraces = Thread.currentThread().getStackTrace();

            for (StackTraceElement stackTrace : stackTraces) {
                Status status = new Status(IStatus.ERROR, Activator.PLUGIN_ID, stackTrace.toString());
                childStatuses.add(status);
            }

            MultiStatus ms = new MultiStatus(Activator.PLUGIN_ID, IStatus.ERROR,
                    childStatuses.toArray(new Status[] {}), t.toString(), t);
            return ms;
        }

    };
    uijob.schedule();
}

From source file:org.bonitasoft.engine.test.internal.EngineStarter.java

private void printThread(final Thread thread) {
    LOGGER.info("\n");
    LOGGER.info("Thread is still alive:" + thread.getName());
    for (StackTraceElement stackTraceElement : thread.getStackTrace()) {
        LOGGER.info("        at " + stackTraceElement.toString());
    }/* w w w  .j a  va  2 s. c  o m*/
}