/* $Id: PerDPResources.java 17884 2009-10-30 13:58:05Z sannegrinovero $
*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2009, Red Hat, Inc. and/or its affiliates or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat, Inc.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
* Lesser General Public License, as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this distribution; if not, write to:
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
*/
package org.hibernate.search.backend.impl.lucene;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import org.hibernate.search.backend.Workspace;
import org.hibernate.search.backend.impl.lucene.works.LuceneWorkVisitor;
import org.hibernate.search.engine.SearchFactoryImplementor;
import org.hibernate.search.store.DirectoryProvider;
/**
* Collects all resources needed to apply changes to one index,
* and are reused across several WorkQueues.
*
* @author Sanne Grinovero
*/
class PerDPResources {
private final ExecutorService executor;
private final LuceneWorkVisitor visitor;
private final Workspace workspace;
private final boolean exclusiveIndexUsage;
PerDPResources(SearchFactoryImplementor searchFactoryImp, DirectoryProvider<?> dp) {
workspace = new Workspace( searchFactoryImp, dp );
visitor = new LuceneWorkVisitor( workspace );
executor = Executors.newFixedThreadPool( 1 );
exclusiveIndexUsage = searchFactoryImp.isExclusiveIndexUsageEnabled( dp );
}
public ExecutorService getExecutor() {
return executor;
}
public LuceneWorkVisitor getVisitor() {
return visitor;
}
public Workspace getWorkspace() {
return workspace;
}
public boolean isExclusiveIndexUsageEnabled() {
return exclusiveIndexUsage;
}
public void shutdown() {
//sets the index to be closed after all current jobs are processed:
if ( exclusiveIndexUsage ) {
executor.execute( new CloseIndexRunnable( workspace ) );
}
executor.shutdown();
}
}