Search in sources :

Example 91 with Observable

use of rx.Observable in project azure-sdk-for-java by Azure.

the class StorageAccountsInner method checkNameAvailabilityWithServiceResponseAsync.

/**
     * Checks that the storage account name is valid and is not already in use.
     *
     * @param name the String value
     * @throws IllegalArgumentException thrown if parameters fail the validation
     * @return the observable to the CheckNameAvailabilityResultInner object
     */
public Observable<ServiceResponse<CheckNameAvailabilityResultInner>> checkNameAvailabilityWithServiceResponseAsync(String name) {
    if (this.client.subscriptionId() == null) {
        throw new IllegalArgumentException("Parameter this.client.subscriptionId() is required and cannot be null.");
    }
    if (this.client.apiVersion() == null) {
        throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null.");
    }
    if (name == null) {
        throw new IllegalArgumentException("Parameter name is required and cannot be null.");
    }
    StorageAccountCheckNameAvailabilityParameters accountName = new StorageAccountCheckNameAvailabilityParameters();
    accountName.withName(name);
    return service.checkNameAvailability(this.client.subscriptionId(), this.client.apiVersion(), this.client.acceptLanguage(), accountName, this.client.userAgent()).flatMap(new Func1<Response<ResponseBody>, Observable<ServiceResponse<CheckNameAvailabilityResultInner>>>() {

        @Override
        public Observable<ServiceResponse<CheckNameAvailabilityResultInner>> call(Response<ResponseBody> response) {
            try {
                ServiceResponse<CheckNameAvailabilityResultInner> clientResponse = checkNameAvailabilityDelegate(response);
                return Observable.just(clientResponse);
            } catch (Throwable t) {
                return Observable.error(t);
            }
        }
    });
}
Also used : StorageAccountCheckNameAvailabilityParameters(com.microsoft.azure.management.storage.StorageAccountCheckNameAvailabilityParameters) Response(retrofit2.Response) ServiceResponse(com.microsoft.rest.ServiceResponse) ServiceResponse(com.microsoft.rest.ServiceResponse) Observable(rx.Observable) ResponseBody(okhttp3.ResponseBody)

Example 92 with Observable

use of rx.Observable in project Gradle-demo by Arisono.

the class Rxjava1 method retryWhen.

private static void retryWhen() {
    Observable.create(new Observable.OnSubscribe<Integer>() {

        @Override
        public void call(Subscriber<? super Integer> t) {
            OkhttpUtils.println("执行任务");
            t.onNext(12);
            OkhttpUtils.println("遇到错误....");
            //				t.onError(new RuntimeException("系统错误"));
            //			    t.onError(new ConnectException("服务器拒绝连接"));
            t.onError(new SocketTimeoutException("服务器连接超时"));
        }
    }).retryWhen(new Func1<Observable<? extends Throwable>, Observable<?>>() {

        @Override
        public Observable<?> call(Observable<? extends Throwable> t) {
            return t.flatMap(new Func1<Throwable, Observable<?>>() {

                private int count = 0;

                @Override
                public Observable<?> call(Throwable t) {
                    if (t instanceof SocketTimeoutException) {
                        OkhttpUtils.println("错误类型:服务器请求超时!!!");
                    }
                    if (t instanceof ConnectException) {
                        OkhttpUtils.println("错误类型:服务器拒绝连接!!!");
                    }
                    if (t instanceof RuntimeException) {
                        OkhttpUtils.println("错误类型:错误类型:运行时发生异常!!!");
                    }
                    if (++count <= 5) {
                        OkhttpUtils.println("网络请求重新连接" + count);
                        return Observable.timer(3000, TimeUnit.MILLISECONDS);
                    }
                    return Observable.error(t);
                }
            });
        }
    }).observeOn(RxjavaUtils.getNamedScheduler("线程1")).subscribe(new Subscriber<Integer>() {

        @Override
        public void onCompleted() {
            OkhttpUtils.println("onCompleted()");
        }

        @Override
        public void onError(Throwable e) {
            OkhttpUtils.println(e.getMessage());
        }

        @Override
        public void onNext(Integer t) {
            OkhttpUtils.println("" + t);
        }
    });
}
Also used : Observable(rx.Observable) SocketTimeoutException(java.net.SocketTimeoutException) Subscriber(rx.Subscriber) Func1(rx.functions.Func1) ConnectException(java.rmi.ConnectException)

