I'm storing FacetHandlers in a local cache for reuse across requests. Also, I'm storing the BoboIndexReader in a cache that I temporarily refresh.
occur in the log when I'm looping over a list of facethandlers I retrieved from the cache. This doesn't happen often. I'm just wondering when this might occur and how to avoid this?
@Override
public void refreshBoboIndexReader(Class<?> clazz, boolean reopen) {
try {
if (reopen) {
setBoboIndexReader(clazz, getBoboReader(clazz));
}
} catch (IOException io) {
log.error("Error creating indexReader", io);
}
}
protected void setBoboIndexReader(Class<?> clazz, BoboIndexReader breader)
throws IOException {
MyDaoHibernate.writeLock.lock();
try {
if (boboReaders.containsKey(clazz))
boboReaders.get(clazz).close();
boboReaders.put(clazz, breader);
} finally {
MyDaoHibernate.writeLock.unlock();
}
}
protected BoboIndexReader getBoboReader(final Class<?> clazz)
throws IOException {
TransactionTemplate transTemplate = new TransactionTemplate(
transactionManager);
IndexReader i = transTemplate
.execute(new TransactionCallback<IndexReader>() {
@Override
public IndexReader doInTransaction(
TransactionStatus status) {
FullTextSession fts = Search
.getFullTextSession(getSessionFactory()
.getCurrentSession());
MutableSearchFactory factory = (MutableSearchFactory) fts.getSearchFactory();
DirectoryBasedIndexManager mgr = (DirectoryBasedIndexManager) factory.getAllIndexesManager().getIndexManager(clazz.getCanonicalName());
try{
return IndexReader.open(mgr.getDirectoryProvider().getDirectory(), true);
}catch(IOException io){
log.error("Error opening indexreader for Bobo", io);
}
return null;
}
});
return BoboIndexReader.getInstance(
i,
sfFactory.getUnfilteredList(), null);
}