Skip to content

Commit

Permalink
Add back original async method signature
Browse files Browse the repository at this point in the history
  • Loading branch information
jianghaolu committed Aug 18, 2016
1 parent 502345e commit 9925f2c
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand All @@ -27,6 +29,15 @@ public interface Creatable<T> 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<T> createAsync(final ServiceCallback<T> callback);

/**
* Puts the request into the queue and allow the HTTP client to execute
* it when system resources are available.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -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<FluentModelT> createAsync(final ServiceCallback<FluentModelT> callback) {
final ServiceCall<FluentModelT> serviceCall = new ServiceCall<>(null);
createAsync().subscribe(new Action1<FluentModelT>() {
@Override
public void call(FluentModelT fluentModelT) {
serviceCall.success(new ServiceResponse<>(fluentModelT, null));
if (callback != null) {
callback.success(new ServiceResponse<>(fluentModelT, null));
}
}
}, new Action1<Throwable>() {
@Override
public void call(Throwable throwable) {
serviceCall.failure(throwable);
if (callback != null) {
callback.failure(throwable);
}
}
});
return serviceCall;
}

/**
* Default implementation of createAsync().
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -289,6 +293,29 @@ public DeploymentImpl create() throws Exception {
return this;
}

@Override
public ServiceCall<Deployment> createAsync(final ServiceCallback<Deployment> callback) {
final ServiceCall<Deployment> serviceCall = new ServiceCall<>(null);
createAsync().subscribe(new Action1<Deployment>() {
@Override
public void call(Deployment fluentModelT) {
serviceCall.success(new ServiceResponse<>(fluentModelT, null));
if (callback != null) {
callback.success(new ServiceResponse<>(fluentModelT, null));
}
}
}, new Action1<Throwable>() {
@Override
public void call(Throwable throwable) {
serviceCall.failure(throwable);
if (callback != null) {
callback.failure(throwable);
}
}
});
return serviceCall;
}

@Override
public Observable<Deployment> createAsync() {
Observable<Deployment> observable = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -123,9 +126,30 @@ public GenericResourceImpl create() throws Exception {
return this;
}

public ServiceCall<GenericResource> createAsync(final ServiceCallback<GenericResource> callback) {
final ServiceCall<GenericResource> serviceCall = new ServiceCall<>(null);
createAsync().subscribe(new Action1<GenericResource>() {
@Override
public void call(GenericResource fluentModelT) {
serviceCall.success(new ServiceResponse<>(fluentModelT, null));
if (callback != null) {
callback.success(new ServiceResponse<>(fluentModelT, null));
}
}
}, new Action1<Throwable>() {
@Override
public void call(Throwable throwable) {
serviceCall.failure(throwable);
if (callback != null) {
callback.failure(throwable);
}
}
});
return serviceCall;
}

@Override
public Observable<GenericResource> createAsync() {
final ServiceCall<GenericResource> serviceCall = new ServiceCall<>(null);
return createResourceAsync();
}

Expand Down

0 comments on commit 9925f2c

Please sign in to comment.