Skip to content

Commit

Permalink
Merge pull request Azure#52 from jianghaolu/unwrap
Browse files Browse the repository at this point in the history
Remove ServiceResponse<> wrappers in most methods
  • Loading branch information
jianghaolu committed Sep 6, 2016
2 parents 670b55e + c78b9c5 commit 3010c5c
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@
import com.microsoft.rest.ServiceCall;
import com.microsoft.rest.ServiceResponse;
import com.microsoft.rest.ServiceResponseWithHeaders;

import java.util.List;

import rx.Observable;
import rx.Subscriber;
import rx.functions.Func1;

import java.util.List;

/**
* An instance of this class provides access to the underlying REST call invocation.
* This class wraps around the Retrofit Call object and allows updates to it in the
Expand Down Expand Up @@ -116,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
24 changes: 7 additions & 17 deletions client-runtime/src/main/java/com/microsoft/rest/ServiceCall.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
package com.microsoft.rest;

import com.google.common.util.concurrent.AbstractFuture;

import rx.Observable;
import rx.Subscription;
import rx.functions.Action1;
Expand All @@ -19,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 @@ -42,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 @@ -69,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 @@ -102,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 All @@ -129,17 +130,6 @@ protected void setSubscription(Subscription subscription) {
this.subscription = subscription;
}

/**
* Invoke this method to report completed, allowing
* {@link AbstractFuture#get()} to be unblocked.
*
* @param result the service response returned.
* @return true if successfully reported; false otherwise.
*/
public boolean success(ServiceResponse<T> result) {
return set(result);
}

@Override
public boolean cancel(boolean mayInterruptIfRunning) {
subscription.unsubscribe();
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);
}

0 comments on commit 3010c5c

Please sign in to comment.