From 9925f2c2af6b8edb1313c7ae708b45da2115c657 Mon Sep 17 00:00:00 2001 From: Jianghao Lu Date: Thu, 18 Aug 2016 15:42:42 -0700 Subject: [PATCH] Add back original async method signature --- .../resources/fluentcore/model/Creatable.java | 11 +++++++ .../model/implementation/CreatableImpl.java | 33 +++++++++++++++++++ .../implementation/DeploymentImpl.java | 27 +++++++++++++++ .../implementation/GenericResourceImpl.java | 26 ++++++++++++++- 4 files changed, 96 insertions(+), 1 deletion(-) diff --git a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/model/Creatable.java b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/model/Creatable.java index 7b76f4647f822..0533b0a2ba2ef 100644 --- a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/model/Creatable.java +++ b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/model/Creatable.java @@ -6,6 +6,8 @@ package com.microsoft.azure.management.resources.fluentcore.model; +import com.microsoft.rest.ServiceCall; +import com.microsoft.rest.ServiceCallback; import rx.Observable; /** @@ -27,6 +29,15 @@ public interface Creatable extends Indexable { */ T create() throws Exception; + /** + * Puts the request into the queue and allow the HTTP client to execute + * it when system resources are available. + * + * @param callback the callback to handle success and failure + * @return a handle to cancel the request + */ + ServiceCall createAsync(final ServiceCallback callback); + /** * Puts the request into the queue and allow the HTTP client to execute * it when system resources are available. diff --git a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/model/implementation/CreatableImpl.java b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/model/implementation/CreatableImpl.java index 206c5fb920568..9036f652302c5 100644 --- a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/model/implementation/CreatableImpl.java +++ b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/model/implementation/CreatableImpl.java @@ -8,7 +8,11 @@ import com.microsoft.azure.management.resources.fluentcore.arm.models.Resource; import com.microsoft.azure.management.resources.fluentcore.model.Creatable; +import com.microsoft.rest.ServiceCall; +import com.microsoft.rest.ServiceCallback; +import com.microsoft.rest.ServiceResponse; import rx.Observable; +import rx.functions.Action1; import rx.functions.Func1; /** @@ -76,6 +80,35 @@ public FluentModelImplT create() throws Exception { throw new IllegalStateException("Internal Error: create can be called only on preparer"); } + /** + * Puts the request into the queue and allow the HTTP client to execute + * it when system resources are available. + * + * @param callback the callback to handle success and failure + * @return a handle to cancel the request + */ + public ServiceCall createAsync(final ServiceCallback callback) { + final ServiceCall serviceCall = new ServiceCall<>(null); + createAsync().subscribe(new Action1() { + @Override + public void call(FluentModelT fluentModelT) { + serviceCall.success(new ServiceResponse<>(fluentModelT, null)); + if (callback != null) { + callback.success(new ServiceResponse<>(fluentModelT, null)); + } + } + }, new Action1() { + @Override + public void call(Throwable throwable) { + serviceCall.failure(throwable); + if (callback != null) { + callback.failure(throwable); + } + } + }); + return serviceCall; + } + /** * Default implementation of createAsync(). * diff --git a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/implementation/DeploymentImpl.java b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/implementation/DeploymentImpl.java index 325ea810b6f63..0436a2feedefc 100644 --- a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/implementation/DeploymentImpl.java +++ b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/implementation/DeploymentImpl.java @@ -23,8 +23,12 @@ import com.microsoft.azure.management.resources.fluentcore.arm.ResourceUtils; import com.microsoft.azure.management.resources.fluentcore.model.Creatable; import com.microsoft.azure.management.resources.fluentcore.model.implementation.CreatableUpdatableImpl; +import com.microsoft.rest.ServiceCall; +import com.microsoft.rest.ServiceCallback; +import com.microsoft.rest.ServiceResponse; import org.joda.time.DateTime; import rx.Observable; +import rx.functions.Action1; import rx.functions.Func1; import rx.schedulers.Schedulers; @@ -289,6 +293,29 @@ public DeploymentImpl create() throws Exception { return this; } + @Override + public ServiceCall createAsync(final ServiceCallback callback) { + final ServiceCall serviceCall = new ServiceCall<>(null); + createAsync().subscribe(new Action1() { + @Override + public void call(Deployment fluentModelT) { + serviceCall.success(new ServiceResponse<>(fluentModelT, null)); + if (callback != null) { + callback.success(new ServiceResponse<>(fluentModelT, null)); + } + } + }, new Action1() { + @Override + public void call(Throwable throwable) { + serviceCall.failure(throwable); + if (callback != null) { + callback.failure(throwable); + } + } + }); + return serviceCall; + } + @Override public Observable createAsync() { Observable observable = null; diff --git a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/implementation/GenericResourceImpl.java b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/implementation/GenericResourceImpl.java index 3a4140b0b35e0..e5d67bb3e94d4 100644 --- a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/implementation/GenericResourceImpl.java +++ b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/implementation/GenericResourceImpl.java @@ -10,7 +10,10 @@ import com.microsoft.azure.management.resources.Plan; import com.microsoft.azure.management.resources.fluentcore.arm.models.implementation.GroupableResourceImpl; import com.microsoft.rest.ServiceCall; +import com.microsoft.rest.ServiceCallback; +import com.microsoft.rest.ServiceResponse; import rx.Observable; +import rx.functions.Action1; import rx.schedulers.Schedulers; /** @@ -123,9 +126,30 @@ public GenericResourceImpl create() throws Exception { return this; } + public ServiceCall createAsync(final ServiceCallback callback) { + final ServiceCall serviceCall = new ServiceCall<>(null); + createAsync().subscribe(new Action1() { + @Override + public void call(GenericResource fluentModelT) { + serviceCall.success(new ServiceResponse<>(fluentModelT, null)); + if (callback != null) { + callback.success(new ServiceResponse<>(fluentModelT, null)); + } + } + }, new Action1() { + @Override + public void call(Throwable throwable) { + serviceCall.failure(throwable); + if (callback != null) { + callback.failure(throwable); + } + } + }); + return serviceCall; + } + @Override public Observable createAsync() { - final ServiceCall serviceCall = new ServiceCall<>(null); return createResourceAsync(); }