List of usage examples for org.apache.solr.util VersionedFile getLatestFile
public static InputStream getLatestFile(String dirName, String fileName) throws FileNotFoundException
From source file:com.billiger.solr.handler.component.QLTBComponent.java
License:Apache License
/** * Get QLTB map for the given IndexReader. * * If the QLTB map is located in the conf/ directory, it is independent * of the IndexReader and reloaded only during a core reload. * If, however, QLTB data is read from ZooKeeper or the data/ directory, * it is reloaded for each new IndexReader via the core's resource loader. * * @return QLTB map for the given IndexReader. */// www .j ava2s .co m private Map<String, List<Query>> getQLTBMap(final IndexReader reader, final SolrCore core) throws Exception { Map<String, List<Query>> map = null; synchronized (qltbCache) { map = qltbCache.get(null); // Magic "null" key for data from conf/ if (map != null) { // QLTB data from the conf/ directory, reader-independent. return map; } map = qltbCache.get(reader); if (map == null) { // No QLTB map for this reader yet, load it from ZooKeeper or // the data/ directory. log.info("load QLTB map for new IndexReader"); String qltbFile = initArgs.get(QLTB_FILE); if (qltbFile == null) { throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "QLTBComponent must specify argument: " + QLTB_FILE); } Config cfg; ZkController zkController = core.getCoreDescriptor().getCoreContainer().getZkController(); if (zkController != null) { // We're running under ZooKeeper control... cfg = new Config(core.getResourceLoader(), qltbFile, null, null); } else { // No ZooKeeper, use data/ directory InputStream is = VersionedFile.getLatestFile(core.getDataDir(), qltbFile); cfg = new Config(core.getResourceLoader(), qltbFile, new InputSource(is), null); } map = loadQLTBMap(cfg, core); qltbCache.put(reader, map); } return map; } }