Example 93 with Observable

use of rx.Observable in project azure-sdk-for-java by Azure.

the class ProfilesInner method beginUpdateWithServiceResponseAsync.

/**
     * Updates an existing CDN profile with the specified profile name under the specified subscription and resource group.
     *
     * @param resourceGroupName Name of the Resource group within the Azure subscription.
     * @param profileName Name of the CDN profile which is unique within the resource group.
     * @param tags Profile tags
     * @throws IllegalArgumentException thrown if parameters fail the validation
     * @return the observable to the ProfileInner object
     */
public Observable<ServiceResponse<ProfileInner>> beginUpdateWithServiceResponseAsync(String resourceGroupName, String profileName, Map<String, String> tags) {
    if (resourceGroupName == null) {
        throw new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null.");
    }
    if (profileName == null) {
        throw new IllegalArgumentException("Parameter profileName is required and cannot be null.");
    }
    if (this.client.subscriptionId() == null) {
        throw new IllegalArgumentException("Parameter this.client.subscriptionId() is required and cannot be null.");
    }
    if (this.client.apiVersion() == null) {
        throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null.");
    }
    if (tags == null) {
        throw new IllegalArgumentException("Parameter tags is required and cannot be null.");
    }
    Validator.validate(tags);
    ProfileUpdateParameters profileUpdateParameters = new ProfileUpdateParameters();
    profileUpdateParameters.withTags(tags);
    return service.beginUpdate(resourceGroupName, profileName, this.client.subscriptionId(), this.client.apiVersion(), this.client.acceptLanguage(), profileUpdateParameters, this.client.userAgent()).flatMap(new Func1<Response<ResponseBody>, Observable<ServiceResponse<ProfileInner>>>() {

        @Override
        public Observable<ServiceResponse<ProfileInner>> call(Response<ResponseBody> response) {
            try {
                ServiceResponse<ProfileInner> clientResponse = beginUpdateDelegate(response);
                return Observable.just(clientResponse);
            } catch (Throwable t) {
                return Observable.error(t);
            }
        }
    });
}
Also used : Response(retrofit2.Response) ServiceResponse(com.microsoft.rest.ServiceResponse) ServiceResponse(com.microsoft.rest.ServiceResponse) ProfileUpdateParameters(com.microsoft.azure.management.cdn.ProfileUpdateParameters) Observable(rx.Observable) ResponseBody(okhttp3.ResponseBody)

Example 94 with Observable

use of rx.Observable in project azure-sdk-for-java by Azure.

the class CustomDomainsInner method beginCreateWithServiceResponseAsync.

/**
     * Creates a new custom domain within an endpoint.
     *
     * @param resourceGroupName Name of the Resource group within the Azure subscription.
     * @param profileName Name of the CDN profile which is unique within the resource group.
     * @param endpointName Name of the endpoint under the profile which is unique globally.
     * @param customDomainName Name of the custom domain within an endpoint.
     * @param hostName The host name of the custom domain. Must be a domain name.
     * @throws IllegalArgumentException thrown if parameters fail the validation
     * @return the observable to the CustomDomainInner object
     */
public Observable<ServiceResponse<CustomDomainInner>> beginCreateWithServiceResponseAsync(String resourceGroupName, String profileName, String endpointName, String customDomainName, String hostName) {
    if (resourceGroupName == null) {
        throw new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null.");
    }
    if (profileName == null) {
        throw new IllegalArgumentException("Parameter profileName is required and cannot be null.");
    }
    if (endpointName == null) {
        throw new IllegalArgumentException("Parameter endpointName is required and cannot be null.");
    }
    if (customDomainName == null) {
        throw new IllegalArgumentException("Parameter customDomainName is required and cannot be null.");
    }
    if (this.client.subscriptionId() == null) {
        throw new IllegalArgumentException("Parameter this.client.subscriptionId() is required and cannot be null.");
    }
    if (this.client.apiVersion() == null) {
        throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null.");
    }
    if (hostName == null) {
        throw new IllegalArgumentException("Parameter hostName is required and cannot be null.");
    }
    CustomDomainParameters customDomainProperties = new CustomDomainParameters();
    customDomainProperties.withHostName(hostName);
    return service.beginCreate(resourceGroupName, profileName, endpointName, customDomainName, this.client.subscriptionId(), this.client.apiVersion(), this.client.acceptLanguage(), customDomainProperties, this.client.userAgent()).flatMap(new Func1<Response<ResponseBody>, Observable<ServiceResponse<CustomDomainInner>>>() {

        @Override
        public Observable<ServiceResponse<CustomDomainInner>> call(Response<ResponseBody> response) {
            try {
                ServiceResponse<CustomDomainInner> clientResponse = beginCreateDelegate(response);
                return Observable.just(clientResponse);
            } catch (Throwable t) {
                return Observable.error(t);
            }
        }
    });
}
Also used : Response(retrofit2.Response) ServiceResponse(com.microsoft.rest.ServiceResponse) ServiceResponse(com.microsoft.rest.ServiceResponse) CustomDomainParameters(com.microsoft.azure.management.cdn.CustomDomainParameters) Observable(rx.Observable) ResponseBody(okhttp3.ResponseBody)

