private void consumeNextEvent ( EventLog < LeadershipEventListener < String > , LeadershipEvent < String > > eventLog , String name , String id , AsyncResponse response ) { eventLog . nextEvent ( ) . whenComplete ( ( event , error ) -> { if ( error == null ) { if ( event . newLeadership ( ) . leader ( ) != null && event . newLeadership ( ) . leader ( ) . id ( ) . equals ( id ) ) { response . resume ( Response . ok ( new LeadershipResponse ( event . newLeadership ( ) ) ) . build ( ) ) ; } else if ( event . newLeadership ( ) . candidates ( ) . stream ( ) . noneMatch ( c -> c . equals ( id ) ) ) { getPrimitive ( name ) . thenCompose ( election -> election . removeListener ( eventLog . listener ( ) ) ) . whenComplete ( ( removeResult , removeError ) -> { response . resume ( Response . status ( Status . NOT_FOUND ) . build ( ) ) ; } ) ; } } else { response . resume ( Response . status ( Status . NOT_FOUND ) . build ( ) ) ; } } ) ; }
Recursively consumes events from the given event log until the next event for the given ID is located .