Example usage for org.apache.lucene.util InfoStream getDefault

List of usage examples for org.apache.lucene.util InfoStream getDefault

Introduction

In this page you can find the example usage for org.apache.lucene.util InfoStream getDefault.

Prototype

public static synchronized InfoStream getDefault() 

Source Link

Document

The default InfoStream used by a newly instantiated classes.

Usage

From source file:org.apache.jackrabbit.oak.plugins.index.lucene.LuceneIndexProviderServiceTest.java

License:Apache License

@Test
public void defaultSetup() throws Exception {
    MockOsgi.activate(service, context.bundleContext(), getDefaultConfig());

    assertNotNull(context.getService(QueryIndexProvider.class));
    assertNotNull(context.getService(Observer.class));
    assertNotNull(context.getService(IndexEditorProvider.class));

    LuceneIndexEditorProvider editorProvider = (LuceneIndexEditorProvider) context
            .getService(IndexEditorProvider.class);
    assertNotNull(editorProvider.getIndexCopier());

    IndexCopier indexCopier = service.getIndexCopier();
    assertNotNull("IndexCopier should be initialized as CopyOnRead is enabled by default", indexCopier);
    assertTrue(indexCopier.isPrefetchEnabled());

    assertNotNull("CopyOnRead should be enabled by default", context.getService(CopyOnReadStatsMBean.class));
    assertNotNull(context.getService(CacheStatsMBean.class));

    assertTrue(context.getService(Observer.class) instanceof BackgroundObserver);
    assertEquals(InfoStream.NO_OUTPUT, InfoStream.getDefault());

    assertEquals(1024, BooleanQuery.getMaxClauseCount());

    MockOsgi.deactivate(service);/*w  ww.  ja  va2  s .c o m*/
}

From source file:org.apache.jackrabbit.oak.plugins.index.lucene.LuceneIndexProviderServiceTest.java

License:Apache License

@Test
public void debugLogging() throws Exception {
    Map<String, Object> config = getDefaultConfig();
    config.put("debug", true);
    MockOsgi.activate(service, context.bundleContext(), config);

    assertEquals(LoggingInfoStream.INSTANCE, InfoStream.getDefault());
    MockOsgi.deactivate(service);//from w  w w  .j av a2  s  .c  o m
}

From source file:org.elasticsearch.index.engine.InternalEngine.java

License:Apache License

private IndexWriter createWriter(boolean create) throws IOException {
    try {/*from   w  ww . j a  v  a  2 s.co m*/
        final IndexWriterConfig iwc = new IndexWriterConfig(engineConfig.getAnalyzer());
        iwc.setCommitOnClose(false); // we by default don't commit on close
        iwc.setOpenMode(create ? IndexWriterConfig.OpenMode.CREATE : IndexWriterConfig.OpenMode.APPEND);
        iwc.setIndexDeletionPolicy(deletionPolicy);
        // with tests.verbose, lucene sets this up: plumb to align with filesystem stream
        boolean verbose = false;
        try {
            verbose = Boolean.parseBoolean(System.getProperty("tests.verbose"));
        } catch (Throwable ignore) {
        }
        iwc.setInfoStream(verbose ? InfoStream.getDefault() : new LoggerInfoStream(logger));
        iwc.setMergeScheduler(mergeScheduler);
        MergePolicy mergePolicy = config().getMergePolicy();
        // Give us the opportunity to upgrade old segments while performing
        // background merges
        mergePolicy = new ElasticsearchMergePolicy(mergePolicy);
        iwc.setMergePolicy(mergePolicy);
        iwc.setSimilarity(engineConfig.getSimilarity());
        iwc.setRAMBufferSizeMB(engineConfig.getIndexingBufferSize().mbFrac());
        iwc.setCodec(engineConfig.getCodec());
        /* We set this timeout to a highish value to work around
         * the default poll interval in the Lucene lock that is
         * 1000ms by default. We might need to poll multiple times
         * here but with 1s poll this is only executed twice at most
         * in combination with the default writelock timeout*/
        iwc.setWriteLockTimeout(5000);
        iwc.setUseCompoundFile(this.engineConfig.isCompoundOnFlush());
        // Warm-up hook for newly-merged segments. Warming up segments here is better since it will be performed at the end
        // of the merge operation and won't slow down _refresh
        iwc.setMergedSegmentWarmer(new IndexReaderWarmer() {
            @Override
            public void warm(LeafReader reader) throws IOException {
                try {
                    LeafReader esLeafReader = new ElasticsearchLeafReader(reader, shardId);
                    assert isMergedSegment(esLeafReader);
                    if (warmer != null) {
                        final Engine.Searcher searcher = new Searcher("warmer",
                                searcherFactory.newSearcher(esLeafReader, null));
                        final IndicesWarmer.WarmerContext context = new IndicesWarmer.WarmerContext(shardId,
                                searcher);
                        warmer.warmNewReaders(context);
                    }
                } catch (Throwable t) {
                    // Don't fail a merge if the warm-up failed
                    if (isClosed.get() == false) {
                        logger.warn("Warm-up failed", t);
                    }
                    if (t instanceof Error) {
                        // assertion/out-of-memory error, don't ignore those
                        throw (Error) t;
                    }
                }
            }
        });
        return new IndexWriter(store.directory(), iwc);
    } catch (LockObtainFailedException ex) {
        boolean isLocked = IndexWriter.isLocked(store.directory());
        logger.warn("Could not lock IndexWriter isLocked [{}]", ex, isLocked);
        throw ex;
    }
}