Changeset 27872

Show
Ignore:
Timestamp:
16.07.2013 01:23:23 (6 years ago)
Author:
davidb
Message:

Null pointer check needed for when none of the solr cores have been loaded in (because no one has entered a Solr collection)

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • gs3-extensions/solr/trunk/src/src/java/org/greenstone/gsdl3/service/GS2SolrSearch.java

    r27867 r27872  
    173173        String collection_core_name_prefix = getCollectionCoreNamePrefix(); 
    174174 
    175         Collection<String> coreNames = all_solr_cores.getCoreNames(); 
    176         if(!coreNames.isEmpty()) { 
    177             Iterator<String> coreIterator = coreNames.iterator(); 
    178             while(coreIterator.hasNext()) { 
    179  
    180             String solrCoreName = coreIterator.next();       
    181             if(solrCoreName.startsWith(collection_core_name_prefix)) { 
    182  
    183                 logger.error("**** Removing collection-specific core: " + solrCoreName + " from CoreContainer"); 
    184  
    185                 // CoreContainer.remove(String name): removes and returns registered core w/o decrementing it's reference count 
    186                 // http://lucene.apache.org/solr/api/index.html?org/apache/solr/core/CoreContainer.html 
    187                 SolrCore solr_core = all_solr_cores.remove(solrCoreName); 
    188                 while(!solr_core.isClosed()) { 
    189                 logger.error("@@@@@@ " + solrCoreName + " was not closed. Closing...."); 
    190                 solr_core.close(); // http://lucene.apache.org/solr/api/org/apache/solr/core/SolrCore.html 
    191                 }  
    192                 if(solr_core.isClosed()) { 
    193                 logger.error("@@@@@@ " + solrCoreName + " is closed."); 
     175        if (all_solr_cores!=null) { 
     176            Collection<String> coreNames = all_solr_cores.getCoreNames(); 
     177            if(!coreNames.isEmpty()) { 
     178            Iterator<String> coreIterator = coreNames.iterator(); 
     179            while(coreIterator.hasNext()) { 
     180                 
     181                String solrCoreName = coreIterator.next();       
     182                if(solrCoreName.startsWith(collection_core_name_prefix)) { 
     183                 
     184                logger.error("**** Removing collection-specific core: " + solrCoreName + " from CoreContainer"); 
     185                 
     186                // CoreContainer.remove(String name): removes and returns registered core w/o decrementing it's reference count 
     187                // http://lucene.apache.org/solr/api/index.html?org/apache/solr/core/CoreContainer.html 
     188                SolrCore solr_core = all_solr_cores.remove(solrCoreName); 
     189                while(!solr_core.isClosed()) { 
     190                    logger.error("@@@@@@ " + solrCoreName + " was not closed. Closing...."); 
     191                    solr_core.close(); // http://lucene.apache.org/solr/api/org/apache/solr/core/SolrCore.html 
     192                }  
     193                if(solr_core.isClosed()) { 
     194                    logger.error("@@@@@@ " + solrCoreName + " is closed."); 
     195                } 
     196                solr_core = null; 
    194197                } 
    195                 solr_core = null; 
    196198            } 
    197199            } 
     
    201203        // All going well, this will happen when we're ant stopping the Greenstone server and the last Solr collection 
    202204        // is being deactivated 
    203         Collection<String> coreNamesRemaining = all_solr_cores.getCoreNames(); 
    204         if(coreNamesRemaining.isEmpty()) { 
    205             logger.error("**** CoreContainer contains 0 solrCores. Shutting down..."); 
    206  
    207             all_solr_cores.shutdown(); // wouldn't do anything anyway for 0 cores I think 
    208             all_solr_cores = null; 
    209         }  
    210         else { // else part is just for debugging 
    211             Iterator coreIterator = coreNamesRemaining.iterator(); 
    212             while(coreIterator.hasNext()) { 
    213             logger.error("**** Core: " + coreIterator.next() + " still exists in CoreContainer"); 
     205 
     206        if (all_solr_cores!=null) { 
     207            Collection<String> coreNamesRemaining = all_solr_cores.getCoreNames(); 
     208            if(coreNamesRemaining.isEmpty()) { 
     209            logger.error("**** CoreContainer contains 0 solrCores. Shutting down..."); 
     210             
     211            all_solr_cores.shutdown(); // wouldn't do anything anyway for 0 cores I think 
     212            all_solr_cores = null; 
     213            }  
     214            else { // else part is just for debugging 
     215            Iterator coreIterator = coreNamesRemaining.iterator(); 
     216            while(coreIterator.hasNext()) { 
     217                logger.error("**** Core: " + coreIterator.next() + " still exists in CoreContainer"); 
     218            } 
    214219            } 
    215220        }