Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ public final CreatedResources<T> create(Creatable<T> ... creatables) throws Exce
return BlockingObservable.from(createAsync(creatables)).single();
}

@Override
public final CreatedResources<T> create(List<Creatable<T>> creatables) throws Exception {
return BlockingObservable.from(createAsync(creatables)).single();
}

@Override
@SafeVarargs
public final Observable<CreatedResources<T>> createAsync(Creatable<T> ... creatables) {
Expand All @@ -58,6 +63,20 @@ public CreatedResources<T> call(CreatableResourcesRoot<T> tCreatableResourcesRoo
});
}

@Override
public final Observable<CreatedResources<T>> createAsync(List<Creatable<T>> creatables) {
CreatableResourcesRootImpl<T> rootResource = new CreatableResourcesRootImpl<>();
rootResource.addCreatableDependencies(creatables);

return rootResource.createAsync()
.map(new Func1<CreatableResourcesRoot<T>, CreatedResources<T>>() {
@Override
public CreatedResources<T> call(CreatableResourcesRoot<T> tCreatableResourcesRoot) {
return new CreatedResourcesImpl<T>(tCreatableResourcesRoot);
}
});
}

@Override
@SafeVarargs
public final ServiceCall<CreatedResources<T>> createAsync(final ServiceCallback<CreatedResources<T>> callback, Creatable<T>... creatables) {
Expand All @@ -70,6 +89,17 @@ public ServiceResponse<CreatedResources<T>> call(CreatedResources<T> ts) {
}), callback);
}

@Override
public final ServiceCall<CreatedResources<T>> createAsync(final ServiceCallback<CreatedResources<T>> callback, List<Creatable<T>> creatables) {
return ServiceCall.create(createAsync(creatables).map(new Func1<CreatedResources<T>, ServiceResponse<CreatedResources<T>>>() {
@Override
public ServiceResponse<CreatedResources<T>> call(CreatedResources<T> ts) {
// TODO: When https://github.com/Azure/azure-sdk-for-java/issues/1029 is done, this map can be removed
return new ServiceResponse<>(ts, null);
}
}), callback);
}

/**
* Implements {@link CreatedResources}.
* @param <ResourceT> the type of the resources in the batch.
Expand Down Expand Up @@ -254,6 +284,13 @@ void addCreatableDependencies(Creatable<T> ... creatables) {
}
}

void addCreatableDependencies(List<Creatable<T>> creatables) {
for (Creatable<T> item : creatables) {
this.keys.add(item.key());
this.addCreatableDependency((item));
}
}

@Override
public Observable<CreatableResourcesRoot<ResourceT>> createResourceAsync() {
return Observable.just((CreatableResourcesRoot<ResourceT>) this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import com.microsoft.rest.ServiceCallback;
import rx.Observable;

import java.util.List;

/**
* Providing access to creating a batch of Azure top level resources of same type.
* <p>
Expand All @@ -24,6 +26,15 @@ public interface SupportsBatchCreation<ResourceT extends Resource> {
*/
CreatedResources<ResourceT> create(Creatable<ResourceT>... creatables) throws Exception;

/**
* Executes the create requests on a collection (batch) of resources.
*
* @param creatables the list of creatables in the batch
* @return the batch operation result from which created resources in this batch can be accessed.
* @throws Exception exceptions from Azure
*/
CreatedResources<ResourceT> create(List<Creatable<ResourceT>> creatables) throws Exception;

/**
* Puts the requests to create a batch of resources into the queue and allow the HTTP client to execute it when
* system resources are available.
Expand All @@ -33,6 +44,15 @@ public interface SupportsBatchCreation<ResourceT extends Resource> {
*/
Observable<CreatedResources<ResourceT>> createAsync(Creatable<ResourceT>... creatables);

/**
* Puts the requests to create a batch of resources into the queue and allow the HTTP client to execute it when
* system resources are available.
*
* @param creatables the list of creatables in the batch
* @return an observable for the resources
*/
Observable<CreatedResources<ResourceT>> createAsync(List<Creatable<ResourceT>> creatables);

/**
* Puts the requests to create a batch of resources into the queue and allow the HTTP client to execute it when
* system resources are available.
Expand All @@ -42,4 +62,14 @@ public interface SupportsBatchCreation<ResourceT extends Resource> {
* @return a handle to cancel the request
*/
ServiceCall<CreatedResources<ResourceT>> createAsync(ServiceCallback<CreatedResources<ResourceT>> callback, Creatable<ResourceT>... creatables);

/**
* Puts the requests to create a batch of resources 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
* @param creatables the list of creatables in the batch
* @return a handle to cancel the request
*/
ServiceCall<CreatedResources<ResourceT>> createAsync(final ServiceCallback<CreatedResources<ResourceT>> callback, List<Creatable<ResourceT>> creatables);
}