Search in sources :

Example 1 with ResourceManagerThrottlingInterceptor

use of com.microsoft.azure.management.resources.fluentcore.utils.ResourceManagerThrottlingInterceptor in project photon-model by vmware.

the class AzureSdkClients method buildRestClient.

/**
 * Build Azure RestClient with specified executor service and credentials using
 * {@link RestClient.Builder}.
 */
private static RestClient buildRestClient(ApplicationTokenCredentials credentials, ExecutorService executorService) {
    final Retrofit.Builder retrofitBuilder;
    {
        retrofitBuilder = new Retrofit.Builder();
        if (executorService != null) {
            RxJavaCallAdapterFactory rxWithExecutorCallFactory = RxJavaCallAdapterFactory.createWithScheduler(Schedulers.from(executorService));
            retrofitBuilder.addCallAdapterFactory(rxWithExecutorCallFactory);
        }
    }
    final RestClient.Builder restClientBuilder = new RestClient.Builder(new OkHttpClient.Builder(), retrofitBuilder);
    restClientBuilder.withBaseUrl(AzureUtils.getAzureBaseUri());
    restClientBuilder.withCredentials(credentials);
    restClientBuilder.withSerializerAdapter(new AzureJacksonAdapter());
    restClientBuilder.withLogLevel(getRestClientLogLevel());
    restClientBuilder.withInterceptor(new ResourceManagerThrottlingInterceptor());
    if (executorService != null) {
        restClientBuilder.withCallbackExecutor(executorService);
    }
    restClientBuilder.withResponseBuilderFactory(new Factory());
    return restClientBuilder.build();
}
Also used : Retrofit(retrofit2.Retrofit) OkHttpClient(okhttp3.OkHttpClient) RxJavaCallAdapterFactory(retrofit2.adapter.rxjava.RxJavaCallAdapterFactory) CacheBuilder(com.google.common.cache.CacheBuilder) AzureJacksonAdapter(com.microsoft.azure.serializer.AzureJacksonAdapter) RestClient(com.microsoft.rest.RestClient) Factory(com.microsoft.rest.ServiceResponseBuilder.Factory) RxJavaCallAdapterFactory(retrofit2.adapter.rxjava.RxJavaCallAdapterFactory) ResourceManagerThrottlingInterceptor(com.microsoft.azure.management.resources.fluentcore.utils.ResourceManagerThrottlingInterceptor)

Aggregations

CacheBuilder (com.google.common.cache.CacheBuilder)1 ResourceManagerThrottlingInterceptor (com.microsoft.azure.management.resources.fluentcore.utils.ResourceManagerThrottlingInterceptor)1 AzureJacksonAdapter (com.microsoft.azure.serializer.AzureJacksonAdapter)1 RestClient (com.microsoft.rest.RestClient)1 Factory (com.microsoft.rest.ServiceResponseBuilder.Factory)1 OkHttpClient (okhttp3.OkHttpClient)1 Retrofit (retrofit2.Retrofit)1 RxJavaCallAdapterFactory (retrofit2.adapter.rxjava.RxJavaCallAdapterFactory)1