public Operation < R , M > waitFor ( RetryOption ... waitOptions ) throws SpannerException { if ( isDone ( ) ) { return this ; } RetrySettings waitSettings = RetryOption . mergeToSettings ( DEFAULT_OPERATION_WAIT_SETTINGS , waitOptions ) ; try { com . google . longrunning . Operation proto = RetryHelper . poll ( new Callable < com . google . longrunning . Operation > ( ) { @ Override public com . google . longrunning . Operation call ( ) throws Exception { return rpc . getOperation ( name ) ; } } , waitSettings , new BasicResultRetryAlgorithm < com . google . longrunning . Operation > ( ) { @ Override public boolean shouldRetry ( Throwable prevThrowable , com . google . longrunning . Operation prevResponse ) { if ( prevResponse != null ) { return ! prevResponse . getDone ( ) ; } if ( prevThrowable instanceof SpannerException ) { SpannerException spannerException = ( SpannerException ) prevThrowable ; return spannerException . getErrorCode ( ) != ErrorCode . NOT_FOUND && spannerException . isRetryable ( ) ; } return false ; } } , clock ) ; return Operation . create ( rpc , proto , parser ) ; } catch ( InterruptedException e ) { throw SpannerExceptionFactory . propagateInterrupt ( e ) ; } catch ( ExecutionException e ) { Throwable cause = e . getCause ( ) ; if ( cause instanceof SpannerException ) { SpannerException spannerException = ( SpannerException ) cause ; if ( spannerException . getErrorCode ( ) == ErrorCode . NOT_FOUND ) { return null ; } throw spannerException ; } if ( cause instanceof PollException ) { throw SpannerExceptionFactory . newSpannerException ( ErrorCode . DEADLINE_EXCEEDED , "Operation did not complete in the given time" ) ; } throw SpannerExceptionFactory . newSpannerException ( cause ) ; } }
Blocks till the operation is complete or maximum time if specified has elapsed .