public boolean addRepository ( final ArchiveRepository archiveRepository , final int pollInterval , TimeUnit timeUnit , boolean waitForInitialPoll ) { if ( pollInterval <= 0 ) { throw new IllegalArgumentException ( "invalid pollInterval " + pollInterval ) ; } Objects . requireNonNull ( timeUnit , "timeUnit" ) ; RepositoryPollerContext pollerContext = new RepositoryPollerContext ( ) ; RepositoryPollerContext oldContext = repositoryContexts . putIfAbsent ( archiveRepository , pollerContext ) ; if ( oldContext != null ) { return false ; } final CountDownLatch initialPollLatch = new CountDownLatch ( 1 ) ; ScheduledFuture < ? > future = pollerThreadPool . scheduleWithFixedDelay ( new Runnable ( ) { public void run ( ) { try { pollRepository ( archiveRepository ) ; initialPollLatch . countDown ( ) ; } catch ( Throwable t ) { // should never happen logger . error ( "Excecution exception on poll" , t ) ; } } } , 0 , pollInterval , timeUnit ) ; pollerContext . future = future ; if ( waitForInitialPoll ) { try { initialPollLatch . await ( ) ; } catch ( Exception e ) { // should never happen logger . error ( "Excecution exception on poll" , e ) ; } } return true ; }
Add a repository and schedule polling