protected synchronized int getFirstReachableMessageId ( ) { final boolean followersRunning = ! this . runningFollowerStartMarks . isEmpty ( ) ; if ( ! followersRunning && this . terminatedFollowerRanges . isEmpty ( ) ) { // no followers present; no reachable messages return - 1 ; } final IntSortedSet set = new IntAVLTreeSet ( this . runningFollowerStartMarks . values ( ) ) ; if ( ! set . isEmpty ( ) ) { final int first = this . messages . getFirstPosition ( ) ; if ( set . firstInt ( ) <= first ) { /* * cannot go below first position; any other calculation * unnecessary */ return first ; } } set . addAll ( this . terminatedFollowerRanges . values ( ) . stream ( ) . map ( pair -> pair [ 0 ] ) . collect ( Collectors . toList ( ) ) ) ; return set . firstInt ( ) ; }
Will crawl the weak hash maps and make sure we always have the latest information on the availability of messages .