b2-sdk-java icon indicating copy to clipboard operation
b2-sdk-java copied to clipboard

[enhancement request] make retryer and sleeper more flexible

Open yanshenxian opened this issue 5 years ago • 5 comments

sdk version: 4.0.0

B2StorageClient client = B2StorageClientFactory
             .createDefaultFactory()
             .create(APP_KEY_ID, APP_KEY, USER_AGENT);

The default B2RetryPolicy wil try max 8 attempts and each time wil sleep at least 1 second.

Because hard code sleeper.sleepSeconds(waitSeconds) written at com.backblaze.b2.client.B2Retryer#doRetry(java.lang.String, com.backblaze.b2.client.B2AccountAuthorizationCache, com.backblaze.b2.client.B2Retryer.RetryableCallable<T>, com.backblaze.b2.client.B2RetryPolicy)

And these classes (and some parameter classes) are package accessed.

It's not easy to change the retry behavior... 😢

yanshenxian avatar Jul 06 '20 12:07 yanshenxian

Hi yanshenxian --

It's true, the B2StorageClientFactory doesn't make it easy to change the retry policy. Sorry. The B2StorageClientFactory is fairly new and doesn't expose all of the flexibility of the rest of the SDK.

To set the B2RetryPolicy implementation to your own class with the existing code, you will need to use something like the B2StorageHttpClientBuilder and call setRetryPolicySupplier, passing a Supplier<B2RetryPolicy>.

Alternatively, if you would like to make a PR that adds setRetryPolicy() to B2StorageClientFactory, I'd be open to reviewing it. :)

thanks, ab

certainmagic avatar Jul 06 '20 16:07 certainmagic

Hi yanshenxian --

Were those pointers helpful?

thanks, ab

certainmagic avatar Jul 08 '20 16:07 certainmagic

@certainmagic hi thanks for your reply~ I'm using setRetryPolicy() simply now. But sorry for have not enough time to write a functional pr...

yanshenxian avatar Jul 09 '20 15:07 yanshenxian

hi yanshenxian --

It looks like your reply got truncated somewhere along the way.

ttfn, ab

certainmagic avatar Jul 10 '20 01:07 certainmagic

Hi @yanshenxian --

Just checking in...

ttfn, ab

certainmagic avatar Jul 15 '20 15:07 certainmagic