@ SuppressWarnings ( "unchecked" ) public void startRegistration ( ) { if ( canceled ) { // we already got canceled return ; } try { // trigger resolution of the target address to a callable gateway final CompletableFuture < G > rpcGatewayFuture ; if ( FencedRpcGateway . class . isAssignableFrom ( targetType ) ) { rpcGatewayFuture = ( CompletableFuture < G > ) rpcService . connect ( targetAddress , fencingToken , targetType . asSubclass ( FencedRpcGateway . class ) ) ; } else { rpcGatewayFuture = rpcService . connect ( targetAddress , targetType ) ; } // upon success, start the registration attempts CompletableFuture < Void > rpcGatewayAcceptFuture = rpcGatewayFuture . thenAcceptAsync ( ( G rpcGateway ) -> { log . info ( "Resolved {} address, beginning registration" , targetName ) ; register ( rpcGateway , 1 , retryingRegistrationConfiguration . getInitialRegistrationTimeoutMillis ( ) ) ; } , rpcService . getExecutor ( ) ) ; // upon failure, retry, unless this is cancelled rpcGatewayAcceptFuture . whenCompleteAsync ( ( Void v , Throwable failure ) -> { if ( failure != null && ! canceled ) { final Throwable strippedFailure = ExceptionUtils . stripCompletionException ( failure ) ; if ( log . isDebugEnabled ( ) ) { log . debug ( "Could not resolve {} address {}, retrying in {} ms." , targetName , targetAddress , retryingRegistrationConfiguration . getErrorDelayMillis ( ) , strippedFailure ) ; } else { log . info ( "Could not resolve {} address {}, retrying in {} ms: {}." , targetName , targetAddress , retryingRegistrationConfiguration . getErrorDelayMillis ( ) , strippedFailure . getMessage ( ) ) ; } startRegistrationLater ( retryingRegistrationConfiguration . getErrorDelayMillis ( ) ) ; } } , rpcService . getExecutor ( ) ) ; } catch ( Throwable t ) { completionFuture . completeExceptionally ( t ) ; cancel ( ) ; } }
This method resolves the target address to a callable gateway and starts the registration after that .