Example usage for org.apache.solr.core SolrCore isClosed

List of usage examples for org.apache.solr.core SolrCore isClosed

Introduction

In this page you can find the example usage for org.apache.solr.core SolrCore isClosed.

Prototype

public boolean isClosed() 

Source Link

Document

Whether this core is closed.

Usage

From source file:com.lucid.solr.sidecar.SidecarIndexReaderFactory.java

License:Apache License

DirectoryReader newReaderInternal(Directory indexDir, IndexWriter writer, SolrCore core) throws IOException {
    DirectoryReader main = null;//  ww w .j a  v a  2 s  . c  o  m
    if (writer != null) {
        main = standardFactory.newReader(writer, core);
    } else {
        main = standardFactory.newReader(indexDir, core);
    }
    if (!enabled) {
        LOG.info("Sidecar index not enabled");
        return main;
    }
    currentCore = core;
    CoreContainer container = core.getCoreDescriptor().getCoreContainer();
    SolrCore source = container.getCore(sourceCollection);
    if (source == null) {
        LOG.info("Source collection '" + sourceCollection + "' not present, sidecar index is disabled.");
        try {
            return new SidecarIndexReader(this, main, null, SidecarIndexReader.getSequentialSubReaders(main),
                    sourceCollection, null);
        } catch (Exception e1) {
            LOG.warn("Unexpected exception, returning single main index", e1);
            return main;
        }
    }
    if (source.isClosed()) {
        LOG.info("Source collection '" + sourceCollection + "' is closed, sidecar index is disabled.");
        try {
            return new SidecarIndexReader(this, main, null, SidecarIndexReader.getSequentialSubReaders(main),
                    sourceCollection, null);
        } catch (Exception e1) {
            LOG.warn("Unexpected exception, returning single main index", e1);
            return main;
        }
    }
    DirectoryReader parallel = null;
    SolrIndexSearcher searcher = null;
    try {
        searcher = source.getNewestSearcher(true).get();
        parallel = buildParallelReader(main, searcher, true);
    } finally {
        if (searcher != null) {
            LOG.info("-- closing " + searcher);
            searcher.close();
        }
        source.close();
    }
    return parallel;
}

From source file:com.lucid.solr.sidecar.SidecarIndexReaderFactory.java

License:Apache License

DirectoryReader reopen(DirectoryReader newMain, boolean rebuild) throws IOException {
    CoreContainer container = currentCore.getCoreDescriptor().getCoreContainer();
    SolrCore source = container.getCore(sourceCollection);
    if (source == null) {
        LOG.info("Source collection '" + sourceCollection + "' not present, sidecar index is disabled.");
        try {/*from w w  w.  j a v  a 2s  .  c  om*/
            return new SidecarIndexReader(this, newMain, null,
                    SidecarIndexReader.getSequentialSubReaders(newMain), sourceCollection, null);
        } catch (Exception e1) {
            LOG.warn("Unexpected exception, returning single main index", e1);
            return newMain;
        }
    }
    if (source.isClosed()) {
        LOG.info("Source collection '" + sourceCollection + "' is closed, sidecar index is disabled.");
        try {
            return new SidecarIndexReader(this, newMain, null,
                    SidecarIndexReader.getSequentialSubReaders(newMain), sourceCollection, null);
        } catch (Exception e1) {
            LOG.warn("Unexpected exception, returning single main index", e1);
            return newMain;
        }
    }
    DirectoryReader parallel = null;
    SolrIndexSearcher searcher = null;
    try {
        searcher = source.getNewestSearcher(true).get();
        parallel = buildParallelReader(newMain, searcher, rebuild);
    } finally {
        if (searcher != null && searcher.getIndexReader().getRefCount() > 0) {
            LOG.info("-- closing " + searcher);
            searcher.close();
        }
        if (source != null) {
            source.close();
        }
    }
    return parallel;
}