public void waitForConnectedAndDeflectorHealthy ( long timeout , TimeUnit unit ) throws InterruptedException , TimeoutException { LOG . debug ( "Waiting until the write-active index is healthy again, checking once per second." ) ; final CountDownLatch latch = new CountDownLatch ( 1 ) ; final ScheduledFuture < ? > scheduledFuture = scheduler . scheduleAtFixedRate ( ( ) -> { try { if ( isConnected ( ) && isDeflectorHealthy ( ) ) { LOG . debug ( "Write-active index is healthy again, unblocking waiting threads." ) ; latch . countDown ( ) ; } } catch ( Exception ignore ) { } // to not cancel the schedule } , 0 , 1 , TimeUnit . SECONDS ) ; // TODO should this be configurable? final boolean waitSuccess = latch . await ( timeout , unit ) ; scheduledFuture . cancel ( true ) ; // Make sure to cancel the task to avoid task leaks! if ( ! waitSuccess ) { throw new TimeoutException ( "Write-active index didn't get healthy within timeout" ) ; } }
Blocks until the Elasticsearch cluster and current write index is healthy again or the given timeout fires .