Skip to content

Commit

Permalink
Squashed 'runtimes/' changes from 930fbf5..3010c5c
Browse files Browse the repository at this point in the history
3010c5c Merge pull request Azure#52 from jianghaolu/unwrap
c78b9c5 Merge commit '9934126e3d2115bedd890f8226cdf1c2c6d39a48' into unwrap
ac146e8 Fix errors
670b55e Merge pull request Azure#51 from jianghaolu/09062016
b5aa0f4 Remove ServiceResponse<> wrappers in most methods
a55439f fixed page listing for no item lists.
e132607 Remove redundant sync & callback based applys
d0191c7 Merge commit '794b2abafedf65c2052f2a7a5932155662de8ab1' into rx
7fb2d38 Fix socket timeout and parallel creation
2c7a100 Fix checkstyle errors
866a220 Adapt fluent impls to use native observables
e9fa2de Fix pagings with headers
ffc5544 Merge commit 'dc9cf4f0b75ac3672a3e125fa2b905dcab7d46f1' into rx
a1c0ae4 Generated code returns observables
7814d4f Merge commit '65d59d6f659b227b9936911c99f9cd053249af86' into rx
de94443 Merge pull request Azure#49 from Azure/sdk_1026
218ef3a Merge pull request Azure#47 from Azure/sdk_1023
13f7e4b Merge pull request Azure#46 from Azure/sdk_1021
6b54fd6 Merge pull request Azure#44 from Azure/sdk_1015
2572366 Merge branch 'master' of github.com:Azure/azure-sdk-for-java into rx
b8004bc Merge pull request Azure#1023 from anuchandy/fixrawtype
ac5100f Fixing the javadoc error and formatting errors for key vault
9980d1f Fixing a bunch of RawType usages and minor improvments in simplying callback
7c46138 Merge pull request Azure#45 from jianghaolu/autorest_1343

git-subtree-dir: runtimes
git-subtree-split: 3010c5c
  • Loading branch information
jianghaolu committed Sep 6, 2016
1 parent dc9cf4f commit 14c7898
Show file tree
Hide file tree
Showing 12 changed files with 70 additions and 58 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import com.microsoft.rest.ServiceCall;
import com.microsoft.rest.ServiceResponse;
import com.microsoft.rest.ServiceResponseWithHeaders;

import java.util.List;

Expand Down Expand Up @@ -45,6 +46,36 @@ public static <E> ServiceCall<List<E>> create(Observable<ServiceResponse<Page<E>
return serviceCall;
}

/**
* Creates a ServiceCall from a paging operation that returns a header response.
*
* @param first the observable to the first page
* @param next the observable to poll subsequent pages
* @param callback the client-side callback
* @param <E> the element type
* @param <V> the header object type
* @return the future based ServiceCall
*/
public static <E, V> ServiceCall<List<E>> createWithHeaders(Observable<ServiceResponseWithHeaders<Page<E>, V>> first, final Func1<String, Observable<ServiceResponseWithHeaders<Page<E>, V>>> next, final ListOperationCallback<E> callback) {
final AzureServiceCall<List<E>> serviceCall = new AzureServiceCall<>();
final PagingSubscriber<E> subscriber = new PagingSubscriber<>(serviceCall, new Func1<String, Observable<ServiceResponse<Page<E>>>>() {
@Override
public Observable<ServiceResponse<Page<E>>> call(String s) {
return next.call(s)
.map(new Func1<ServiceResponseWithHeaders<Page<E>, V>, ServiceResponse<Page<E>>>() {
@Override
public ServiceResponse<Page<E>> call(ServiceResponseWithHeaders<Page<E>, V> pageVServiceResponseWithHeaders) {
return pageVServiceResponseWithHeaders;
}
});
}
}, callback);
serviceCall.setSubscription(first
.single()
.subscribe(subscriber));
return serviceCall;
}

