public synchronized Future < Message > setExpectation ( final C condition , final MessageAction < P > action ) { if ( this . isStopped ( ) ) { throw new IllegalStateException ( "Already stopped." ) ; } final AbstractExpectation < C , P > expectation = this . createExpectation ( condition , action ) ; final Future < Message > future = AbstractExpectationManager . EXECUTOR . submit ( expectation ) ; this . expectations . put ( expectation , future ) ; AbstractExpectationManager . LOGGER . info ( "Registered expectation {} with action {}." , expectation , action ) ; return future ; }
The resulting future will only return after such a message is received that makes the condition true .