Example usage for com.google.common.util.concurrent UncheckedTimeoutException getLocalizedMessage

List of usage examples for com.google.common.util.concurrent UncheckedTimeoutException getLocalizedMessage

Introduction

In this page you can find the example usage for com.google.common.util.concurrent UncheckedTimeoutException getLocalizedMessage.

Prototype

public String getLocalizedMessage() 

Source Link

Document

Creates a localized description of this throwable.

Usage

From source file:org.zenoss.zep.index.impl.lucene.LuceneEventIndexBackend.java

private TopDocs timeLimitedSearch(final IndexSearcher searcher, final Query query, final Sort sort,
        final int offset, final int limit, final int numDocs) throws ZepException {

    TopDocs docs;/*from  www .  j  ava 2s  . c  o  m*/

    Callable search_call = new Callable<TopDocs>() {
        public TopDocs call() throws IOException, Exception {
            TopDocs tdocs;
            if (sort != null) {
                logger.debug("Query: {}, Sort: {}, Offset: {}, Limit: {}",
                        new Object[] { query, sort, offset, limit });
                tdocs = searcher.search(query, null, numDocs, sort);
            } else {
                logger.debug("Query: {}, Offset: {}, Limit: {}", new Object[] { query, offset, limit });
                tdocs = searcher.search(query, null, numDocs);
            }
            return tdocs;
        }
    };

    try {
        if (this.luceneSearchTimeout > 0) {
            TimeLimiter limiter = new SimpleTimeLimiter();
            docs = (TopDocs) limiter.callWithTimeout(search_call, this.luceneSearchTimeout, TimeUnit.SECONDS,
                    true);
        } else
            docs = (TopDocs) search_call.call();
    } catch (UncheckedTimeoutException e) {
        String msg = "Lucene search exceeded time limit ( " + this.luceneSearchTimeout + " seconds.)";
        if (sort != null)
            logger.warn(msg + "Query: {}, Sort: {}, Offset: {}, Limit: {}",
                    new Object[] { query, sort, offset, limit });
        else
            logger.warn(msg + "Query: {}, Offset: {}, Limit: {}", new Object[] { query, offset, limit });
        throw new ZepException(msg + e.getLocalizedMessage(), e);
    } catch (OutOfMemoryError oome) {
        throw oome;
    } catch (Exception e) {
        logger.error("Exception performing timed search: ", e);
        throw new ZepException(e.getLocalizedMessage(), e);
    }

    return docs;
}