Backblaze / b2-sdk-java

The official Java SDK for using Backblaze's B2 Storage APIs
Other
93 stars 26 forks source link

[enhancement request] make retryer and sleeper more flexible #121

Open yanshenxian opened 4 years ago

yanshenxian commented 4 years ago

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... 😢

certainmagic commented 4 years ago

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.

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

thanks, ab

certainmagic commented 4 years ago

Hi yanshenxian --

Were those pointers helpful?

thanks, ab

yanshenxian commented 4 years ago

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

certainmagic commented 4 years ago

hi yanshenxian --

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

ttfn, ab

certainmagic commented 4 years ago

Hi @yanshenxian --

Just checking in...

ttfn, ab