private void openProxy ( CompletableFuture < SessionClient > future ) { log . debug ( "Opening proxy session" ) ; proxyFactory . get ( ) . thenCompose ( proxy -> proxy . connect ( ) ) . whenComplete ( ( proxy , error ) -> { if ( error == null ) { synchronized ( this ) { this . log = ContextualLoggerFactory . getLogger ( getClass ( ) , LoggerContext . builder ( SessionClient . class ) . addValue ( proxy . sessionId ( ) ) . add ( "type" , proxy . type ( ) ) . add ( "name" , proxy . name ( ) ) . build ( ) ) ; this . session = proxy ; proxy . addStateChangeListener ( this :: onStateChange ) ; eventListeners . entries ( ) . forEach ( entry -> proxy . addEventListener ( entry . getKey ( ) , entry . getValue ( ) ) ) ; onStateChange ( PrimitiveState . CONNECTED ) ; } future . complete ( this ) ; } else { recoverTask = context . schedule ( Duration . ofSeconds ( 1 ) , ( ) -> openProxy ( future ) ) ; } } ) ; }
Opens a new client completing the provided future only once the client has been opened .