Example 95 with Observable

use of rx.Observable in project azure-sdk-for-java by Azure.

the class RegistriesInner method regenerateCredentialWithServiceResponseAsync.

/**
     * Regenerates one of the login credentials for the specified container registry.
     *
     * @param resourceGroupName The name of the resource group to which the container registry belongs.
     * @param registryName The name of the container registry.
     * @param name Specifies name of the password which should be regenerated -- password or password2. Possible values include: 'password', 'password2'
     * @throws IllegalArgumentException thrown if parameters fail the validation
     * @return the observable to the RegistryListCredentials object
     */
public Observable<ServiceResponse<RegistryListCredentials>> regenerateCredentialWithServiceResponseAsync(String resourceGroupName, String registryName, PasswordName name) {
    if (this.client.subscriptionId() == null) {
        throw new IllegalArgumentException("Parameter this.client.subscriptionId() is required and cannot be null.");
    }
    if (resourceGroupName == null) {
        throw new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null.");
    }
    if (registryName == null) {
        throw new IllegalArgumentException("Parameter registryName is required and cannot be null.");
    }
    if (this.client.apiVersion() == null) {
        throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null.");
    }
    if (name == null) {
        throw new IllegalArgumentException("Parameter name is required and cannot be null.");
    }
    RegenerateCredentialParameters regenerateCredentialParameters = new RegenerateCredentialParameters();
    regenerateCredentialParameters.withName(name);
    return service.regenerateCredential(this.client.subscriptionId(), resourceGroupName, registryName, this.client.apiVersion(), this.client.acceptLanguage(), regenerateCredentialParameters, this.client.userAgent()).flatMap(new Func1<Response<ResponseBody>, Observable<ServiceResponse<RegistryListCredentials>>>() {

        @Override
        public Observable<ServiceResponse<RegistryListCredentials>> call(Response<ResponseBody> response) {
            try {
                ServiceResponse<RegistryListCredentials> clientResponse = regenerateCredentialDelegate(response);
                return Observable.just(clientResponse);
            } catch (Throwable t) {
                return Observable.error(t);
            }
        }
    });
}
Also used : Response(retrofit2.Response) ServiceResponse(com.microsoft.rest.ServiceResponse) ServiceResponse(com.microsoft.rest.ServiceResponse) RegenerateCredentialParameters(com.microsoft.azure.management.containerregistry.RegenerateCredentialParameters) Observable(rx.Observable) ResponseBody(okhttp3.ResponseBody)

Aggregations

Observable (rx.Observable)210 ResponseBody (okhttp3.ResponseBody)97 Response (retrofit2.Response)93 ServiceResponse (com.microsoft.rest.ServiceResponse)92 ArrayList (java.util.ArrayList)39 Test (org.junit.Test)34 List (java.util.List)33 Func1 (rx.functions.Func1)26 IOException (java.io.IOException)16 Subscription (rx.Subscription)14 Action1 (rx.functions.Action1)13 Context (android.content.Context)12 Schedulers (rx.schedulers.Schedulers)12 ByteBuf (io.netty.buffer.ByteBuf)10 NonNull (android.support.annotation.NonNull)9 Collections (java.util.Collections)9 Intent (android.content.Intent)8 SharedPreferences (android.content.SharedPreferences)8 UnsupportedEncodingException (java.io.UnsupportedEncodingException)8 PreferenceManager (android.preference.PreferenceManager)7