/**
* The subscriber that handles user callback and automatically subscribes to the next page.
*
Expand Down Expand Up @@ -86,7 +117,7 @@ public void onNext(ServiceResponse<Page<E>> serviceResponse) {
}
}
if (behavior == ListOperationCallback.PagingBehavior.STOP || serviceResponse.getBody().getNextPageLink() == null) {
serviceCall.set(new ServiceResponse<>(lastResponse.getBody().getItems(), lastResponse.getResponse()));
serviceCall.set(lastResponse.getBody().getItems());
} else {
serviceCall.setSubscription(next.call(serviceResponse.getBody().getNextPageLink()).single().subscribe(this));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
package com.microsoft.azure;

import com.microsoft.rest.ServiceCallback;
import com.microsoft.rest.ServiceResponse;

import java.util.List;

Expand Down Expand Up @@ -71,7 +70,7 @@ public void load(List<E> result) {
}

@Override
public void success(ServiceResponse<List<E>> result) {
public void success(List<E> result) {
success();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,10 @@ public PagedList() {
*/
public PagedList(Page<E> page) {
this();
items.addAll(page.getItems());
List<E> retrievedItems = page.getItems();
if (retrievedItems != null && retrievedItems.size() != 0) {
items.addAll(retrievedItems);
}
nextPageLink = page.getNextPageLink();
currentPage = page;
}
Expand Down Expand Up @@ -138,14 +141,17 @@ public boolean hasNext() {
public E next() {
if (!itemsListItr.hasNext()) {
if (!hasNextPage()) {
throw new NoSuchElementException();
throw new NoSuchElementException();
} else {
int size = items.size();
loadNextPage();
itemsListItr = items.listIterator(size);
}
}
return itemsListItr.next();
if (itemsListItr.hasNext()) {
return itemsListItr.next();
}
return null;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ public Builder(OkHttpClient.Builder httpClientBuilder, Retrofit.Builder retrofit
// Set up OkHttp client
this.httpClientBuilder = httpClientBuilder
.cookieJar(new JavaNetCookieJar(cookieManager))
.readTimeout(30, TimeUnit.SECONDS)
.addInterceptor(userAgentInterceptor);
this.retrofitBuilder = retrofitBuilder;
this.buildable = new Buildable();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,6 @@ public interface TaskGroup<T, U extends TaskItem<T>> {
*/
void prepare();

/**
* Executes the tasks in the group.
* <p>
* the order of execution of tasks ensure that a task gets selected for execution only after
* the execution of all the tasks it depends on
* @throws Exception the exception
*/
void execute() throws Exception;

/**
* Executes the tasks in the group asynchronously.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
*/
public abstract class TaskGroupBase<T, U extends TaskItem<T>>
implements TaskGroup<T, U> {
/**
* Stores the tasks in this group and their dependency information.
*/
private DAGraph<U, DAGNode<U>> dag;

/**
Expand Down Expand Up @@ -55,31 +58,8 @@ public void prepare() {
}
}

@Override
public void execute() throws Exception {
DAGNode<U> nextNode = dag.getNext();
while (nextNode != null) {
nextNode.data().execute();
this.dag().reportedCompleted(nextNode);
nextNode = dag.getNext();
}
}

@Override
public Observable<T> executeAsync() {
return executeReadyTasksAsync();
}

@Override
public T taskResult(String taskId) {
return dag.getNodeData(taskId).result();
}

/**
* Executes all runnable tasks, a task is runnable when all the tasks its depends
* on are finished running.
*/
private Observable<T> executeReadyTasksAsync() {
DAGNode<U> nextNode = dag.getNext();
final List<Observable<T>> observables = new ArrayList<>();
while (nextNode != null) {
Expand All @@ -92,12 +72,17 @@ public Observable<T> call(T t) {
if (dag().isRootNode(thisNode)) {
return Observable.just(t);
} else {
return executeReadyTasksAsync();
return executeAsync();
}
}
}));
nextNode = dag.getNext();
}
return Observable.merge(observables).last();
return Observable.merge(observables);
}

@Override
public T taskResult(String taskId) {
return dag.getNodeData(taskId).result();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,6 @@ public interface TaskItem<U> {
*/
U result();

/**
* Executes the task.
* <p>
* once executed the result will be available through result getter
*
* @throws Exception exception
*/
void execute() throws Exception;

/**
* Executes the task asynchronously.
* <p>
Expand Down
1 change: 0 additions & 1 deletion client-runtime/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ dependencies {
compile 'com.squareup.retrofit2:converter-jackson:2.0.2'
compile 'com.squareup.retrofit2:adapter-rxjava:2.0.2'
compile 'io.reactivex:rxjava:1.1.8'
compile 'io.reactivex:rxjava-computation-expressions:0.21.0'
compile 'com.fasterxml.jackson.datatype:jackson-datatype-joda:2.7.2'
compile 'org.apache.commons:commons-lang3:3.4'
testCompile 'junit:junit:4.12'
Expand Down
4 changes: 4 additions & 0 deletions client-runtime/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@
<groupId>io.reactivex</groupId>
<artifactId>rxjava</artifactId>
</dependency>
<dependency>
<groupId>com.squareup.retrofit2</groupId>
<artifactId>adapter-rxjava</artifactId>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
Expand Down
12 changes: 6 additions & 6 deletions client-runtime/src/main/java/com/microsoft/rest/ServiceCall.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
*
* @param <T> the type of the returning object
*/
public class ServiceCall<T> extends AbstractFuture<ServiceResponse<T>> {
public class ServiceCall<T> extends AbstractFuture<T> {
/**
* The Retrofit method invocation.
*/
Expand All @@ -43,7 +43,7 @@ public static <T> ServiceCall<T> create(final Observable<ServiceResponse<T>> obs
.subscribe(new Action1<ServiceResponse<T>>() {
@Override
public void call(ServiceResponse<T> t) {
serviceCall.set(t);
serviceCall.set(t.getBody());
}
}, new Action1<Throwable>() {
@Override
Expand All @@ -70,9 +70,9 @@ public static <T> ServiceCall<T> create(final Observable<ServiceResponse<T>> obs
@Override
public void call(ServiceResponse<T> t) {
if (callback != null) {
callback.success(t);
callback.success(t.getBody());
}
serviceCall.set(t);
serviceCall.set(t.getBody());
}
}, new Action1<Throwable>() {
@Override
Expand Down Expand Up @@ -103,9 +103,9 @@ public static <T, V> ServiceCall<T> createWithHeaders(final Observable<ServiceRe
@Override
public void call(ServiceResponse<T> t) {
if (callback != null) {
callback.success(t);
callback.success(t.getBody());
}
serviceCall.set(t);
serviceCall.set(t.getBody());
}
}, new Action1<Throwable>() {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public abstract class ServiceCallback<T> {
/**
* Override this method to handle successful REST call results.
*
* @param result the ServiceResponse holding the response.
* @param result the result object.
*/
public abstract void success(ServiceResponse<T> result);
public abstract void success(T result);
}
5 changes: 5 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,11 @@
<artifactId>rxjava</artifactId>
<version>1.1.8</version>
</dependency>
<dependency>
<groupId>com.squareup.retrofit2</groupId>
<artifactId>adapter-rxjava</artifactId>
<version>2.0.2</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
Expand Down

0 comments on commit 14c7898

Please sign in to comment.