private void setupIndexMonitor ( final DataSchema dataSchema , final GenericDataSource dataSource ) { logger . log ( FINE , "LuceneSearchServiceImpl::setupIndexMonitor Attempting to setup Index monitor..." ) ; try { if ( GoogleAppEngineUtil . isGaeEnv ( ) ) { return ; // only use for pure lucene tomcat implementation, doesn't work on GAE. } if ( dataSource . getDataSourceType ( ) != GenericDataSource . DataSourceType . ServletRelativeDataSource || dataSource . getLocation ( ) == null ) { // only able to monitor servlet relative datasources return ; } else { // assertFilePathExists(dataSource.getLocation(), "jsonPath invalid:"); // File json = new File(dataSource.getLocation()); // try { // fileChangeMonitor = FileChangeMonitor.getInstance(); // fileChangeMonitor.init(json.toPath()); // if(Log.isDebugEnabled()) Log.debug("LuceneSearchServiceImpl::setupIndexMonitor","Index monitor setup completed."); // } catch (IOException e) { // throw new SearchException("Unable to initialize file change monitor",e); // } } fileChangeMonitor = FileChangeMonitor . getInstance ( ) ; fileChangeMonitor . addObserver ( new Observer ( ) { @ Override public void update ( Observable o , Object arg ) { JSONWithMetaData jsonContent ; try { logger . log ( FINE , "LuceneSearchServiceImpl::setupIndexMonitor" , "Index monitor change noted." ) ; jsonContent = getJsonArrayFrom ( dataSource ) ; } catch ( SearchException e ) { throw new IllegalStateException ( e ) ; } setupIndex ( dataSource , dataSchema , jsonContent ) ; } } ) ; } catch ( Exception e ) { logger . log ( SEVERE , "LuceneSearchServiceImpl::setupIndexMonitor Failed to setup monitor for indexed file changes" , e ) ; } }
setup a monitor to watch for changes in datasource