private void schedule ( final IndexSet indexSet ) { final String indexSetId = indexSet . getConfig ( ) . id ( ) ; final String indexSetTitle = indexSet . getConfig ( ) . title ( ) ; final Duration refreshInterval = indexSet . getConfig ( ) . fieldTypeRefreshInterval ( ) ; if ( Duration . ZERO . equals ( refreshInterval ) ) { LOG . debug ( "Skipping index set with ZERO refresh interval <{}/{}>" , indexSetTitle , indexSetId ) ; return ; } if ( ! indexSet . getConfig ( ) . isWritable ( ) ) { LOG . debug ( "Skipping non-writable index set <{}/{}>" , indexSetTitle , indexSetId ) ; return ; } // Make sure there is no existing polling job running for this index set cancel ( futures . get ( indexSetId ) ) ; LOG . debug ( "Schedule index field type updating for index set <{}/{}> every {} ms" , indexSetId , indexSetTitle , refreshInterval . getMillis ( ) ) ; final ScheduledFuture < ? > future = scheduler . scheduleAtFixedRate ( ( ) -> { try { // Only check the active write index on a regular basis, the others don't change anymore final String activeWriteIndex = indexSet . getActiveWriteIndex ( ) ; if ( activeWriteIndex != null ) { LOG . debug ( "Updating index field types for active write index <{}> in index set <{}/{}>" , activeWriteIndex , indexSetTitle , indexSetId ) ; poller . pollIndex ( activeWriteIndex , indexSetId ) . ifPresent ( dbService :: upsert ) ; } else { LOG . warn ( "Active write index for index set \"{}\" ({}) doesn't exist yet" , indexSetTitle , indexSetId ) ; } } catch ( TooManyAliasesException e ) { LOG . error ( "Couldn't get active write index" , e ) ; } catch ( Exception e ) { LOG . error ( "Couldn't update field types for index set <{}/{}>" , indexSetTitle , indexSetId , e ) ; } } , 0 , refreshInterval . getMillis ( ) , TimeUnit . MILLISECONDS ) ; futures . put ( indexSetId , future ) ; }
Creates a new polling job for the given index set to keep the active write index information up to date .