You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stanbol.apache.org by og...@apache.org on 2011/05/13 17:29:21 UTC
svn commit: r1102791 [3/9] - in
/incubator/stanbol/trunk/entityhub/yard/solr/src:
main/java/org/apache/stanbol/entityhub/yard/solr/
main/java/org/apache/stanbol/entityhub/yard/solr/defaults/
main/java/org/apache/stanbol/entityhub/yard/solr/impl/ main/j...
Modified: incubator/stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/impl/DefaultSolrDirectoryManager.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/impl/DefaultSolrDirectoryManager.java?rev=1102791&r1=1102790&r2=1102791&view=diff
==============================================================================
--- incubator/stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/impl/DefaultSolrDirectoryManager.java (original)
+++ incubator/stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/impl/DefaultSolrDirectoryManager.java Fri May 13 15:29:20 2011
@@ -44,312 +44,341 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
- * Implementation of the {@link SolrDirectoryManager} interface that supports
- * the dynamic initialisation of new cores based on the default core configuration
- * contained within the SolrYard bundle.
+ * Implementation of the {@link SolrDirectoryManager} interface that supports the dynamic initialisation of
+ * new cores based on the default core configuration contained within the SolrYard bundle.
*
* @author Rupert Westenthaler
- *
+ *
*/
-@Component(immediate=true,metatype=true)
+@Component(immediate = true, metatype = true)
@Service
-@Properties(value={
- @Property(name=SolrDirectoryManager.MANAGED_SOLR_DIR_PROPERTY,value=SolrDirectoryManager.DEFAULT_SOLR_DATA_DIR)
- })
+@Properties(value = {@Property(name = SolrDirectoryManager.MANAGED_SOLR_DIR_PROPERTY, value = SolrDirectoryManager.DEFAULT_SOLR_DATA_DIR)})
public class DefaultSolrDirectoryManager implements SolrDirectoryManager {
/**
* The logger
*/
private final Logger log = LoggerFactory.getLogger(DefaultSolrDirectoryManager.class);
-
+
/**
- * This key is used to store the file name of the archive supposed to provide
- * the data for the uninitialised index within the configuration the configuration
+ * This key is used to store the file name of the archive supposed to provide the data for the
+ * uninitialised index within the configuration the configuration
*/
private static final String UNINITIALISED_INDEX_ARCHIVE_NAME_KEY = "Uninitialised-Index-Archive-Name";
-
-
+
/**
* The dataFileProvider used to lookup index data
*/
@Reference
private DataFileProvider dataFileProvider;
/**
- * The directory used by the internally managed embedded solr server.
- * Use {@link #lookupManagedSolrDir()} instead of using this member, because
- * this member is not initialised within the constructor or the
+ * The directory used by the internally managed embedded solr server. Use {@link #lookupManagedSolrDir()}
+ * instead of using this member, because this member is not initialised within the constructor or the
* {@link #activate(ComponentContext)} method.
*/
private File solrDataDir;
-
+
/**
- * The component context. Only available when running within an OSGI
- * Environment and the component is active.
+ * The component context. Only available when running within an OSGI Environment and the component is
+ * active.
*/
private ComponentContext componentContext;
/**
- * For some functionality within this component it is important to track
- * if this instance operates within or outside of an OSGI environment.
- * because of this this boolean is set to true as soon as the first time
- * {@link #activate(ComponentContext)} or {@link #deactivate(ComponentContext)}
- * is called. If someone knows a better method to check that feel free to
- * change!
+ * For some functionality within this component it is important to track if this instance operates within
+ * or outside of an OSGI environment. because of this this boolean is set to true as soon as the first
+ * time {@link #activate(ComponentContext)} or {@link #deactivate(ComponentContext)} is called. If someone
+ * knows a better method to check that feel free to change!
*/
private boolean withinOSGI = false;
/**
- * Initialising Solr Indexes with a lot of data may take some time. Especially
- * if the data need to be copied to the managed directory. Therefore it is
- * important to wait for the initialisation to be complete before opening
- * an Solr Index on it.<p>
- * To this set all cores that are currently initialised are added. As soon
- * as an initialisation completed this set is notified.
+ * Initialising Solr Indexes with a lot of data may take some time. Especially if the data need to be
+ * copied to the managed directory. Therefore it is important to wait for the initialisation to be
+ * complete before opening an Solr Index on it.
+ * <p>
+ * To this set all cores that are currently initialised are added. As soon as an initialisation completed
+ * this set is notified.
*/
private Set<String> initCores = new HashSet<String>();
/**
- * Holds the list of cores that where installed by using
- * {@link #createSolrDirectory(String, String, java.util.Properties)} but the
- * {@link DataFileProvider} could not yet provide the necessary data for the
- * initialisation.<p>
- * The list of uninitialised cores is stored within the data folder of the
- * bundle under {@link #UNINITIALISED_SITE_DIRECTORY_NAME} and loaded at
- * activation.
+ * Holds the list of cores that where installed by using
+ * {@link #createSolrDirectory(String, String, java.util.Properties)} but the {@link DataFileProvider}
+ * could not yet provide the necessary data for the initialisation.
+ * <p>
+ * The list of uninitialised cores is stored within the data folder of the bundle under
+ * {@link #UNINITIALISED_SITE_DIRECTORY_NAME} and loaded at activation.
*
*/
private Map<String,java.util.Properties> uninitialisedCores = new HashMap<String,java.util.Properties>();
-
- public DefaultSolrDirectoryManager() {
- }
-
- /* (non-Javadoc)
+
+ public DefaultSolrDirectoryManager() {}
+
+ /*
+ * (non-Javadoc)
+ *
* @see org.apache.stanbol.entityhub.yard.solr.impl.ManagedSolrDirectory#isSolrDir(java.lang.String)
*/
public final boolean isManagedIndex(String solrIndexName) throws IllegalStateException {
- if(solrIndexName == null){
+ if (solrIndexName == null) {
throw new IllegalArgumentException("The parsed name of the Solr index MUST NOT be NULL");
}
- if(solrIndexName.isEmpty()){
+ if (solrIndexName.isEmpty()) {
throw new IllegalArgumentException("The parsed name of the Solr index MUST NOT be empty");
}
- //first check if the directory for the parsed index exists
- boolean exists = new File(lookupManagedSolrDir(componentContext),solrIndexName).exists();
- return !exists ? //if no directory exists
- //check also if an uninitialised index was requested
- uninitialisedCores.containsKey(solrIndexName):
- true;
+ // first check if the directory for the parsed index exists
+ boolean exists = new File(lookupManagedSolrDir(componentContext), solrIndexName).exists();
+ return !exists ? // if no directory exists
+ // check also if an uninitialised index was requested
+ uninitialisedCores.containsKey(solrIndexName)
+ : true;
}
- /* (non-Javadoc)
+
+ /*
+ * (non-Javadoc)
+ *
* @see org.apache.stanbol.entityhub.yard.solr.impl.ManagedSolrDirectory#getManagedIndices()
*/
public final Map<String,File> getManagedIndices() throws IllegalStateException {
File solrDir = lookupManagedSolrDir(componentContext);
String[] indexNames = solrDir.list(DirectoryFileFilter.INSTANCE);
Map<String,File> indexes = new HashMap<String,File>();
- for(String indexName:indexNames){
- //TODO: validate that this is actually a SolrCore!
- indexes.put(indexName, new File(solrDir,indexName));
- }
- //we need also add the uninitialised indexes (with a null as value)
- for(String indexName: uninitialisedCores.keySet()){
- if(!indexes.containsKey(indexName)){
+ for (String indexName : indexNames) {
+ // TODO: validate that this is actually a SolrCore!
+ indexes.put(indexName, new File(solrDir, indexName));
+ }
+ // we need also add the uninitialised indexes (with a null as value)
+ for (String indexName : uninitialisedCores.keySet()) {
+ if (!indexes.containsKey(indexName)) {
indexes.put(indexName, null);
}
}
return indexes;
}
- public boolean isInitialisedIndex(String solrIndexName){
- if(solrIndexName == null){
+
+ public boolean isInitialisedIndex(String solrIndexName) {
+ if (solrIndexName == null) {
throw new IllegalArgumentException("The parsed name of the Solr index MUST NOT be NULL");
}
- if(solrIndexName.isEmpty()){
+ if (solrIndexName.isEmpty()) {
throw new IllegalArgumentException("The parsed name of the Solr index MUST NOT be empty");
}
- if(initCores.contains(solrIndexName)){ //if it is currently initialised
- return false; //return false
- } else { //check if the dir is there
- return new File(lookupManagedSolrDir(componentContext),solrIndexName).exists();
+ if (initCores.contains(solrIndexName)) { // if it is currently initialised
+ return false; // return false
+ } else { // check if the dir is there
+ return new File(lookupManagedSolrDir(componentContext), solrIndexName).exists();
}
}
- /* (non-Javadoc)
- * @see org.apache.stanbol.entityhub.yard.solr.impl.ManagedSolrDirectory#getSolrDirectory(java.lang.String)
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.apache.stanbol.entityhub.yard.solr.impl.ManagedSolrDirectory#getSolrDirectory(java.lang.String)
*/
- public final File getSolrIndexDirectory(final String solrIndexName,boolean allowDefaultInit) throws IllegalArgumentException {
- return initSolrDirectory(solrIndexName,null,allowDefaultInit,componentContext);
+ public final File getSolrIndexDirectory(final String solrIndexName, boolean allowDefaultInit) throws IllegalArgumentException {
+ return initSolrDirectory(solrIndexName, null, allowDefaultInit, componentContext);
}
- public final File createSolrIndex(final String solrIndexName, ArchiveInputStream ais){
- return initSolrDirectory(solrIndexName,ais,false,componentContext);
+
+ public final File createSolrIndex(final String solrIndexName, ArchiveInputStream ais) {
+ return initSolrDirectory(solrIndexName, ais, false, componentContext);
}
+
@Override
- public final File createSolrDirectory(String solrIndexName, String indexArchiveRef, java.util.Properties properties) throws IllegalArgumentException,IOException {
- if(componentContext == null){
- throw new IllegalStateException("Creating an Index by using the DataFileProvider does only work when running within an OSGI");
+ public final File createSolrDirectory(String solrIndexName,
+ String indexArchiveRef,
+ java.util.Properties properties) throws IllegalArgumentException,
+ IOException {
+ if (componentContext == null) {
+ throw new IllegalStateException(
+ "Creating an Index by using the DataFileProvider does only work when running within an OSGI");
}
- //now add the index to the list of uninitialised
- addUninitialisedIndex(solrIndexName,indexArchiveRef, properties);
+ // now add the index to the list of uninitialised
+ addUninitialisedIndex(solrIndexName, indexArchiveRef, properties);
return initSolrDirectory(solrIndexName, null, false, componentContext);
}
/**
- * Tries to get the {@link ArchiveInputStream} for the index from the
- * {@link DataFileProvider}.
- * @param context the context used to perform the operations
- * @param solrIndexName the name of the index to initialise
- * @param properties the properties for this index. Must contain the
- * {@link #UNINITIALISED_INDEX_ARCHIVE_NAME_KEY}.
- * @return The {@link ArchiveInputStream} or <code>null</code> if the
- * data are still not available
- * @throws IOException on any IO related error while initialising the index
- * @throws IllegalStateException if the parsed configuration does not provide
- * a value for {@link #UNINITIALISED_INDEX_ARCHIVE_NAME_KEY}.
- */
- private ArchiveInputStream lookupIndexArchive(ComponentContext context, String solrIndexName,java.util.Properties properties) throws IOException, IllegalStateException {
- //we need to copy the properties to a map
+ * Tries to get the {@link ArchiveInputStream} for the index from the {@link DataFileProvider}.
+ *
+ * @param context
+ * the context used to perform the operations
+ * @param solrIndexName
+ * the name of the index to initialise
+ * @param properties
+ * the properties for this index. Must contain the
+ * {@link #UNINITIALISED_INDEX_ARCHIVE_NAME_KEY}.
+ * @return The {@link ArchiveInputStream} or <code>null</code> if the data are still not available
+ * @throws IOException
+ * on any IO related error while initialising the index
+ * @throws IllegalStateException
+ * if the parsed configuration does not provide a value for
+ * {@link #UNINITIALISED_INDEX_ARCHIVE_NAME_KEY}.
+ */
+ private ArchiveInputStream lookupIndexArchive(ComponentContext context,
+ String solrIndexName,
+ java.util.Properties properties) throws IOException,
+ IllegalStateException {
+ // we need to copy the properties to a map
Map<String,String> propMap;
- if(properties == null){
- properties = new java.util.Properties(); //create an empty properties file
+ if (properties == null) {
+ properties = new java.util.Properties(); // create an empty properties file
propMap = null;
} else {
propMap = new HashMap<String,String>();
- for(Entry<Object,Object> entry : properties.entrySet()){
- propMap.put(entry.getKey().toString(), entry.getValue()!=null?entry.getValue().toString():null);
+ for (Entry<Object,Object> entry : properties.entrySet()) {
+ propMap.put(entry.getKey().toString(), entry.getValue() != null ? entry.getValue().toString()
+ : null);
}
}
String archiveName = properties.getProperty(UNINITIALISED_INDEX_ARCHIVE_NAME_KEY);
- if(archiveName == null){
- throw new IllegalStateException("Found uninitialised index config that does not contain the required "+
- UNINITIALISED_INDEX_ARCHIVE_NAME_KEY+" property!");
- }
- propMap.remove(UNINITIALISED_INDEX_ARCHIVE_NAME_KEY);//do not parse this internal property
- InputStream is = dataFileProvider.getInputStream(context.getBundleContext().getBundle().getSymbolicName(), archiveName, propMap);
- return is == null?null:ConfigUtils.getArchiveInputStream(archiveName, is);
+ if (archiveName == null) {
+ throw new IllegalStateException(
+ "Found uninitialised index config that does not contain the required "
+ + UNINITIALISED_INDEX_ARCHIVE_NAME_KEY + " property!");
+ }
+ propMap.remove(UNINITIALISED_INDEX_ARCHIVE_NAME_KEY);// do not parse this internal property
+ InputStream is = dataFileProvider.getInputStream(context.getBundleContext().getBundle()
+ .getSymbolicName(), archiveName, propMap);
+ return is == null ? null : ConfigUtils.getArchiveInputStream(archiveName, is);
}
- private void addUninitialisedIndex(String indexName,String sourceFileName,java.util.Properties config) throws IOException {
+
+ private void addUninitialisedIndex(String indexName, String sourceFileName, java.util.Properties config) throws IOException {
ComponentContext context = componentContext;
- if(context == null){
- throw new IllegalStateException("This feature is only available when running within an OSGI environment");
+ if (context == null) {
+ throw new IllegalStateException(
+ "This feature is only available when running within an OSGI environment");
}
- if(config == null){
+ if (config == null) {
config = new java.util.Properties();
}
config.setProperty(UNINITIALISED_INDEX_ARCHIVE_NAME_KEY, sourceFileName);
synchronized (uninitialisedCores) {
- if(uninitialisedCores.put(indexName, config) != null){
- removeUninitialisedIndexConfig(context,indexName); //remove the old version
+ if (uninitialisedCores.put(indexName, config) != null) {
+ removeUninitialisedIndexConfig(context, indexName); // remove the old version
}
- saveUninitialisedIndexConfig(context,indexName, config); //save the new version
+ saveUninitialisedIndexConfig(context, indexName, config); // save the new version
}
}
- private void removeUninitialisedIndex(String indexName){
+
+ private void removeUninitialisedIndex(String indexName) {
ComponentContext context = componentContext;
synchronized (uninitialisedCores) {
- if(uninitialisedCores.remove(indexName) != null){
- if(context == null){
- //check only for the context if we need actually to remove
- //an entry, because this method is also called outside an
- //OSGI environment (but will never remove something from
- //uninitialisedCores)
- throw new IllegalStateException("This feature is only available when running within an OSGI environment");
+ if (uninitialisedCores.remove(indexName) != null) {
+ if (context == null) {
+ // check only for the context if we need actually to remove
+ // an entry, because this method is also called outside an
+ // OSGI environment (but will never remove something from
+ // uninitialisedCores)
+ throw new IllegalStateException(
+ "This feature is only available when running within an OSGI environment");
}
- removeUninitialisedIndexConfig(context,indexName); //remove the old version
+ removeUninitialisedIndexConfig(context, indexName); // remove the old version
}
}
}
+
/**
- * Internally used to get/init the Solr directory of a SolrCore or the root
- * Solr directory (if <code>null</code> is parsed)
- * @param solrIndexName the name of the Core or <code>null</code> to get/init
- * the root solr directory
- * @param ais The Input stream of the Archive to load the index from or
- * <code>null</code> to load the default core configuration.
- * @param allowDefaultInitialisation If <code>true</code> a new core is
- * initialised with the default configuration (empty index with the default
- * Solr schema and configuration). If <code>false</code> the core is only
- * created if a valid configuration is parsed.
- * @param context A reference to the component context or <code>null</code> if
- * running outside an OSGI container. This is needed to avoid that
- * {@link #deactivate(ComponentContext)} sets the context to <code>null</code>
- * during this method does its initialisation work.
- * @return the Solr directory or <code>null</code> if the requested index
- * could not be created (e.g. because of <code>false</code> was parsed as
- * create) or in case this component is deactivated
- * @throws IllegalStateException in case this method is called when this
- * component is running within an OSGI environment and it is deactivated or
- * the initialisation for the parsed index failed.
- * @throws IllegalArgumentException if the parsed solrIndexName is <code>null</code> or
- * empty.
- */
- private final File initSolrDirectory(final String solrIndexName,ArchiveInputStream ais,boolean allowDefaultInitialisation,ComponentContext context) throws IllegalStateException {
- if(solrIndexName == null){
+ * Internally used to get/init the Solr directory of a SolrCore or the root Solr directory (if
+ * <code>null</code> is parsed)
+ *
+ * @param solrIndexName
+ * the name of the Core or <code>null</code> to get/init the root solr directory
+ * @param ais
+ * The Input stream of the Archive to load the index from or <code>null</code> to load the
+ * default core configuration.
+ * @param allowDefaultInitialisation
+ * If <code>true</code> a new core is initialised with the default configuration (empty index
+ * with the default Solr schema and configuration). If <code>false</code> the core is only
+ * created if a valid configuration is parsed.
+ * @param context
+ * A reference to the component context or <code>null</code> if running outside an OSGI
+ * container. This is needed to avoid that {@link #deactivate(ComponentContext)} sets the
+ * context to <code>null</code> during this method does its initialisation work.
+ * @return the Solr directory or <code>null</code> if the requested index could not be created (e.g.
+ * because of <code>false</code> was parsed as create) or in case this component is deactivated
+ * @throws IllegalStateException
+ * in case this method is called when this component is running within an OSGI environment and
+ * it is deactivated or the initialisation for the parsed index failed.
+ * @throws IllegalArgumentException
+ * if the parsed solrIndexName is <code>null</code> or empty.
+ */
+ private final File initSolrDirectory(final String solrIndexName,
+ ArchiveInputStream ais,
+ boolean allowDefaultInitialisation,
+ ComponentContext context) throws IllegalStateException {
+ if (solrIndexName == null) {
throw new IllegalArgumentException("The parsed name of the Solr index MUST NOT be NULL");
}
- if(solrIndexName.isEmpty()){
+ if (solrIndexName.isEmpty()) {
throw new IllegalArgumentException("The parsed name of the Solr index MUST NOT be empty");
}
File managedCoreContainerDirectory = lookupManagedSolrDir(context);
- File coreDir = new File(managedCoreContainerDirectory,solrIndexName);
- if(!coreDir.exists()){
- //first add the index to the list of currently init cores
+ File coreDir = new File(managedCoreContainerDirectory, solrIndexName);
+ if (!coreDir.exists()) {
+ // first add the index to the list of currently init cores
synchronized (initCores) {
- log.debug(" > start initializing SolrIndex {}"+solrIndexName);
+ log.debug(" > start initializing SolrIndex {}" + solrIndexName);
initCores.add(solrIndexName);
}
- //second check if the Index is an uninitialised one and if this is the case
- //try to get the ArchiveInputStream form the DataFileProvider
+ // second check if the Index is an uninitialised one and if this is the case
+ // try to get the ArchiveInputStream form the DataFileProvider
java.util.Properties uninitialisedProperties;
synchronized (uninitialisedCores) {
uninitialisedProperties = uninitialisedCores.get(solrIndexName);
- if(uninitialisedProperties != null){
- //NOTE: this may override an parsed ArchiveInputStream
+ if (uninitialisedProperties != null) {
+ // NOTE: this may override an parsed ArchiveInputStream
// -> this is an error by the implementation of this class
- // so throw an Exception to detect such errors early!
- if(ais != null){
- throw new IllegalStateException("The parsed ArchiveInputStream is not null for an uninitialised Index. " +
- "Please report this error the the stanbol-def mailing list!");
+ // so throw an Exception to detect such errors early!
+ if (ais != null) {
+ throw new IllegalStateException(
+ "The parsed ArchiveInputStream is not null for an uninitialised Index. "
+ + "Please report this error the the stanbol-def mailing list!");
}
try {
ais = lookupIndexArchive(context, solrIndexName, uninitialisedProperties);
} catch (Exception e) {
- log.warn("The Index Archive for index {} not available (see \"Stanbol Data File Provider\" Tab of the Apache Webconsole for details).", solrIndexName);
+ log.warn(
+ "The Index Archive for index {} not available (see \"Stanbol Data File Provider\" Tab of the Apache Webconsole for details).",
+ solrIndexName);
}
}
}
- //third do the actual initialisation work
+ // third do the actual initialisation work
try {
- if(ais != null){
+ if (ais != null) {
ConfigUtils.copyCore(ais, coreDir, solrIndexName, false);
- //try to remove from uninitialised
- removeUninitialisedIndex(solrIndexName);
- } else if(allowDefaultInitialisation){
- //TODO: Refactor so that the lookup via Bundle and/or jar
- // file works via an internal implementation of an
- // FileDataProvider
- if(context != null){ //load via bundle
- ConfigUtils.copyCore(context.getBundleContext().getBundle(),
- coreDir, null, false);
- } else { //load from jar
- ConfigUtils.copyCore((Class<?>)null, coreDir, null, false);
+ // try to remove from uninitialised
+ removeUninitialisedIndex(solrIndexName);
+ } else if (allowDefaultInitialisation) {
+ // TODO: Refactor so that the lookup via Bundle and/or jar
+ // file works via an internal implementation of an
+ // FileDataProvider
+ if (context != null) { // load via bundle
+ ConfigUtils.copyCore(context.getBundleContext().getBundle(), coreDir, null, false);
+ } else { // load from jar
+ ConfigUtils.copyCore((Class<?>) null, coreDir, null, false);
}
}
} catch (Exception e) {
- throw new IllegalStateException(
- String.format("Unable to copy default configuration for Solr Index %s to the configured path %s"
- ,solrIndexName==null?"":solrIndexName,managedCoreContainerDirectory.getAbsoluteFile()),e);
+ throw new IllegalStateException(String.format(
+ "Unable to copy default configuration for Solr Index %s to the configured path %s",
+ solrIndexName == null ? "" : solrIndexName,
+ managedCoreContainerDirectory.getAbsoluteFile()), e);
} finally {
- //regardless what happened remove the index from the currently init
- //indexes and notify all other waiting for the initialisation
+ // regardless what happened remove the index from the currently init
+ // indexes and notify all other waiting for the initialisation
synchronized (initCores) {
- //initialisation done
+ // initialisation done
initCores.remove(solrIndexName);
- log.debug(" ... notify after trying to init SolrIndex {}"+solrIndexName);
- //notify that the initialisation completed or failed
- initCores.notifyAll();
+ log.debug(" ... notify after trying to init SolrIndex {}" + solrIndexName);
+ // notify that the initialisation completed or failed
+ initCores.notifyAll();
}
}
- } else { //the dir exists
- //check if still initialising ... and wait until the initialisation
- //is complete
+ } else { // the dir exists
+ // check if still initialising ... and wait until the initialisation
+ // is complete
synchronized (initCores) {
- while(initCores.contains(solrIndexName)){
- log.info(" > wait for initialisation of SolrIndex "+solrIndexName);
+ while (initCores.contains(solrIndexName)) {
+ log.info(" > wait for initialisation of SolrIndex " + solrIndexName);
try {
initCores.wait();
} catch (InterruptedException e) {
@@ -361,67 +390,72 @@ public class DefaultSolrDirectoryManager
return coreDir;
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see org.apache.stanbol.entityhub.yard.solr.impl.ManagedSolrDirectory#getManagedSolrDir()
*/
public File getManagedDirectory() {
return lookupManagedSolrDir(componentContext);
}
+
/**
- * Lookup the location of the managed Solr directory. Also initialised the
- * default configuration if the directory does not yet exist.
- * @param context A reference to the component context or <code>null</code> if
- * running outside an OSGI container. This is needed to avoid that
- * {@link #deactivate(ComponentContext)} sets the context to <code>null</code>
- * during this method does its initialisation work.
+ * Lookup the location of the managed Solr directory. Also initialised the default configuration if the
+ * directory does not yet exist.
+ *
+ * @param context
+ * A reference to the component context or <code>null</code> if running outside an OSGI
+ * container. This is needed to avoid that {@link #deactivate(ComponentContext)} sets the
+ * context to <code>null</code> during this method does its initialisation work.
* @return the directory based on the current configuration
- * @throws IllegalStateException in case this method is called when this
- * component is running within an OSGI environment and it is deactivated.
+ * @throws IllegalStateException
+ * in case this method is called when this component is running within an OSGI environment and
+ * it is deactivated.
*/
private File lookupManagedSolrDir(ComponentContext context) throws IllegalStateException {
- if(solrDataDir == null){
+ if (solrDataDir == null) {
String configuredDataDir;
- if(context == null){ //load via system properties
- configuredDataDir = System.getProperty(MANAGED_SOLR_DIR_PROPERTY,DEFAULT_SOLR_DATA_DIR);
- } else { //load via OSGI config
+ if (context == null) { // load via system properties
+ configuredDataDir = System.getProperty(MANAGED_SOLR_DIR_PROPERTY, DEFAULT_SOLR_DATA_DIR);
+ } else { // load via OSGI config
Object value = context.getProperties().get(MANAGED_SOLR_DIR_PROPERTY);
- if(value != null){
+ if (value != null) {
configuredDataDir = value.toString();
} else {
configuredDataDir = DEFAULT_SOLR_DATA_DIR;
}
}
- //property substitution
+ // property substitution
configuredDataDir = substituteProperty(configuredDataDir,
- context != null?context.getBundleContext():null);
- //determine the directory holding the SolrIndex
+ context != null ? context.getBundleContext() : null);
+ // determine the directory holding the SolrIndex
/*
- * NOTE:
- * In case the configuredDataDir.isAbsolute()==false this code will
- * initialise the index relative to the "user.dir" of the application.
+ * NOTE: In case the configuredDataDir.isAbsolute()==false this code will initialise the index
+ * relative to the "user.dir" of the application.
*/
- if(withinOSGI && context == null){
- //ensure to do not set an solrDataDir if this component is
- //running within an OSGI environment and is deactivated
- throw new IllegalStateException("Unable to lookup managed Solr directories when component is deactivated!");
- } else { //set the the absolute path
+ if (withinOSGI && context == null) {
+ // ensure to do not set an solrDataDir if this component is
+ // running within an OSGI environment and is deactivated
+ throw new IllegalStateException(
+ "Unable to lookup managed Solr directories when component is deactivated!");
+ } else { // set the the absolute path
solrDataDir = new File(configuredDataDir);
}
- //check if the "solr.xml" file exists in the directory
- File solrConf = new File(solrDataDir,"solr.xml");
- if(!solrConf.exists()){
+ // check if the "solr.xml" file exists in the directory
+ File solrConf = new File(solrDataDir, "solr.xml");
+ if (!solrConf.exists()) {
try {
- if(context != null){ //load via bundle
- solrDataDir = ConfigUtils.copyDefaultConfig(
- context.getBundleContext().getBundle(),solrDataDir, false);
- } else { //load from jar
- solrDataDir = ConfigUtils.copyDefaultConfig(
- (Class<?>)null, solrDataDir, false);
+ if (context != null) { // load via bundle
+ solrDataDir = ConfigUtils.copyDefaultConfig(context.getBundleContext().getBundle(),
+ solrDataDir, false);
+ } else { // load from jar
+ solrDataDir = ConfigUtils.copyDefaultConfig((Class<?>) null, solrDataDir, false);
}
} catch (IOException e) {
throw new IllegalStateException(
- String.format("Unable to copy default configuration for the manages Solr Directory to the configured path %s!"
- , solrDataDir.getAbsoluteFile()),e);
+ String.format(
+ "Unable to copy default configuration for the manages Solr Directory to the configured path %s!",
+ solrDataDir.getAbsoluteFile()), e);
}
}
}
@@ -429,37 +463,39 @@ public class DefaultSolrDirectoryManager
}
/**
- * Substitutes ${property.name} with the values retrieved via
- * {@link System#getProperty(String, String)}. An empty string is used as
- * default<p>
- * Nested substitutions are NOTE supported. However multiple substitutions
- * are supported. <p>
+ * Substitutes ${property.name} with the values retrieved via {@link System#getProperty(String, String)}.
+ * An empty string is used as default
+ * <p>
+ * Nested substitutions are NOTE supported. However multiple substitutions are supported.
+ * <p>
* If someone knows a default implementation feel free to replace!
- * @param value the value to substitute
- * @param bundleContext If not <code>null</code> the
- * {@link BundleContext#getProperty(String)} is used instead of the
- * {@link System#getProperty(String)}. By that it is possible to use
- * OSGI only properties for substitution.
+ *
+ * @param value
+ * the value to substitute
+ * @param bundleContext
+ * If not <code>null</code> the {@link BundleContext#getProperty(String)} is used instead of
+ * the {@link System#getProperty(String)}. By that it is possible to use OSGI only properties
+ * for substitution.
* @return the substituted value
*/
- private static String substituteProperty(String value,BundleContext bundleContext) {
+ private static String substituteProperty(String value, BundleContext bundleContext) {
int prevAt = 0;
int foundAt = 0;
StringBuilder substitution = new StringBuilder();
- while((foundAt = value.indexOf("${",prevAt))>=prevAt){
+ while ((foundAt = value.indexOf("${", prevAt)) >= prevAt) {
substitution.append(value.substring(prevAt, foundAt));
- String propertyName = value.substring(
- foundAt+2,value.indexOf('}',foundAt));
- String propertyValue = bundleContext == null? //if no bundleContext is available
- System.getProperty(propertyName): //use the System properties
- bundleContext.getProperty(propertyName);
- substitution.append(propertyValue==null?"":propertyValue);
- prevAt = foundAt+propertyName.length()+3; //+3 -> "${}".length
+ String propertyName = value.substring(foundAt + 2, value.indexOf('}', foundAt));
+ String propertyValue = bundleContext == null ? // if no bundleContext is available
+ System.getProperty(propertyName)
+ : // use the System properties
+ bundleContext.getProperty(propertyName);
+ substitution.append(propertyValue == null ? "" : propertyValue);
+ prevAt = foundAt + propertyName.length() + 3; // +3 -> "${}".length
}
substitution.append(value.substring(prevAt, value.length()));
return substitution.toString();
}
-
+
@Activate
protected void activate(ComponentContext context) throws IOException {
componentContext = context;
@@ -468,12 +504,13 @@ public class DefaultSolrDirectoryManager
uninitialisedCores.putAll(loadUninitialisedIndexConfigs(componentContext));
}
}
+
@Deactivate
protected void deactivate(ComponentContext context) {
synchronized (uninitialisedCores) {
uninitialisedCores.clear();
}
componentContext = null;
-
+
}
}
Modified: incubator/stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/impl/DefaultSolrServerProvider.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/impl/DefaultSolrServerProvider.java?rev=1102791&r1=1102790&r2=1102791&view=diff
==============================================================================
--- incubator/stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/impl/DefaultSolrServerProvider.java (original)
+++ incubator/stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/impl/DefaultSolrServerProvider.java Fri May 13 15:29:20 2011
@@ -33,42 +33,47 @@ import org.apache.solr.client.solrj.impl
import org.apache.stanbol.entityhub.yard.solr.SolrServerProvider;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+
/**
- * Implementation of the {@link SolrServerProvider} interface supporting all
- * the types directly supported by the SolrJ library. This includes all Clients
- * using an remote SolrServer.<p>
+ * Implementation of the {@link SolrServerProvider} interface supporting all the types directly supported by
+ * the SolrJ library. This includes all Clients using an remote SolrServer.
+ * <p>
* This does not support an embedded SolrServer
+ *
* @author Rupert Westenthaler
- *
+ *
*/
-@Component(immediate=true)
+@Component(immediate = true)
@Service
public class DefaultSolrServerProvider implements SolrServerProvider {
-
+
private final Logger log = LoggerFactory.getLogger(DefaultSolrServerProvider.class);
-
+
@Override
- public SolrServer getSolrServer(Type type, String uriOrPath, String... additional) throws NullPointerException, IllegalArgumentException {
- if(uriOrPath == null){
+ public SolrServer getSolrServer(Type type, String uriOrPath, String... additional) throws NullPointerException,
+ IllegalArgumentException {
+ if (uriOrPath == null) {
throw new IllegalArgumentException("The parsed SolrServer URI MUST NOT be NULL!");
}
- if(type == null){
+ if (type == null) {
type = Type.HTTP;
- } else if(type == Type.EMBEDDED){
+ } else if (type == Type.EMBEDDED) {
throw new IllegalArgumentException(
- String.format("The EmbeddedSolrServer (type=%s) is not supported by this SolrServerProvider implementation",
- type));
+ String.format(
+ "The EmbeddedSolrServer (type=%s) is not supported by this SolrServerProvider implementation",
+ type));
}
final URL solrServerURL;
try {
solrServerURL = new URL(uriOrPath);
} catch (MalformedURLException e) {
- throw new IllegalArgumentException("The parsed SolrServer location is not a valid URL",e);
+ throw new IllegalArgumentException("The parsed SolrServer location is not a valid URL", e);
}
- if(type != Type.LOAD_BALANCE && additional != null && additional.length>0){
- log.warn(String.format("The parsed SolrServer type \"%s\" does not support multiple SolrServer instaces." +
- "The %s additional SolrServer locations parsed are ignored! (ignored Servers: %s)",
- type,additional.length,Arrays.toString(additional)));
+ if (type != Type.LOAD_BALANCE && additional != null && additional.length > 0) {
+ log.warn(String.format(
+ "The parsed SolrServer type \"%s\" does not support multiple SolrServer instaces."
+ + "The %s additional SolrServer locations parsed are ignored! (ignored Servers: %s)",
+ type, additional.length, Arrays.toString(additional)));
}
switch (type) {
case HTTP:
@@ -77,43 +82,46 @@ public class DefaultSolrServerProvider i
try {
return new StreamingUpdateSolrServer(uriOrPath, 10, 3);
} catch (MalformedURLException e) {
- //URL is already validated before!
- throw new IllegalArgumentException(e.getMessage(),e);
+ // URL is already validated before!
+ throw new IllegalArgumentException(e.getMessage(), e);
}
case LOAD_BALANCE:
Collection<String> solrServers = new ArrayList<String>();
- solrServers.add(uriOrPath); //the main server
- //check the additional server locations
- if(additional != null){
- for(String serverlocation : additional){
- if(serverlocation != null){
+ solrServers.add(uriOrPath); // the main server
+ // check the additional server locations
+ if (additional != null) {
+ for (String serverlocation : additional) {
+ if (serverlocation != null) {
try {
new URL(serverlocation);
solrServers.add(serverlocation);
} catch (MalformedURLException e) {
- log.warn(String.format("The parsed additional SolrServer %s is no valid URL. -> This location is ignored",
- serverlocation),e);
+ log.warn(
+ String.format(
+ "The parsed additional SolrServer %s is no valid URL. -> This location is ignored",
+ serverlocation), e);
}
- } //else ignore
+ } // else ignore
}
}
try {
return new LBHttpSolrServer(solrServers.toArray(new String[solrServers.size()]));
} catch (MalformedURLException e) {
// URLs are already validated before!
- throw new IllegalArgumentException(e.getMessage(),e);
+ throw new IllegalArgumentException(e.getMessage(), e);
}
default:
- //write an error to clearly show that there is something wrong with this implementation
- log.error("This should never happen, because this class should eighter throw an IllegalArgumentException or support the type "+type);
- throw new IllegalArgumentException("The parsed Type "+type+" is not supported");
-
+ // write an error to clearly show that there is something wrong with this implementation
+ log.error("This should never happen, because this class should eighter throw an IllegalArgumentException or support the type "
+ + type);
+ throw new IllegalArgumentException("The parsed Type " + type + " is not supported");
+
}
}
-
+
@Override
public Set<Type> supportedTypes() {
- return EnumSet.of(Type.HTTP, Type.LOAD_BALANCE,Type.STREAMING);
+ return EnumSet.of(Type.HTTP, Type.LOAD_BALANCE, Type.STREAMING);
}
-
+
}
Modified: incubator/stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/impl/EmbeddedSolrPorovider.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/impl/EmbeddedSolrPorovider.java?rev=1102791&r1=1102790&r2=1102791&view=diff
==============================================================================
--- incubator/stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/impl/EmbeddedSolrPorovider.java (original)
+++ incubator/stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/impl/EmbeddedSolrPorovider.java Fri May 13 15:29:20 2011
@@ -41,134 +41,139 @@ import org.osgi.service.component.Compon
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.xml.sax.SAXException;
+
/**
- * Support for the use of {@link EmbeddedSolrPorovider} in combination with the
- * SolrYard implementation. This implements the {@link SolrServerProvider}
- * interface for the {@link Type#EMBEDDED}.<p>
+ * Support for the use of {@link EmbeddedSolrPorovider} in combination with the SolrYard implementation. This
+ * implements the {@link SolrServerProvider} interface for the {@link Type#EMBEDDED}.
+ * <p>
+ *
+ * TODO: add functionality to lookup the internally managed {@link CoreContainer}. Maybe this requires to add
+ * a second service
*
- * TODO: add functionality to lookup the internally managed {@link CoreContainer}.
- * Maybe this requires to add a second service
* @author Rupert Westenthaler
- *
+ *
*/
-@Component(immediate=true,metatype=false)
+@Component(immediate = true, metatype = false)
@Service
public class EmbeddedSolrPorovider implements SolrServerProvider {
private final Logger log = LoggerFactory.getLogger(EmbeddedSolrPorovider.class);
- //define the default values here because they are not accessible via the Solr API
+ // define the default values here because they are not accessible via the Solr API
public static final String SOLR_XML_NAME = "solr.xml";
public static final String SOLR_CONFIG_NAME = "solrconfig.xml";
public static final String SOLR_SCHEMA_NAME = "schema.xml";
-
+
/**
- * internally used to keep track of active {@link CoreContainer}s for
- * requested paths.
+ * internally used to keep track of active {@link CoreContainer}s for requested paths.
*/
@SuppressWarnings("unchecked")
- private Map<String, CoreContainer> coreContainers = new ReferenceMap();
-
-
- public EmbeddedSolrPorovider() {
- }
-
+ private Map<String,CoreContainer> coreContainers = new ReferenceMap();
+
+ public EmbeddedSolrPorovider() {}
+
@Override
- public SolrServer getSolrServer(Type type, String uriOrPath, String... additional) throws NullPointerException, IllegalArgumentException {
- log.debug(String.format("getSolrServer Request for %s and path %s",type,uriOrPath));
- if(uriOrPath == null){
+ public SolrServer getSolrServer(Type type, String uriOrPath, String... additional) throws NullPointerException,
+ IllegalArgumentException {
+ log.debug(String.format("getSolrServer Request for %s and path %s", type, uriOrPath));
+ if (uriOrPath == null) {
throw new IllegalArgumentException("The Path to the Index MUST NOT be NULL!");
}
- log.info("parsed solr server location "+uriOrPath);
- //first try as file (but keep in mind it could also be an URI)
+ log.info("parsed solr server location " + uriOrPath);
+ // first try as file (but keep in mind it could also be an URI)
File index = ConfigUtils.toFile(uriOrPath);
- if(!index.exists()){
- throw new IllegalArgumentException(String.format("The parsed Index Path %s does not exist",uriOrPath));
+ if (!index.exists()) {
+ throw new IllegalArgumentException(String.format("The parsed Index Path %s does not exist",
+ uriOrPath));
}
- log.info("get solr server for location "+index);
+ log.info("get solr server for location " + index);
File coreDir = null;
- if(index.isDirectory()){
+ if (index.isDirectory()) {
File solr = getFile(index, SOLR_XML_NAME);
String coreName;
- if(solr != null){
- //in that case we assume that this is a single core installation
+ if (solr != null) {
+ // in that case we assume that this is a single core installation
coreName = "";
} else {
solr = getFile(index.getParentFile(), SOLR_XML_NAME);
- if(solr != null){
- //assume this is a multi core
+ if (solr != null) {
+ // assume this is a multi core
coreName = index.getName();
coreDir = index;
- index = index.getParentFile(); //set the index dir to the parent
+ index = index.getParentFile(); // set the index dir to the parent
} else {
- throw new IllegalArgumentException(String.format("The parsed Index Path %s is not an Solr " +
- "Index nor a Core of an Multi Core Configuration " +
- "(no \""+SOLR_XML_NAME+"\" was found in this nor the parent directory!)",uriOrPath));
+ throw new IllegalArgumentException(String.format(
+ "The parsed Index Path %s is not an Solr "
+ + "Index nor a Core of an Multi Core Configuration " + "(no \""
+ + SOLR_XML_NAME + "\" was found in this nor the parent directory!)",
+ uriOrPath));
}
}
- //now init the EmbeddedSolrServer
- log.info(String.format("Create EmbeddedSolrServer for index %s and core %s",index.getAbsolutePath(),coreName));
+ // now init the EmbeddedSolrServer
+ log.info(String.format("Create EmbeddedSolrServer for index %s and core %s",
+ index.getAbsolutePath(), coreName));
CoreContainer coreContainer = getCoreContainer(index.getAbsolutePath(), solr);
- //if we have a multi core environment and the core is not yet registered
- if(!coreName.isEmpty() && !coreContainer.getCoreNames().contains(coreName)){
- //register this core first
+ // if we have a multi core environment and the core is not yet registered
+ if (!coreName.isEmpty() && !coreContainer.getCoreNames().contains(coreName)) {
+ // register this core first
/*
- * NOTE:
- * We need to reset the ContextClassLoader to the one used for this
- * Bundle, because Solr uses this ClassLoader to load all the
- * plugins configured in the SOLR_XML_NAME and schema.xml.
- * The finally block resets the context class loader to the previous
- * value. (Rupert Westenthaler 20010209)
+ * NOTE: We need to reset the ContextClassLoader to the one used for this Bundle, because Solr
+ * uses this ClassLoader to load all the plugins configured in the SOLR_XML_NAME and
+ * schema.xml. The finally block resets the context class loader to the previous value.
+ * (Rupert Westenthaler 20010209)
*/
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader(EmbeddedSolrPorovider.class.getClassLoader());
try {
- //SolrResourceLoader solrLoader = new SolrResourceLoader(coreDir.getAbsolutePath());
- CoreDescriptor coreDescriptor = new CoreDescriptor(coreContainer,coreName,coreDir.getAbsolutePath());
+ // SolrResourceLoader solrLoader = new SolrResourceLoader(coreDir.getAbsolutePath());
+ CoreDescriptor coreDescriptor = new CoreDescriptor(coreContainer, coreName,
+ coreDir.getAbsolutePath());
SolrCore core;
try {
core = coreContainer.create(coreDescriptor);
} catch (Exception e) {
- throw new IllegalStateException(
- String.format("Unable to load/register Solr Core %s " +
- "to SolrServer %s!",coreName,index.getAbsoluteFile()),e);
+ throw new IllegalStateException(String.format("Unable to load/register Solr Core %s "
+ + "to SolrServer %s!", coreName,
+ index.getAbsoluteFile()), e);
}
- coreContainer.register(coreName, core,false);
- //persist the new core to have it available on the next start
- coreContainer.persist();
+ coreContainer.register(coreName, core, false);
+ // persist the new core to have it available on the next start
+ coreContainer.persist();
} finally {
Thread.currentThread().setContextClassLoader(classLoader);
}
}
return new EmbeddedSolrServer(coreContainer, coreName);
} else {
- throw new IllegalArgumentException(String.format("The parsed Index Path %s is no Directory",uriOrPath));
+ throw new IllegalArgumentException(String.format("The parsed Index Path %s is no Directory",
+ uriOrPath));
}
}
-
- protected final CoreContainer getCoreContainer(File solrDir) throws IllegalArgumentException, IllegalStateException {
- return getCoreContainer(solrDir.getAbsolutePath(), new File(solrDir,SOLR_XML_NAME));
+
+ protected final CoreContainer getCoreContainer(File solrDir) throws IllegalArgumentException,
+ IllegalStateException {
+ return getCoreContainer(solrDir.getAbsolutePath(), new File(solrDir, SOLR_XML_NAME));
}
- protected final CoreContainer getCoreContainer(String solrDir, File solrConf) throws IllegalArgumentException, IllegalStateException {
+
+ protected final CoreContainer getCoreContainer(String solrDir, File solrConf) throws IllegalArgumentException,
+ IllegalStateException {
CoreContainer container = coreContainers.get(solrDir);
- if(container == null){
+ if (container == null) {
container = new CoreContainer(solrDir);
/*
- * NOTE:
- * We need to reset the ContextClassLoader to the one used for this
- * Bundle, because Solr uses this ClassLoader to load all the
- * plugins configured in the SOLR_XML_NAME and schema.xml.
- * The finally block resets the context class loader to the previous
- * value. (Rupert Westenthaler 20010209)
+ * NOTE: We need to reset the ContextClassLoader to the one used for this Bundle, because Solr
+ * uses this ClassLoader to load all the plugins configured in the SOLR_XML_NAME and schema.xml.
+ * The finally block resets the context class loader to the previous value. (Rupert Westenthaler
+ * 20010209)
*/
ClassLoader loader = Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader(EmbeddedSolrPorovider.class.getClassLoader());
try {
container.load(solrDir, solrConf);
} catch (ParserConfigurationException e) {
- throw new IllegalStateException("Unable to parse Solr Configuration",e);
+ throw new IllegalStateException("Unable to parse Solr Configuration", e);
} catch (IOException e) {
- throw new IllegalStateException("Unable to access Solr Configuration",e);
+ throw new IllegalStateException("Unable to access Solr Configuration", e);
} catch (SAXException e) {
- throw new IllegalStateException("Unable to parse Solr Configuration",e);
+ throw new IllegalStateException("Unable to parse Solr Configuration", e);
} finally {
Thread.currentThread().setContextClassLoader(loader);
}
@@ -176,58 +181,64 @@ public class EmbeddedSolrPorovider imple
}
return container;
}
-
+
@Override
public Set<Type> supportedTypes() {
return Collections.singleton(Type.EMBEDDED);
}
+
@Activate
protected void activate(ComponentContext context) {
- log.debug("activating"+EmbeddedSolrPorovider.class.getSimpleName());
- //currently not used
+ log.debug("activating" + EmbeddedSolrPorovider.class.getSimpleName());
+ // currently not used
}
+
@Deactivate
protected void deactivate(ComponentContext context) {
- log.debug("deactivating"+EmbeddedSolrPorovider.class.getSimpleName());
- //currently not used
+ log.debug("deactivating" + EmbeddedSolrPorovider.class.getSimpleName());
+ // currently not used
}
-//Keeping for now because this might be useful when checking for required files
-// /**
-// * Checks if the parsed directory contains a file that starts with the parsed
-// * name. Parsing "hallo" will find "hallo.all", "hallo.ween" as well as "hallo".
-// * @param dir the Directory. This assumes that the parsed File is not
-// * <code>null</code>, exists and is an directory
-// * @param name the name. If <code>null</code> any file is accepted, meaning
-// * that this will return true if the directory contains any file
-// * @return the state
-// */
-// private boolean hasFile(File dir, String name){
-// return dir.list(new NameFileFilter(name)).length>0;
-// }
-// /**
-// * Returns the first file that matches the parsed name.
-// * Parsing "hallo" will find "hallo.all", "hallo.ween" as well as "hallo".
-// * @param dir the Directory. This assumes that the parsed File is not
-// * <code>null</code>, exists and is an directory.
-// * @param name the name. If <code>null</code> any file is accepted, meaning
-// * that this will return true if the directory contains any file
-// * @return the first file matching the parsed prefix.
-// */
-// private File getFileByPrefix(File dir, String prefix){
-// String[] files = dir.list(new PrefixFileFilter(prefix));
-// return files.length>0?new File(dir,files[0]):null;
-// }
+
+ // Keeping for now because this might be useful when checking for required files
+ // /**
+ // * Checks if the parsed directory contains a file that starts with the parsed
+ // * name. Parsing "hallo" will find "hallo.all", "hallo.ween" as well as "hallo".
+ // * @param dir the Directory. This assumes that the parsed File is not
+ // * <code>null</code>, exists and is an directory
+ // * @param name the name. If <code>null</code> any file is accepted, meaning
+ // * that this will return true if the directory contains any file
+ // * @return the state
+ // */
+ // private boolean hasFile(File dir, String name){
+ // return dir.list(new NameFileFilter(name)).length>0;
+ // }
+ // /**
+ // * Returns the first file that matches the parsed name.
+ // * Parsing "hallo" will find "hallo.all", "hallo.ween" as well as "hallo".
+ // * @param dir the Directory. This assumes that the parsed File is not
+ // * <code>null</code>, exists and is an directory.
+ // * @param name the name. If <code>null</code> any file is accepted, meaning
+ // * that this will return true if the directory contains any file
+ // * @return the first file matching the parsed prefix.
+ // */
+ // private File getFileByPrefix(File dir, String prefix){
+ // String[] files = dir.list(new PrefixFileFilter(prefix));
+ // return files.length>0?new File(dir,files[0]):null;
+ // }
/**
* Returns the first file that matches the parsed name (case sensitive)
- * @param dir the Directory. This assumes that the parsed File is not
- * <code>null</code>, exists and is an directory.
- * @param name the name. If <code>null</code> any file is accepted, meaning
- * that this will return true if the directory contains any file
+ *
+ * @param dir
+ * the Directory. This assumes that the parsed File is not <code>null</code>, exists and is an
+ * directory.
+ * @param name
+ * the name. If <code>null</code> any file is accepted, meaning that this will return true if
+ * the directory contains any file
* @return the first file matching the parsed name.
*/
- private File getFile(File dir, String name){
- String[] files = dir.list(new NameFileFilter(name));
- return files.length>0?new File(dir,files[0]):null;
+ private File getFile(File dir, String name) {
+ String[] files = dir.list(new NameFileFilter(name));
+ return files.length > 0 ? new File(dir, files[0]) : null;
}
}